Price it first
Ask for an estimate with a typical text and your decisions. It counts the input tokens and quotes the most the call can cost. It runs no model and charges nothing.POST /v1/decide/estimate, with the same body as a decision. Estimates count against
their own token budget, estimate_tokens_per_minute. Pricing has the price for each
model.
Know your limits
Three limits of your tier set how fast you can go. They are shared by every key of your organisation.
Short texts usually meet the requests limit first, and long texts the tokens limit. With one text a request,
your requests a minute set your pace: multiply by 60 for texts an hour. At tier 0 that is 1,800 an hour,
so 100,000 texts take more than two days.
A new organisation starts at tier 0. Limits has the numbers for each tier, and buying
credit moves you to a higher one (move up a tier).
GET /v1/account gives your own limits in effective_limits. It needs a key with full or read access:
an inference key can’t read it.
Send them at a steady pace
This code runs as many workers as your tier allows at once. Each worker waits between its calls, so together they stay under your requests limit. It usesAsyncOneHot, the
async Python client.
RPM and CONCURRENCY to your tier’s numbers. For long texts or images, input tokens a minute
(tpm) can run out first: lower RPM until RPM times a request’s input tokens stays under
tpm. Over a limit, a request gets 429 with a
Retry-After header. The clients wait that long and try again, twice by default
(retries).
For a long run, write each answer to a file as it arrives, with its text’s ID. When you start again,
skip the IDs you already have.
Rerun safely
Give each text its own idempotency key, made from its ID, as above.- Run the same items again, and each one already answered returns its saved answer. It isn’t run or
charged again. A saved answer lasts 24 hours. After that, its key answers
409 idempotency_response_expiredand never runs the text again. - Change the decisions, and change the key too, such as
-v2. The same key with a different body is refused with409 idempotency_conflict. - An organisation with zero data retention keeps no answers, so a rerun there runs and charges again.
retryable is true. Otherwise the same key returns the same
failure: fix the request, and give it a new key (errors).
Keep each request lean
- Put only the text the questions need in
context. You pay for every input token. - Ask all the questions about a text in one request. You pay for the text once.
kettei-coreis the cheapest model, and it reads text. Usekettei-chuborkettei-fatfor images.- Keep the questions and outcome descriptions the same for every text, so the answers are comparable.
Before a long run
- Have enough credit. Multiply the estimate by the number of texts. When credit runs out, the rest
get
402 insufficient_credit, and nothing is charged for them. Buy credit, or turn on automatic top-ups (buy credit), then send them again. - Warm a fine-tuned model first. A fine-tuned model that has been idle may need to load. With the
default fallback, a call that waits more than 10 seconds for the load is answered by its base model,
with
fallback.reasonmodel_warming. Keep the model warm for the run (keep a model warm), or checkfallbackin each answer and send those texts again with a new idempotency key. The old key would return the saved fallback answer.
