Skip to content

Costs and budgets ​

Prism records the tokens and cost of every answered request. With a monthly budget set, a routing rule can switch to free models once the money is spent.

How cost is worked out ​

Each model's cost in prism.yaml gives its price in US dollars per million tokens:

yaml
cost: {input_per_mtok: 3.00, output_per_mtok: 15.00}

For every answered request Prism multiplies the tokens the provider reports by these prices. When a provider reports no token counts, for example some streamed answers, Prism estimates the input from the request size and marks the record as estimated.

These figures are only as accurate as the prices you enter. Your provider's bill is the real cost.

Set a monthly budget ​

  1. Add a budget to prism.yaml:

    yaml
    budget:
      monthly_usd: 50
  2. Add a rule that reacts when it is spent. Put it near the top, so it wins over task rules:

    yaml
    routing:
      rules:
        - if: {budget_exceeded: true}
          then: local:any
  3. Restart prism serve.

budget_exceeded becomes true when this calendar month's recorded spend reaches monthly_usd. It turns false again at the start of the next month. With monthly_usd at 0 or unset, there is no budget and the condition never matches.

WARNING

The budget does not block requests by itself. It only changes routing through your budget_exceeded rule. A request for a cloud model by name still goes to that model.

Use a subscription as the overflow ​

If you pay for a Claude or ChatGPT plan, send traffic there once the API budget is spent, instead of to a smaller local model:

yaml
routing:
  rules:
    - if: {budget_exceeded: true}
      then: claude-sub

claude-sub is the alias of a claude-code provider. See Use your subscription as a provider.

Check your spending ​

From the command line:

bash
prism usage

The first line shows the month's total and your budget, for example This month: $0.0000 of $50.00 budget. Below it is one line per model with requests, input tokens, output tokens and cost. Before any request it says No usage recorded yet.

In the dashboard, the Usage page shows Spent, Budget, Remaining and Requests, a chart of daily cost over 30 days and a table per model. The same data is at GET /admin/usage.

Where the records are kept ​

Usage is appended to ~/.local/share/prism/usage.jsonl (or $XDG_DATA_HOME/prism/usage.jsonl). Each line holds the time, provider, model, token counts and cost. Your prompts and answers are never stored there.

To start counting from zero, stop the gateway and delete or move the file.

Next steps ​