Skip to main content
Helicone OSS LLM Observability

Error Handling & Fallback

How Helicone AI Gateway handles errors and automatically falls back between billing methods
4 min read

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:

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.

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#

  1. 403 Forbidden → Critical access issue, contact support
  2. 401 Unauthorized → Fix your provider API key
  3. 400 Bad Request → Fix your request format
  4. 500 Server Error → Provider issue or configuration problem
  5. 429 Rate Limit → Only shown if all attempts hit rate limits
Note

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 CodeWhat It MeansAction RequiredExample
401Authentication failedCheck your provider API key in settingsInvalid OpenAI API key
403Access forbiddenContact support@helicone.aiWallet suspended, model blocked
400Invalid request formatFix your request body or parametersMissing required field
429Insufficient creditsAdd credits OR configure provider keysNo Helicone credits, no BYOK
500Upstream provider errorCheck provider status or retryProvider API timeout
503Service unavailableProvider temporarily down, retry laterProvider 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:

  1. Add Helicone credits at /credits
  2. Configure provider keys in /settings/providers
  3. Enable automatic retries with Helicone-Retry-Enabled: true to handle transient failures
Info

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#

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#

Tip

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#


Info

Need Help? If you're seeing unexpected errors or need assistance configuring fallback, contact us at support@helicone.ai or join our Discord community.