Cost optimization
Cost optimization
Advice like “use a cheaper model” is only sometimes the right answer. This page is ordered by how much each lever usually moves the bill.
1. Cap the output
Output tokens cost several times what input tokens cost on nearly every model, and the model decides how long the output is unless you say otherwise.
For extraction, classification, and routing — where a short answer is the whole point — an output cap is close to free money. It also fails loudly rather than silently: a truncated response is visible, an unbounded one just costs more.
2. Match the model to the step
Most pipelines have one step that genuinely needs the strongest model and several that do not. Routing, intent detection, tagging, and reformatting run fine on the cheapest tier.
Splitting a pipeline this way typically moves more money than any single model swap, because the cheap steps are the frequent ones.
3. Reuse the prefix so caching can work
Cached input is billed well below fresh input. A stable system prompt and a stable document prefix, placed at the start of the request and left byte-identical between calls, will hit that cache.
What defeats it: injecting a timestamp, a request ID, or a shuffled list into the prefix. Put anything that varies at the end.
4. Know which models change price on you
Two families bill more under conditions that are easy to miss:
- Peak hours. The DeepSeek family doubles during weekday peak hours in Beijing time. Hunyuan
hy3has its own daily window. A nightly batch is cheap; the same batch at 10:00 on a Tuesday is not. - Context tiers. The GPT-5.6 and Grok families bill a higher rate past a context threshold. A long agent session crosses it without any signal in the client.
Exact hours and thresholds are in the pricing page footnotes, and every response’s usage record shows which rate was applied. Scheduling a batch outside a peak window is a change to one cron expression.
5. Send less context
Context is charged on every turn of a conversation, not once. Two habits dominate:
- Trim history. Sending an entire conversation on turn 40 means paying for turn 1 forty times. Summarise, or window.
- Send the selection, not the file. In coding tools this is the single biggest lever — Cursor and Cline both send the open buffer if you let them.
6. Stream, so you can stop
stream: true does not change the price of a completed response, but it lets you abandon one that has gone wrong after a few hundred tokens instead of paying for all of it. It also makes the application feel faster, which is why it is worth doing regardless.
7. Measure before optimising
Give every application, tool, and environment its own API key. by_api_key in GET /v1/usage then attributes spend with no instrumentation on your side, and by_model shows which model is actually responsible.
Guessing which integration is expensive is usually wrong. A browser translation extension making thousands of tiny calls and an agent making a few enormous ones look nothing alike on the invoice.
8. Reconcile refunds
Failed tasks are refunded. If your ledger records the reservation and never reads the refund, your internal numbers will overstate spend and you will optimise against a figure that is not real. GET /v1/usage reports credits_settled and credits_refunded separately for this reason.
What does not help
- Retrying aggressively. A retried
400is the same wrong request at the same price. Retry only429and5xx— see Development Guide. - Polling faster. Poll requests count against the request rate, not the balance, so hammering the task endpoint buys
429s rather than speed. - Downgrading the model on a step that then needs two attempts. A cheap model that has to be re-run, or corrected by an expensive one, costs more than doing it once properly. Measure the pipeline, not the unit price.

