Skip to content

Improve OpenRouter API error messages for better debugging#145

Open
DalasNoin wants to merge 1 commit intosafety-research:mainfrom
DalasNoin:fix/improve-api-error-messages
Open

Improve OpenRouter API error messages for better debugging#145
DalasNoin wants to merge 1 commit intosafety-research:mainfrom
DalasNoin:fix/improve-api-error-messages

Conversation

@DalasNoin
Copy link

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}}"

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}}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant