Skip to main content

Price AI Models from a Custom Pricing Catalog

Early Access

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:

The Helm chart has no dedicated value for this option yet, so pass it as an argument:

traefik-values.yaml
additionalArguments:
- "--hub.aigateway.pricing.filePath=/etc/traefik/pricing/prices.yaml"

To mount the file from a ConfigMap, see Deploy the file on Kubernetes.

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 detailed level, the gateway records gen_ai.client.operation.cost for 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 costLimit on ai-rate-limit or ai-quota, the gateway denies a request for a model without a price with a missing_pricing error. Setting allowMissingPricing to true lets 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:

  • provider and model match case-insensitively.
  • The provider value must be the one the AI middleware sets, whatever the name (for example for a self-hosted model).
  • Without provider, the gen_ai.provider.name metric label can still show a provider that the gateway resolves from the host, for example openai. The gateway doesn't check the catalog in that case. An entry for openai has no effect until the AI middleware sets provider: 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 model name 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:

failover-with-cost-limit.yaml
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:

chatcompletion-primary.yaml (secondary: provider acme-b)
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
prices.yaml
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​

prices.yaml
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 openai entry overrides the built-in price of gpt-5, and sets a lower price for cached input tokens. Without cacheRead, cached input tokens price at the input rate.
  • The vllm entry prices acme-llm, a self-hosted model the built-in list has no price for.

Add a tier above an input-token threshold​

prices.yaml
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:

ai-pricing-configmap.yaml
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
traefik-values.yaml
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​

FieldDescriptionExampleFormatDefault
modelsList of model prices the catalog defines.see Examplesarrayrequired; use models: [] for an empty catalog

Model entry​

Each entry of models prices one model for one provider.

FieldDescriptionExampleFormatDefault
providerProvider this price applies to, matched case-insensitively against the provider the AI middleware sets.openaistringrequired
modelModel 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-5stringrequired
ratesPrices for this model. Every rate is a number in USD per million tokens, 0 or greater and less than 1000000.see ratesobjectrequired
tiersRate overrides that apply once a request's input tokens, including cached tokens, cross a threshold.see Examplesarrayoptional; 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​

FieldDescriptionFormatDefault
rates.inputPrice per million input tokens. Applies to every input token, except the cached ones once cacheRead or cacheWrite is set.numberrequired
rates.outputPrice per million output tokens.numberrequired
rates.cacheReadPrice per million cached input tokens read from cache.numberunset: these tokens price at rates.input
rates.cacheWritePrice per million input tokens written to cache.numberunset: these tokens price at rates.input

tiers​

FieldDescriptionFormatDefault
aboveInput-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 aboverequired
ratesPrices 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 ratesrequired, 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.