anyllm.space
Main navigation
Documentation sections ▾
Documentation / Cost caps and idempotent retries

Cost caps and idempotent retries

Estimate the maximum charge before dispatch, reuse the same operation key on retry and inspect the ledger afterward.

Set a cost cap

X-Max-Cost-Rub is the maximum RUB amount you authorize for one API call. The gateway compares it with its estimate before dispatch. Set max_tokens deliberately. A larger output allowance increases the estimate even if the answer ultimately uses fewer tokens. For a model and message payload, POST /v1/quotes can return a short-lived quote. See API errors if the estimate exceeds the cap.

Retry one logical operation

Choose one Idempotency-Key for one workload, project and request payload. Keep it unchanged when retrying the same call. Use a fresh key for a new job or a changed body. A project can attach its own X-Client-Reference for order-level reconciliation.

Reconcile a timeout

A disconnected client may have sent a valid job. First look up GET /v1/requests/{id} using the request's project key. Inspect execution and billing separately. A released reserve, a pending operation and a settled charge call for different actions. Inspect Request history before issuing a new job.