Skip to main content
CetiRun

Budgets and spend

Set the monthly AI Gateway budgets and request limits of Agents, and read what each Agent, user, and Team spends.

Each Agent has its own virtual key in the AI Gateway. The key has a monthly budget in US dollars. There is no token allowance. The AI Gateway counts the spend of every model call against the key, and it refuses calls when the spend reaches the budget. This page is for platform administrators.

Where the budget of an Agent comes from

AgentBudget of the keyWho can change it
A standard Agent: an Agent without a Team, or with a Team without an Agent PolicyThe operator’s aiGateway.defaultBudget when the key is created. The default is 10000 USD. The key has no request limitsA platform administrator, in the AI Gateway console. The operator keeps the change
The CetiAdmin Agentcetiadmin.model.initialMonthlyBudgetUSD when the key is created. make deploy requires this value. aiGateway.defaultBudget does not applyA platform administrator, in the AI Gateway console. The operator keeps the change
An Agent of a policy-bound TeammodelAccess.gatewayBudget.defaultMonthlyUSD of the Agent Policy, or the spec.modelAccess.monthlyBudgetUSD of the Agent, up to maxMonthlyUSD of the Agent PolicyA Portal administrator, in the Agent Policy. An admission administrator, with kubectl. The operator sets the key budget again after a change in the console

aiGateway.defaultBudget applies only when the operator creates a key. A change to the value does not change the keys that exist. With make deploy, set the value under platform.values.cetirun-operator.aiGateway.defaultBudget. Set it to the amount that one standard Agent can spend in a month.

An Agent Policy that allows models must have a monthly AI Gateway budget. In the Agent Policy editor, select Set monthly Gateway budget. Then set the default and the maximum.

The budget resets on the first day of each month, UTC. A job of the AI Gateway applies the resets about every ten minutes. As a result, a key can stay refused for up to ten minutes after the reset time.

What the budget counts

  • Shared models. Each call is charged at the price of the model. Refer to Set the price of a model.
  • GitHub Copilot models. Each call is charged at the list price of the model, from the same budget. This applies also when the subscription of the owner pays for the call.
  • Routers. Each call is charged at the price of the tier model that it goes to. The calls of an llm or jev classifier are also charged. The own price of a router in the AI Gateway only passes the check for unpriced models.
  • Internal tasks. The internal tasks of OpenClaw count like other calls. Refer to How Agents receive their models.

When the budget runs out

When the spend reaches the budget, the AI Gateway refuses each request of the key with HTTP 402. The requests to the GitHub Copilot models of the Agent stop too. The message of the AI Gateway starts with CetiRun AI Gateway:. It says that the budget of the Agent is spent, when the budget resets, and that a CetiRun administrator can raise it. When the budget of the AI Gateway team of the Agent is spent, the message names the Team instead. The Agents show this in different ways:

  • Hermes shows the message. Then it adds its own advice to add credits with the provider, which does not apply to the AI Gateway.
  • OpenClaw shows a shorter message: the Agent is out of budget on the AI Gateway, and a CetiRun administrator can raise the budget. The message omits the date of the reset. OpenClaw keeps using the key after the refusal, so its next request goes to the AI Gateway again.

To restore an Agent before the reset, do one of these steps:

  • For a standard Agent, raise the budget of its key in the AI Gateway console.
  • For an Agent of a policy-bound Team, raise the budget of the Agent Policy. This change restarts the running Agents of the Agent Policy one time.
  • For one Agent of a policy-bound Team, suspend the Agent. Then set its spec.modelAccess.monthlyBudgetUSD, up to the maximum of the Agent Policy. Only an admission administrator can make this change, and only while the Agent is suspended. Refer to AgentPolicy model access.

To select another HTTP status for an exhausted budget, set budgetExceededStatusCode of the AI Gateway chart. The chart accepts 402, 422, and 429. Refer to the chart README’s When a budget runs out for the behavior of the Agents with each status.

Team totals

The operator creates one AI Gateway team for each CetiRun Team, with the ID cetirun-team-<team>. The keys of the Agents of the Team belong to this AI Gateway team. The keys also name the owner of each Agent as their AI Gateway user. The operator creates the AI Gateway team without a budget, and it does not change the team after that.

To limit the total monthly spend of a Team, set a budget on its AI Gateway team in the console. Do not change the model access of the team in the console. The operator gives model access to each key.

Request limits

An Agent Policy can also limit the AI Gateway traffic of each Agent (modelAccess.rateLimits):

  • Parallel requests
  • Requests per minute (RPM)
  • Tokens per minute (TPM)
  • RPM or TPM for individual models

Each Agent of the Agent Policy gets the same limits on its own key. As a result, the traffic of one Agent does not count against another Agent. To set no limit, leave a field empty. Standard Agents have no request limits.

The operator applies a change of only the limits to the keys that exist. It does not stop or restart running Agents. A request over a limit gets HTTP 429 with a retry-after header. A TPM limit counts the tokens of finished requests. Refer to AgentPolicy rate limits.

A per-model limit applies to the model name that the AI Gateway counts:

  • For a router, this is the internal name of the router. A limit that an Agent Policy sets for the name of a router also applies under the internal name.
  • A per-model limit on a tier model does not apply to requests that go through a router.

Read the spend

The Portal shows the spend of the key of each Agent in the current month and its budget. These are the numbers that the operator last read from the AI Gateway. The operator reads them about every ten minutes.

  • Owners see them in the Usage section of the Agent page. Portal administrators see them in the Usage section of the management page of the Agent.
  • All agents shows them in the Spent (USD) column.

The Portal also shows why the AI Gateway refuses a key: Budget reached, Suspended, No model access, or Blocked by an administrator. While the operator blocks a key, until the AI Gateway confirms the block, the Portal shows Block pending. When the AI Gateway lost the record of the key, the Portal shows Key recovery required with the last spend that the operator read. Refer to Recover a missing key record. The Portal does not calculate a remaining amount. It does not show the history of the spend or the budget of an AI Gateway team.

The AI Gateway console shows the spend and the budget of each key, user, and team. Refer to Open the console. The key alias of an Agent is cetirun-<agent>-<agent UID>. The request log and the metrics of the AI Gateway also record the spend. Refer to Logs and metrics.

With the ADX-Mon collection, the function GatewayRequests() of the logs database gives one row for each call. For example, this query shows the calls and the spend of each Agent, owner, Team, and model since midnight UTC:

GatewayRequests()
| where Timestamp > startofday(now()) and CallOrigin != "health_check"
| summarize Calls = count(), Spend = sum(Spend) by Agent, Owner, Team, Model, CopilotRoute

CopilotRoute is true for the calls that a GitHub Copilot route of the owner answered. The subscription of the owner paid for them, and the budget counts them at the list price of the model.

The metric litellm_remaining_api_key_budget_metric shows the remaining budget of each key. Counters such as litellm_spend_metric_total restart from zero when an AI Gateway Pod restarts. Use the metrics for trends and alerts. For exact spend, use the request log or the daily totals of the AI Gateway. Refer to the chart README’s Request log and metrics.

The budget totals of the keys do not depend on the retention of the spend log.

Sources: key budgets and teams, AI Gateway client, operator values, AI Gateway values, and log query functions.