Skip to content

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.

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.

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 }
}
}