fix: surface provider API errors instead of showing empty response#5176
Open
superShen0916 wants to merge 1 commit into
Open
fix: surface provider API errors instead of showing empty response#5176superShen0916 wants to merge 1 commit into
superShen0916 wants to merge 1 commit into
Conversation
When OpenRouter or other providers return rate-limit (429) or insufficient-credits (402) errors, LiteLLM may wrap the error in a response object rather than raising an exception. Previously, aider showed "0 received" with no explanation, leaving users confused. This change: - Checks the completion response for an error field before processing - Displays the provider error message to the user when found - Improves the empty-response warning to mention rate limits and credits as likely causes Fixes Aider-AI#3264 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3264 — When OpenRouter or other providers return rate-limit (429) or insufficient-credits (402) errors, LiteLLM may wrap the error in a response object rather than raising an exception. Previously, aider showed "0 received" with no explanation, leaving users confused about why no response was generated.
Changes
Detect API errors in completion responses (
send()inbase_coder.py): Aftersend_completionreturns, check if the response has anerrorfield (populated by LiteLLM for API-level errors). If present, display the error message viatool_errorand return early — avoiding the misleading token report.Improve empty-response warning (
show_send_output_stream): Replace the generic "Empty response received from LLM. Check your provider account?" with a more actionable message that mentions rate limits, insufficient credits, and provider availability as likely causes, and suggests--verbosefor debugging.Test plan
completion.erroris populated (currently for provider errors that LiteLLM wraps in a response)None/falsy for normal completionsRisk
Low. The error check is defensive and only fires when the provider returns an explicit error object. All existing success paths are unchanged.
🤖 Generated with Claude Code