Custom costs
AI Gateway allows you to set custom costs at the request level. By using this feature, the cost metrics can accurately reflect your unique pricing, overriding the default or public model costs.
To add custom costs to your API requests, use the cf-aig-custom-cost
header. This header enables you to specify the cost per token for both input (tokens sent) and output (tokens received).
- per_token_in: The negotiated input token cost (per token).
- per_token_out: The negotiated output token cost (per token).
There is no limit to the number of decimal places you can include, ensuring precise cost calculations, regardless of how small the values are.
Custom costs will appear in the logs with an underline, making it easy to identify when custom pricing has been applied.
In this example, if you have a negotiated price of $1 per million input tokens and $2 per million output tokens, include the cf-aig-custom-cost
header as shown below.