Aller au contenu
Cette page n'est pas encore disponible dans votre langue. La version anglaise est affichée.

AI Cost Estimates and Spend Caps

The ai_budget block estimates what judge batches, Solo Mode labeling, and labeling engine runs will cost, and refuses any run that would pass cap_usd.

Potato's ai_budget block estimates what an AI run will cost before the run starts, and refuses a run that would take the project's AI spend past a dollar ceiling. The estimate counts tokens from the item text and prices the tokens from a table of published per-token rates that ships with Potato. The ceiling is ai_budget.cap_usd. Potato compares the ceiling with the money already spent plus the projected cost of the next run, and a run projected to cross the ceiling does not start. One running total covers the whole project. Spend from Solo Mode therefore counts against a later judge batch, and the reverse. Every figure is an estimate for deciding whether a run is affordable, and the provider's invoice stays the record of what you paid.

Configuration options

Add the block below to an existing config to set a $25 ceiling on the project's AI spend:

yaml
ai_budget:
  cap_usd: 25.0

The block takes two options, and neither has a default:

OptionDefaultWhat the option controls
cap_usdnoneThe dollar ceiling for the project's AI spend. A run whose projected cost would take the total past the ceiling is refused before the first model call. Without cap_usd, Potato still records spend and refuses nothing.
pricesnonePer-model rates in US dollars per million tokens, written as model-name: [input, output]. Entries are merged over the built-in price table and replace a built-in row of the same name.

Potato refuses to start when prices is not a mapping, when an entry is not a list of two numbers, or when a rate is negative. An entry whose output rate is lower than its input rate loads with a warning. Every rate in the built-in table charges more for output than for input, and a lower output rate usually means the pair was entered in the wrong order. A cap_usd that is not a number logs a warning and leaves the project without a ceiling. A quoted number such as "25" is read as 25. A server started with potato start names the ceiling in the log at startup, and a deployment through WSGI or create_app never logs the ceiling. The startup line prints a malformed cap_usd as if the value were a ceiling, and only the warning shows that no ceiling applies.

AI features the cap covers

The cap and the running total cover four AI features:

  • Judge batches. The batch behind POST /admin/api/judge-alignment/run runs the judge alignment judge over items your annotators have labeled.
  • The position-bias probe. POST /admin/api/judge-position-bias asks the judge about each sampled item twice, the second time with the labels in reverse order.
  • Solo Mode. Solo Mode checks the cap for background labeling, gold-set evaluation, prompt trials, and the prompt-sensitivity check.
  • The labeling engine. Every labeling engine run checks the cap before each chunk of items.

Other AI calls in Potato record no spend and are not checked against the cap. The hints and rationales annotators request through ai_support, the chat_support sidebar, icl_labeling, the LLM behind active_learning, and model_training all run outside the budget. Solo Mode's calls to the revision model run outside the budget too. Those calls cover prompt optimization and the paraphrases for the prompt-sensitivity check, and Solo Mode writes the paraphrases before the cap check runs. The paraphrases from the labeling engine's prompt_search count against budgets.model_usd and are never recorded in the spend total. For spend from the uncovered calls, set a limit with the provider.

When each feature checks the cap

Each feature checks the cap at a different point, and a refusal leaves different work behind:

FeatureWhen Potato checksResult when the run would cross the cap
Judge batchOnce, before the first model callReturns HTTP 402 with "ran": false, the cap, the amount spent, the estimate, and an error message. No item is judged.
Position-bias probeOnce, before the first model callReturns the same 402 response. No item is probed.
Solo Mode background labelingBefore labeling starts, and again before every batchAt the start, /solo/api/start-labeling returns 402 with the refusal message. Before a later batch, Potato pauses background labeling and shows the reason on the Solo Mode dashboard. Items already labeled keep their labels.
Solo Mode gold-set evaluation, prompt trials, and sensitivity checkOnce, before the job labels any itemThe job ends with status failed and the refusal message as its error.
Labeling engineBefore every chunk of runtime.batch_size itemsThe run ends with status paused. Finished chunks stay committed, and the next run picks up the items that have no prediction.

