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 the packages/cost/models directory:
Step 2: Create Provider Definition#
We will use DeepInfra as our example.
For OpenAI-Compatible Providers#
Create a new file in packages/cost/models/providers/[provider-name].ts:
Make sure to look up the correct endpoints and override anything that is not OpenAI API default.
This handles auth because the 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 the BaseProvider definition.
Step 3: Add Provider to Index#
Update packages/cost/models/providers/index.ts:
Step 4: Add Provider to the Web's Data#
Update web/data/providers.ts to include the new provider:
Step 5: Update provider helpers#
Include provider in packages/cost/models/provider-helpers.ts within the heliconeProviderToModelProviderName function, so the mapping is done by the AI Gateway correctly.
Also, go to the 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 to packages/cost/models/providers/priorities.ts and include your provider within the PROVIDER_PRIORITIES constant variable.
Step 7: Update provider setup for tests#
Head to worker/test/setup.ts and include your new provider within the supabase-js mock.
Step 8: Define Authors (Model Creators)#
Create author definitions in packages/cost/models/authors/[author-name]/:
Folder Structure#
models.ts#
Include the model within the models 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 the packages/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!
Two important things to note here:
- 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#
Update packages/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#
Update packages/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 in packages/cost/models/registry-types.ts.
Add your new model to the packages/cost/models/registry.ts:
Step 10: Create Tests#
Create test files in worker/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 the auth() method with custom logic:
Issue: Non-Standard Request Format#
Solution: Override the buildBody() 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
