Helicone AI Gateway automatically tries multiple billing methods to ensure your requests succeed. When one method fails, it falls back to alternatives and returns the most actionable error to help you fix issues quickly.
How Fallback Works#
The AI Gateway supports two billing methods:
Pay-as-you-go with Helicone credits. Simple, no provider account needed.
Use your own provider API keys. You're billed directly by the provider.
Automatic Fallback: When you configure both methods, the gateway tries PTB first. If it fails (e.g., insufficient credits), it automatically falls back to BYOK.
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
Setup: You have Helicone credits
Result: ✅ Request completes using Pass-Through Billing
Error: None - successful response
Scenario 2: PTB Fails, BYOK Succeeds
Setup: No Helicone credits, but valid provider API key configured
Result: ✅ Request completes using your provider key
Error: None - successful response (PTB's 429 is hidden since BYOK succeeded)
Scenario 3: PTB Fails, BYOK Fails
Setup: No Helicone credits, invalid/failing provider key
Result: ❌ Request fails
Error Returned: BYOK's error (401, 500, etc.) - NOT PTB's 429
Why: 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
Setup: No Helicone credits, no provider keys configured
Result: ❌ Request fails
Error Returned: 429 Insufficient credits
Why: No alternative billing method available
Example:
Solutions:
- Add Helicone credits at
/credits - Configure provider keys in
/settings/providers - Enable automatic retries with
Helicone-Retry-Enabled: trueto 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
BYOK Errors:
- 401: "Invalid API key" → Check provider keys in
/settings/providers - 500: "Provider error" → Check provider status
- 503: "Service unavailable" → Provider having issues
Best Practices#
Set up both PTB and BYOK for maximum reliability. If one fails, the other serves as backup.
Keep track of your Helicone credits to avoid 429 errors during critical requests.
Use Helicone retry headers to automatically retry transient errors (429, 500, 503) with exponential backoff.
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.