A one-time check before the first call means a judge batch either runs in full or does not start. A batch halted halfway would leave a partly judged project and a bill for the judged part. Solo Mode and the labeling engine label whole corpora in the background, check the cap again before every batch or chunk, and can stop partway.

The labeling_engine block has a separate limit named budgets.model_usd, and the labeling engine configuration page documents the limit. ai_budget.cap_usd is compared with the project's recorded spend from every covered feature. budgets.model_usd counts only the engine's own model calls and is checked before each call.

Token and price estimates

Potato counts input tokens from characters, at four characters per token. Tokenizers differ by model and by language. A count from characters can therefore be off in either direction, and is no basis for checking an invoice. Three rules push the estimate up rather than down:

  • Output at the limit. Each item is charged the full output limit from the model's max_tokens, not a typical reply length. The judge uses 100 tokens when max_tokens is unset.
  • Prompt overhead on every item. The judge adds 600 characters per item for the rubric, the label list, and the JSON instruction. Solo Mode adds the length of the current prompt plus 400 characters to every item.
  • Every call priced. The position-bias probe is priced at two calls per item per scheme. Solo Mode prices two calls per item for the label and the uncertainty estimate. A decision model (systemone or laya) is priced at one call per item with no output tokens in Solo Mode, and the labeling engine also prices a decision source with no output tokens. Under sampling_diversity, Solo Mode prices one call plus num_samples. With the jury on, Solo Mode multiplies the count by the number of jurors. A labeling engine source with k_sample confidence is priced at its samples count per item.

Dollar figures come from a price table in potato/ai/cost.py. The table lists base published input and output rates per million tokens for OpenAI, Anthropic, and Google models, without batch discounts, prompt caching, or long-context tiers. The gemini-3.6-flash, gemini-3.7-flash, and gemini-3.8-flash rows carry promotional rates that run through 2026-12-31, and the published rates for those models double on 2027-01-01. Each estimate includes an as_of field with the date the table was last checked against the vendors' pricing pages, and in Potato 2.14.0 the field reads 2026-09-05. Vendors change prices and release models between Potato releases. Before a large run, compare the model's row with the vendor's own pricing page, and set ai_budget.prices when the two differ.

Potato matches a model name to the longest table row contained in the name. gpt-4o-mini has its own row and is not priced as gpt-4o, and a dated snapshot such as gpt-4o-2024-08-06 takes the gpt-4o row. A model with no row of its own takes the row of the nearest family name inside its name, and that row can belong to an older or a more expensive model. When a capped run is priced from a family row, the server log reports the price as matched to the nearest family in PRICE_TABLE. Give the model its own entry in ai_budget.prices to check the cap against the model's real rate.

Models with no price and self-hosted models

How the cap treats a run depends on whether Potato can put a dollar figure on the model:

ModelEstimateCap
Priced, with a projected total above the capA dollar figureRefused before the first call
Priced, with a projected total within the capA dollar figureRuns
A self-hosted endpoint typecost_usd: 0 and local: trueRuns
No row in the table or in ai_budget.pricesA token count and cost_usd: nullRuns, with a warning that the cap cannot be checked

An unpriced model is the case to watch. New models are the most likely to be missing from the table, and the provider bills the run whether or not Potato can price the run. When cap_usd is set, the server log reports has no price on record for each such run. Without a cap, Potato logs no warning. The running total counts unpriced runs separately instead of adding them as zero. Add the model to ai_budget.prices to make the cap apply.

Potato prices the vllm, ollama, yolo, laya, and SAM endpoint types at zero, along with the trained, fixture, static, and jury types. The labeling engine also prices any source whose base_url is a localhost address at zero. A self-hosted estimate still reports a token count, and the count predicts how long the run takes.

