byterover-cli
byterover-cli copied to clipboard
OpenRouter API returns 400 provider error
Priority: High
Description: OpenRouter API call fails with a 400 error from the provider.
Error Message: ERROR: Error in OpenRouter API call (Attempt 1/3): 400 Provider returned error
Root Cause: The OpenRouter service is likely receiving an invalid request format, possibly due to:
- Invalid function schema (same issue as OpenAI)
- Unsupported parameters for the selected model
- Authentication or configuration issues
Location: src/core/brain/llm/services/openrouter.ts
Investigation Required:
- Check if the same schema validation issue affects OpenRouter
- Verify OpenRouter API key configuration
- Confirm the selected model supports function calling
- Review request payload formatting
OpenRouter 402 Error - Token Limit Issue
This issue likely comes from token limits rather than a bug in the code. For example, I ran a test myself using a free API key from OpenRouter and also got this error:
10:07:06 ERROR: Error in OpenRouter API call (Attempt 1/3): 402 This request requires more credits, or fewer max_tokens. You requested up to 65536 tokens, but can only afford 3934.
10:07:08 ERROR: Error in OpenRouter API call (Attempt 2/3): 402 This request requires more credits, or fewer max_tokens. You requested up to 65536 tokens, but can only afford 3934.
10:07:10 ERROR: Error in OpenRouter API call (Attempt 3/3): 402 This request requires more credits, or fewer max_tokens. You requested up to 65536 tokens, but can only afford 3934.
10:07:10 ERROR: Failed to get response from OpenRouter after 3 attempts.
Analysis:
- Retry logic working (3 attempts made)
- Consistent 402 error (credit limit, not code bug)
- 65,536 tokens requested vs 3,934 affordable
- Missing
max_tokensparameter in API call
Fix: The best fix is to limit the tokens according to the free plan from OpenRouter (about 3000)
// src/core/brain/llm/services/openrouter.ts
max_tokens: 3000, // Add this parameter