Skip to main content

How Routing Works

Helicone AI Gateway intelligently routes your requests to the best available provider based on:
  • Authentication method (BYOK vs PTB)
  • Provider priority (OpenAI, Anthropic, etc.)
  • Cost optimization
  • Availability and rate limits
  • Explicit routing rules

Routing Priority

When you specify a model without a provider, the gateway builds a list of attempts and tries them in order:
1

BYOK Attempts First

If you have provider keys configured, BYOK attempts are prioritized:
2

Provider Priority

Within BYOK and PTB groups, providers are prioritized by:
  1. Native provider (e.g., OpenAI for GPT models)
  2. Major cloud providers (Azure, Bedrock, Vertex)
  3. Alternative providers (DeepInfra, OpenRouter, etc.)
3

Fallback Chain

If a request fails, the gateway automatically tries the next provider in the list.

Routing Examples

Automatic Routing

Let the gateway choose the best provider:
Routing behavior:
  • If you have an OpenAI BYOK key: Uses OpenAI directly
  • If no BYOK key: Uses PTB (Helicone billing)
  • Automatically tries alternatives if the first attempt fails

Explicit Provider Routing

Specify the exact provider you want:
Explicit routing still respects BYOK → PTB priority. If you have a BYOK key for the specified provider, it’s used first.

Multi-Model Fallback

Specify multiple models to try in order:
Behavior:
  1. Tries OpenAI BYOK (if configured)
  2. Falls back to OpenAI PTB
  3. Then tries Azure BYOK (if configured)
  4. Then Azure PTB
  5. Finally tries DeepInfra
See Fallbacks for more advanced fallback strategies.

Provider Exclusions

Exclude specific providers from automatic routing:
The !provider syntax excludes providers globally for all models in the comma-separated list.

Provider Priority Order

The gateway uses the following priority order for routing (within BYOK and PTB groups):
For GPT models (gpt-4o, gpt-5, o1, etc.):
  1. OpenAI (native provider)
  2. Azure OpenAI
  3. Alternative providers (DeepInfra, OpenRouter, etc.)
This priority order is implemented in the AttemptBuilder class and can be customized with explicit routing or exclusions.

BYOK vs PTB Routing

BYOK (Bring Your Own Key)

When you configure provider keys in Settings → API Keys:
  • Priority: BYOK attempts always come first
  • Billing: Direct from the provider
  • Failover: Falls back to PTB if BYOK fails

PTB (Pass-Through Billing)

When using Helicone’s API key without BYOK:
  • Priority: After BYOK attempts
  • Billing: Through Helicone (add credits at helicone.ai/credits)
  • Authentication: Single API key for all providers

Regional Routing

Some providers support regional endpoints:

AWS Bedrock

Azure OpenAI

Configure Azure deployments in Settings → API Keys, then:

Cost-Optimized Routing

The gateway considers provider pricing when routing:

Cost Tracking

View costs by provider in the Helicone dashboard

LLM Cost API

Access pricing data at helicone.ai/llm-cost

Routing Observability

Track which providers were attempted in the Helicone dashboard:
1

View Request Details

Open any request in Requests
2

Check Provider

See which provider was used and if fallbacks occurred
3

Analyze Patterns

Use filters to analyze routing patterns across requests

Advanced Routing

Model-Specific Provider Routing

Route different models to different providers:

Conditional Routing

Route based on application logic:

Routing Errors

The gateway returns errors when routing fails:
error
Invalid model or provider name:
error
Invalid or missing API key:
error
Rate limit exceeded or insufficient credits:

Best Practices

Let the gateway choose providers automatically:
This provides:
  • Automatic BYOK → PTB fallback
  • Cost optimization
  • Built-in resilience
Use explicit providers when you need:
  • Data residency requirements
  • Specific SLAs
  • Regulatory compliance
Add provider keys for:
  • Better cost control
  • Direct provider billing
  • Priority routing
Configure at Settings → API Keys
Use the Helicone dashboard to:
  • Track provider usage
  • Identify cost optimization opportunities
  • Detect routing issues
View at Helicone Dashboard

Next Steps

Fallbacks

Configure automatic failover strategies

Getting Started

Start using the AI Gateway

Browse Models

Explore all available models

Cost API

Access provider pricing data