Two endpoint types are priced wrongly in Potato 2.14.0:

  • huggingface. Potato prices huggingface at zero and treats the endpoint as self-hosted, although the huggingface endpoint sends requests with your API key to Hugging Face's hosted Inference API. The cap therefore never limits a run on the huggingface endpoint, and any charge for the run appears only on the Hugging Face bill. Watch Hugging Face's own billing for those runs. The same classification makes the labeling engine skip pii_redaction for the huggingface endpoint. Item text goes to Hugging Face's hosted API unmasked, even with redaction turned on.
  • ollama_vision. Potato has no price row for ollama_vision and does not class the endpoint as self-hosted. A run on ollama_vision therefore reports cost_usd: null as an unpriced run, and a capped labeling engine run logs the warning before every chunk. In the labeling engine, setting the source's base_url to a localhost address prices the source at zero. A source with no base_url stays unpriced, although the endpoint itself defaults to localhost:11434.

Per-model prices in ai_budget.prices

Set ai_budget.prices when a model is missing from the table or when the vendor's rate has changed since the table was checked. Each entry maps a model name to the model's input and output rates in US dollars per million tokens. Copy the rates from the vendor's pricing page on the day you set them. The model name and the rates in the block below are placeholders:

yaml
ai_budget:
  cap_usd: 25.0
  prices:
    # USD per million tokens, [input, output]
    example-model-v2: [1.00, 4.00]

Potato matches entries by the same longest-name rule as the built-in table. One entry can therefore cover a whole model family or a single dated snapshot. An entry replaces the built-in row of the same name, and a longer entry name wins over a shorter built-in row.

The spend record and the ai-cost endpoint

Potato records each run in the ai_spend table of project.sqlite in the task directory, under the project's annotation_task_name. The labeling engine writes one row for each model in each chunk, and n_runs therefore counts an engine run once per chunk and model. Changing annotation_task_name starts a new total. Read the project's total, and the estimate for the next judge batch, from the admin API:

bash
curl -H "X-API-Key: $ADMIN_KEY" http://localhost:8000/admin/api/ai-cost

Add ?max_per_schema=N to price a smaller judge batch. On a new project with a judge on Ollama, the response reads as follows:

json
{
  "next_judge_run": {
    "n_items": 400,
    "input_tokens": 98400,
    "output_tokens": 40000,
    "total_tokens": 138400,
    "model": "llama3.2",
    "cost_usd": 0.0,
    "priced": true,
    "local": true,
    "as_of": "2026-09-05",
    "notes": ["Self-hosted: no per-token cost. The token count still predicts how long the run takes."],
    "summary": "400 item(s), about 138,400 tokens, on a self-hosted model: no per-token cost."
  },
  "spent": {
    "cost_usd": 0.0,
    "total_tokens": 0,
    "n_runs": 0,
    "n_unpriced_runs": 0,
    "cap_usd": 25.0,
    "runs": [],
    "note": ""
  }
}

spent.runs lists the 50 most recent runs, each with its action, model, item count, token counts, cost, and an estimated flag. spent.cost_usd sums the priced runs only, and n_unpriced_runs counts the rest. The judge batch, the position-bias probe, and Solo Mode record estimates scaled to the items each run attempted. The labeling engine records the token counts the provider returns where the endpoint reports usage, and marks the row as estimated otherwise. A run that stops partway is charged for the items that reached the model. A failed call still counts, because the provider bills a call that reached the model even when the reply was unusable.

In Solo Mode, the AI Spend card on the Solo Mode dashboard shows the dollar total, the cap, the tokens so far, an estimate for the items still to label, and the reason for the last refusal. The card reads /solo/api/spend, and the /solo/api/spend route needs a logged-in session rather than the admin key. The admin dashboard has no spend panel. Outside Solo Mode, read the total from /admin/api/ai-cost.

Further reading

For implementation details, see the source documentation.