Improve OpenRouter API error messages for better debugging#145
Open
DalasNoin wants to merge 1 commit intosafety-research:mainfrom
Open
Improve OpenRouter API error messages for better debugging#145DalasNoin wants to merge 1 commit intosafety-research:mainfrom
DalasNoin wants to merge 1 commit intosafety-research:mainfrom
Conversation
When OpenRouter API calls fail (e.g., due to insufficient credits, rate
limits, or other errors), the error messages were verbose and included
full tracebacks, making it difficult to identify the actual issue.
Changes:
- Simplify error logging to show only exception type and message instead
of full traceback (e.g., "APIStatusError: Error code: 402 - ..." instead
of "Exception Type: APIStatusError, Error Details: ..., Traceback: ...")
- Include the last 3 error messages in the final RuntimeError when no
response data is received, so users can see what actually went wrong
(e.g., "Insufficient credits" messages are now visible)
This makes it much easier to diagnose API issues, especially credential
and quota problems.
Example improved error:
Before: "RuntimeError: No response data received"
After: "RuntimeError: No response data received after 3 attempts. Recent
errors: APIStatusError: Error code: 402 - {'error': {'message':
'Insufficient credits. Add more using https://openrouter.ai/settings/credits',
'code': 402}}"
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.
When OpenRouter API calls fail (e.g., due to insufficient credits, rate limits, or other errors), the error messages were incorrectly pointing at some issue with a POSIX path and did not explain the cause of the error. in my case there was a simple out-of-credits openrouter error.
This makes it much easier to diagnose API issues, especially credential and quota problems.
Example improved error:
Before: "RuntimeError: No response data received"
After: "RuntimeError: No response data received after 3 attempts. Recent errors: APIStatusError: Error code: 402 - {'error': {'message': 'Insufficient credits. Add more using https://openrouter.ai/settings/credits', 'code': 402}}"