Price AI Models from a Custom Pricing Catalog
This feature is currently in early access. Available starting v3.22.0-ea.3.
Overview
The AI Gateway prices every request against a built-in list of model prices. This covers the Chat Completion, Responses API, Messages API, Bedrock Mantle, and Google Agent Platform middlewares. A custom pricing catalog is a file of your own prices that the gateway adds on top of that list. Use it to price a model the list doesn't know, such as a self-hosted or internal model, and to override the price of a model the list already has.
Cost metrics and the cost-based limits and quotas of the Rate Limit & Quota middleware use the same price, so a custom price applies to all of them. In the Administration UI, spend comes from the cost metric and uses catalog prices. Cache savings use the built-in list.
A catalog entry prices one model for one provider. For a model the catalog lists, the catalog price always wins over the built-in list. It replaces the whole built-in price of that model, so the built-in tiers and any non-token fees, such as web search, no longer apply. For every other model, the gateway uses the built-in list.
Configuration
To enable the catalog, set hub.aigateway.pricing.filePath to the path of your pricing file:
- Helm
- Install Configuration
The Helm chart has no dedicated value for this option yet, so pass it as an argument:
additionalArguments:
- "--hub.aigateway.pricing.filePath=/etc/traefik/pricing/prices.yaml"
To mount the file from a ConfigMap, see Deploy the file on Kubernetes.
--hub.aigateway.pricing.filePath=/etc/traefik/pricing/prices.yaml
Leave hub.aigateway.pricing.filePath unset to use only the built-in list.
The file extension selects the format: .yaml or .yml for YAML, .json for JSON, and .toml
for TOML. The gateway rejects any other extension. In every format, it also rejects an unknown field.
Reload the pricing file
The gateway reloads the file when it changes, and reads it again every minute.
At startup, a missing pricing file, or one with an error, stops the gateway. After a successful start, the gateway keeps the last valid catalog when the file goes missing or has an error.
Check that the gateway loaded the file
To confirm that the gateway loaded the file, look for the Pricing file loaded line in the
Traefik Hub logs. The line has the path of the file and the number of models it prices. The
gateway logs the same line after each successful reload.
Check whether a model has a price
To find out whether the gateway can price a model, send a request for that model through the route and look at one of these results:
- Cost metric. With metrics at the
detailedlevel, the gateway recordsgen_ai.client.operation.costfor each priced response. When the metric is missing for the model, the gateway has no price for it, or the response carries no token usage. - Cost limit. On a route with a
costLimitonai-rate-limitorai-quota, the gateway denies a request for a model without a price with amissing_pricingerror. SettingallowMissingPricingtotruelets the request through.
To confirm that the gateway applies your catalog price, read the X-Quota-Remaining-Cost header
before and after one request. The difference is the cost that the gateway charged.
Match a request to a catalog entry
Set provider on the AI middleware that handles the request. The gateway only
checks the catalog for the provider the AI middleware sets. When provider is unset on the
Chat Completion,
Responses API, or
Messages API middleware, every request prices against the
built-in list, even for a model your catalog lists. The Bedrock Mantle
middleware uses aws.bedrock by default, and the Google Agent Platform
middleware always uses gcp.vertex_ai.
The gateway matches an entry to a request with these rules:
providerandmodelmatch case-insensitively.- The
providervalue must be the one the AI middleware sets, whatever the name (for example for a self-hosted model). - Without
provider, thegen_ai.provider.namemetric label can still show a provider that the gateway resolves from the host, for exampleopenai. The gateway doesn't check the catalog in that case. An entry foropenaihas no effect until the AI middleware setsprovider: openai. - An entry for a model that the built-in list knows also covers the dated names and aliases that the built-in list maps to that model.
- To price one variant differently, or to be sure that a variant uses your price, list it by its full name. The full name always wins, whatever the order in the file.
- A model that the built-in list doesn't know, such as a self-hosted model, must match the
modelname of an entry exactly.
Combine the catalog with limits and failover
Place ai-rate-limit and ai-quota after the AI middleware. The limiter prices a request with
the provider and model that the AI middleware sets. A limiter that runs first has neither, and
it can't use your catalog. The limiter denies a request it can't price with a missing_pricing
error.
With a failover, the router can't know which provider will answer. Attach the AI middleware and the limiter to each service of the failover. Reference the same limiter middleware from every service. The limiter then checks and charges one bucket, priced with the provider that answered:
apiVersion: traefik.io/v1alpha1
kind: TraefikService
metadata:
name: failover-primary
namespace: ai-failover
spec:
failover:
service:
name: primary-llm
port: 80
middlewares:
- name: chatcompletion-primary
- name: cost-limit
fallback:
name: secondary-llm
port: 80
middlewares:
- name: chatcompletion-secondary
- name: cost-limit
errors:
status:
- "500-504"
The cost-limit middleware is a cost-based limit
of the Rate Limit & Quota middleware.
Set provider on each chat-completion middleware. Add a catalog entry for each provider and
model pair:
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: chatcompletion-primary
namespace: ai-failover
spec:
plugin:
chat-completion:
provider: acme-a
model: acme-llm
token: urn:k8s:secret:primary-key:token
models:
- provider: acme-a
model: acme-llm
rates:
input: 0.05
output: 0.25
- provider: acme-b
model: acme-llm
rates:
input: 0.1
output: 0.5
When a request fails over from acme-a to acme-b, the limiter charges it at the acme-b price.
Examples
Price a known model and a self-hosted model
models:
- provider: openai
model: gpt-5
rates:
input: 1.25
output: 10
cacheRead: 0.125
- provider: vllm
model: acme-llm
rates:
input: 0.05
output: 0.25
- The
openaientry overrides the built-in price ofgpt-5, and sets a lower price for cached input tokens. WithoutcacheRead, cached input tokens price at theinputrate. - The
vllmentry pricesacme-llm, a self-hosted model the built-in list has no price for.
Add a tier above an input-token threshold
models:
- provider: vllm
model: acme-llm
rates:
input: 0.05
output: 0.25
tiers:
- above: 128000
rates:
input: 0.1
Above 128,000 input tokens, including cached tokens, input prices at 0.1 instead of 0.05.
output keeps the entry's base rate, because the tier doesn't set it. List tiers in increasing
above order. The gateway rejects the file if a tier's above isn't greater than the previous
tier's.
Deploy the file on Kubernetes
Store the file in a ConfigMap, mount it as a volume, and point hub.aigateway.pricing.filePath at
the mounted path:
apiVersion: v1
kind: ConfigMap
metadata:
name: ai-pricing-catalog
namespace: traefik
data:
prices.yaml: |
models:
- provider: vllm
model: acme-llm
rates:
input: 0.05
output: 0.25
volumes:
- name: ai-pricing-catalog
mountPath: /etc/traefik/pricing
type: configMap
additionalArguments:
- "--hub.aigateway.pricing.filePath=/etc/traefik/pricing/prices.yaml"
The chart mounts the ConfigMap named in volumes[].name from the release namespace, as a volume
without subPath. Don't switch to a subPath mount. Kubelet never updates a file mounted that way, and the
gateway keeps pricing against a stale catalog.
Reference
Pricing file
| Field | Description | Example | Format | Default |
|---|---|---|---|---|
models | List of model prices the catalog defines. | see Examples | array | required; use models: [] for an empty catalog |
Model entry
Each entry of models prices one model for one provider.
| Field | Description | Example | Format | Default |
|---|---|---|---|---|
provider | Provider this price applies to, matched case-insensitively against the provider the AI middleware sets. | openai | string | required |
model | Model name this price applies to, matched case-insensitively against the name the response reports. An entry for a model that the built-in list knows also covers its dated names and aliases. | gpt-5 | string | required |
rates | Prices for this model. Every rate is a number in USD per million tokens, 0 or greater and less than 1000000. | see rates | object | required |
tiers | Rate overrides that apply once a request's input tokens, including cached tokens, cross a threshold. | see Examples | array | optional; without it, the base rates apply at every input-token level |
Listing the same provider and model twice in the file is a validation error.
rates
| Field | Description | Format | Default |
|---|---|---|---|
rates.input | Price per million input tokens. Applies to every input token, except the cached ones once cacheRead or cacheWrite is set. | number | required |
rates.output | Price per million output tokens. | number | required |
rates.cacheRead | Price per million cached input tokens read from cache. | number | unset: these tokens price at rates.input |
rates.cacheWrite | Price per million input tokens written to cache. | number | unset: these tokens price at rates.input |
tiers
| Field | Description | Format | Default |
|---|---|---|---|
above | Input-token threshold, including cached tokens. The tier's rates apply once a request's input tokens exceed this value. | integer, greater than the previous tier's above | required |
rates | Prices that replace the entry's base rates above this threshold. An unset price keeps the entry's base value. Setting cacheRead or cacheWrite in a tier requires the entry's base rates to already set that price. | object, same fields as the entry's rates | required, at least one price |
Troubleshooting
The gateway ignores the catalog price
Check that the AI middleware sets provider and that its value matches the provider in the
catalog entry. Without provider, the gateway doesn't check the catalog. It prices every request
against the built-in list, even when the metrics show a provider name such as openai. Bedrock
Mantle and Google Agent Platform set the provider themselves, to aws.bedrock and gcp.vertex_ai.
The gateway keeps the old prices after an edit
Look for Unable to load the pricing file, the current prices stay in use in the Traefik Hub logs.
The gateway logs the reason once, for example an unknown field, and keeps the last valid catalog
until the file loads without an error. If the file is mounted from a Kubernetes ConfigMap, check that the
mount doesn't use subPath.
The gateway doesn't start
At startup, a missing pricing file, or one with an error, stops the gateway. The error names the
field that is wrong, for example field outputt not found.
A request fails with missing_pricing
The limiter can't price the request. Check that ai-rate-limit or ai-quota runs after the AI
middleware, and that the catalog or the built-in list has a price for the model. See
Combine the catalog with limits and failover.
Related Content
- Read the Rate Limit & Quota documentation for cost-based limits and quotas.
- Read the Chat Completion documentation for the
providerfield. - Read the Failover guide for chaining providers.
- Read the Observability documentation for GenAI cost metrics.
