How Fallback Works
The AI Gateway supports two billing methods:Pass-Through Billing (PTB)
Pay-as-you-go with Helicone credits. Simple, no provider account needed.
Bring Your Own Keys (BYOK)
Use your own provider API keys. You’re billed directly by the provider.
Error Priority Logic
When both billing methods fail, the gateway returns the most actionable error to help you resolve the issue:Priority Order
- 403 Forbidden → Critical access issue, contact support
- 401 Unauthorized → Fix your provider API key
- 400 Bad Request → Fix your request format
- 500 Server Error → Provider issue or configuration problem
- 429 Rate Limit → Only shown if all attempts hit rate limits
Why this order? If you configured BYOK, errors from your provider keys (401, 500) are more actionable than PTB’s “insufficient credits” (429). You chose BYOK for a reason!
Common Error Scenarios
Error Code | What It Means | Action Required | Example |
---|---|---|---|
401 | Authentication failed | Check your provider API key in settings | Invalid OpenAI API key |
403 | Access forbidden | Contact support@helicone.ai | Wallet suspended, model blocked |
400 | Invalid request format | Fix your request body or parameters | Missing required field |
429 | Insufficient credits | Add credits OR configure provider keys | No Helicone credits, no BYOK |
500 | Upstream provider error | Check provider status or retry | Provider API timeout |
503 | Service unavailable | Provider temporarily down, retry later | Provider maintenance |
Fallback Scenarios
Scenario 1: PTB Succeeds
Scenario 1: PTB Succeeds
Setup: You have Helicone creditsResult: ✅ Request completes using Pass-Through BillingError: None - successful response
Scenario 2: PTB Fails, BYOK Succeeds
Scenario 2: PTB Fails, BYOK Succeeds
Setup: No Helicone credits, but valid provider API key configuredResult: ✅ Request completes using your provider keyError: None - successful response (PTB’s 429 is hidden since BYOK succeeded)
Scenario 3: PTB Fails, BYOK Fails
Scenario 3: PTB Fails, BYOK Fails
Setup: No Helicone credits, invalid/failing provider keyResult: ❌ Request failsError Returned: BYOK’s error (401, 500, etc.) - NOT PTB’s 429Why: You configured BYOK, so we show what’s wrong with your provider key rather than “insufficient credits”Example:
Scenario 4: No BYOK Configured, PTB Fails
Scenario 4: No BYOK Configured, PTB Fails
Setup: No Helicone credits, no provider keys configuredResult: ❌ Request failsError Returned: 429 Insufficient creditsWhy: No alternative billing method availableExample:Solutions:
- Add Helicone credits at
/credits
- Configure provider keys in
/settings/providers
- Enable automatic retries with
Helicone-Retry-Enabled: true
to handle transient failures
Retries can help! If you’re experiencing temporary rate limits or server errors, use Helicone retry headers to automatically retry failed requests with exponential backoff.
Understanding Error Sources
When you see an error, you can determine which billing method it came from: PTB Errors:- 429: “Insufficient credits” → Add credits at
/credits
- 403: “Wallet suspended” → Contact support
- 401: “Invalid API key” → Check provider keys in
/settings/providers
- 500: “Provider error” → Check provider status
- 503: “Service unavailable” → Provider having issues
Best Practices
Configure Both Methods
Set up both PTB and BYOK for maximum reliability. If one fails, the other serves as backup.
Monitor Credit Balance
Keep track of your Helicone credits to avoid 429 errors during critical requests.
Enable Automatic Retries
Use Helicone retry headers to automatically retry transient errors (429, 500, 503) with exponential backoff.
Log Error Details
Log the full error response to debug provider-specific issues quickly.
Error Handling in Code
Prefer built-in retries: Instead of implementing your own retry logic, use Helicone’s automatic retry headers by adding
Helicone-Retry-Enabled: true
to your requests. This handles exponential backoff automatically.Retry Logic Example
Error Classification
Related Resources
- Automatic Retries - Configure retry headers for handling transient failures
- Provider Routing - Learn how to configure fallback providers
- Settings: Provider Keys - Add your provider API keys
- Credits - Add Helicone credits for Pass-Through Billing
Need Help? If you’re seeing unexpected errors or need assistance configuring fallback, contact us at support@helicone.ai or join our Discord community.