Model pricing
OpenGateLLM allows you to define the costs for each model router. For more information about model routers, see setup your models documentation. The compute cost of a request is calculated from the number of tokens used and the costs defined for the model router, with the following formula:
cost = round((prompt_tokens / 1000000 * router.costs.prompt_tokens) + (completion_tokens / 1000000 * router.costs.completion_tokens), ndigits=6)The compute cost is returned in the response, in the usage.cost field, and recorded with the request usage, see usage monitoring documentation for more information.
Configuration
Section titled “Configuration”There are three ways to configure model pricing: Playground UI, API, or configuration file.
To define pricing in the Playground, go to the Routers page and create or edit a router with:
Prompt tokens cost: Cost per million input tokens.Completion tokens cost: Cost per million output tokens.
See POST /v1/admin/routers and PATCH /v1/admin/routers/{router_id} endpoints for defining cost_prompt_tokens and cost_completion_tokens of a router in API reference.
Prompt and completion token costs are expressed per million tokens.
To define model pricing in the configuration file, set the following fields for each model:
cost_prompt_tokens: Cost per million prompt/input tokens.cost_completion_tokens: Cost per million completion/output tokens.
Example:
models: [...] - name: my-language-model type: text-generation cost_prompt_tokens: 0.1 cost_completion_tokens: 0.3 providers: - type: openai url: https://api.openai.com key: ${OPENAI_API_KEY} model_name: gpt-4o-miniCost monitoring
Section titled “Cost monitoring”The user can see each request cost in the response of the API request. The cost is returned in the usage.cost field.
Moreover, Usage page in the Playground allows the user to see the history of the requests made by him and the cost of each.
{ "id": "chatcmpl-123", "object": "chat.completion", "created": 1677652288, "model": "my-language-model", "choices": [ ... ], "usage": { "prompt_tokens": 10, "completion_tokens": 20, "total_tokens": 30, "cost": 0.000015, "carbon": {"kWh": 0.0001456, "kgCO2eq": 0.0000672 } }}