Overview
Adding a new provider to Helicone involves several key components:- Authors: Companies that create the models (e.g., OpenAI, Anthropic)
- Models: Individual model definitions with pricing and metadata
- Providers: Inference providers that host models (e.g., OpenAI, Vertex AI, DeepInfra, Bedrock)
- Endpoints: Model-provider combinations with deployment configurations
Prerequisites
- OpenAI-compatible API (recommended for simplest integration)
- Access to provider’s pricing and inference documentation
- Model specifications (context length, supported features)
- API authentication details
Step 1: Understanding the File Structure
All model support configurations are located in thepackages/cost/models directory:
Step 2: Create Provider Definition
We will useDeepInfra as our example.
For OpenAI-Compatible Providers
Create a new file inpackages/cost/models/providers/[provider-name].ts:
BaseProvider class handles the standard Bearer ${apiKey} authentication pattern automatically when you set auth = "api-key", which is the common pattern for OpenAI-compatible APIs.
For Non-OpenAI Compatible Providers
For non-OpenAI compatible providers, you’ll need to override additional methods. You can find options by reviewing theBaseProvider definition.
Step 3: Add Provider to Index
Updatepackages/cost/models/providers/index.ts:
Step 4: Add Provider to the Web’s Data
Updateweb/data/providers.ts to include the new provider:
Step 5: Update provider helpers
Include provider inpackages/cost/models/provider-helpers.ts within the heliconeProviderToModelProviderName function, so the mapping is done by the AI Gateway correctly.
getUsageProcessor function within packages/cost/usage.ts and add the provider. If your provider require a custom usage processor (non-OpenAI compatible), you will need to add it here.
Step 6: Add provider to priorities list
We need to add the provider to the list of priorities so the gateway knows how much to prioritize each provider. Go topackages/cost/models/providers/priorities.ts and include your provider within the PROVIDER_PRIORITIES constant variable.
Step 7: Update provider setup for tests
Head toworker/test/setup.ts and include your new provider within the supabase-js mock.
Step 8: Define Authors (Model Creators)
Create author definitions inpackages/cost/models/authors/[author-name]/:
Folder Structure
models.ts
Include the model within themodels object. This can contain all model versions within that model family, in this case, the mistral-nemo model family.
Make sure to research each value and include the tokenizer in the Tokenizer interface type if it is not there already.
endpoints.ts
Now, update thepackages/models/[author]/[model-family]/endpoints.ts file with model-provider endpoint combinations.
Make sure to review the provider’s page itself since the inference cost changes per provider.
Make sure the initial key "mistral-nemo:deepinfra" is human-readable and friendly. It’s what users will call!
- Some providers have multiple deployment regions:
- Pricing Configuration
Step 9: Add model to Author registries (if needed)
If the model family hasn’t been created, you will need to add it within the AI Gateway’s registry.index.ts
Updatepackages/cost/models/authors/[author]/index.ts to include the new model family.
You don’t need to update anything if the model family has already been created.
metadata.ts
Updatepackages/cost/models/authors/[author]/metadata.ts to fetch models.
You don’t need to update anything if the author has already been created.
registry-types.ts
Update types for the new model family inpackages/cost/models/registry-types.ts.
packages/cost/models/registry.ts:
Step 10: Create Tests
Create test files inworker/tests/ai-gateway/ for the author.
Feel free to use the existing tests there as reference.
Step 11: Snapshots
Make sure to rerun snapshots before deploying.Common Issues & Solutions
Issue: Complex Authentication
Solution: Override theauth() method with custom logic:
Issue: Non-Standard Request Format
Solution: Override thebuildBody() method:
Issue: Multiple Pricing Tiers
Solution: Use threshold-based pricing:Deployment Checklist
- Provider class created with correct authentication
- Models defined with accurate specifications
- Endpoints configured with correct pricing
- Registry types updated
- Tests written and passing
- Snapshots updated
- Documentation updated
- Pass-through billing tested (if applicable)
- Fallback behavior verified