Cost optimization
The biggest savings usually come from capping output length, routing simple steps to cheaper models and keeping a stable prompt prefix so that cached input applies. Switching to a cheaper model is only sometimes the right answer. The eight levers on this page are 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 saves money at almost no cost. An output cap also fails visibly: a truncated response is easy to see, while an unbounded response 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 by step 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 the input cache.
A timestamp, a request ID, or a shuffled list injected into the prefix breaks the cache. Put anything that varies at the end of the request.
4. Know which models change price on you
Some models bill more under two conditions that are easy to miss:
- Peak hours. The two DeepSeek HC (high-cache) models double on weekdays 09:00–12:00 and 14:00–18:00 Beijing time, while the regular paid DeepSeek models bill one rate at all hours. Hunyuan
hy3has its own daily window. A nightly batch is cheap; the same batch at 10:00 on a Tuesday is not. - Context tiers. Most GPT-6 models bill a higher rate above 272K input tokens and Grok above 200,000 tokens. 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, sending only the selection 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 streaming lets you abandon a response that has gone wrong after a few hundred tokens instead of paying for the whole response. Streaming also makes the application feel faster, so streaming is worth enabling even without the cost benefit.
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 overstate spend, and you optimise against a figure that is not real. GET /v1/usage reports credits_settled and credits_refunded separately so that you can reconcile both values.
What does not help
- Retrying aggressively. A retried
400is the same wrong request at the same price. Retry only429and5xx. See Development Guide. - Polling faster. Polling does not speed up task execution. Respect
poll_after_secondsinstead of repeatedly requesting the same status. - 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.

