AIDiscount优汇智
Home / Blog

How to Cut AI API Costs: Model Choice, Context Size and Output Limits

Practical ways to lower your AI API bill: pick the right model for each task, send less context, cap output length, reuse cached prompts and track spending per request.

2026-11-25 · 3 min read · AIDiscount team

CostTokensPricing

AI APIs bill by the token. A token is a few characters of text. You pay for the tokens you send (input) and the tokens the model writes back (output). Output tokens usually cost several times more than input tokens. Every saving comes from one of three things: a cheaper rate per token, fewer input tokens, or fewer output tokens.

1. Use the smallest model that does the job

Prices between models differ by more than ten times. Many tasks do not need the strongest model:

  • Small, fast models handle classification, extraction, short summaries, translation and autocomplete well.
  • Large models are worth it for hard reasoning, long multi-step coding tasks and work where a wrong answer is expensive.

Some lower-cost models and their current prices:

ModelInput / 1M tokensOutput / 1M tokensvs. official price
DeepSeek V4.1 Flash
deepseek-v4.1-flash
$0.0857$0.342942.9% off
GLM-5.3-Flash
glm-5.3-flash
$0.0686$0.2452% off
GLM-5.3-FlashX
glm-5.3-flashx
$0.1714$0.6052% off
Claude Haiku 4.5
claude-haiku-4-5-20251001
$0.075$0.37592.5% off
DeepSeek V4 Pro
deepseek-v4-pro
$0.3857$1.157141.6% off
GLM-5.3
glm-5.3
$0.6857$2.4045.5% off

Prices are read from the live model marketplace when this page is generated and may change. The marketplace always shows the current rate.

A common pattern is routing: send each request to a small model first, and only escalate to a large model when the task is hard or the small model's answer fails a check. Because an OpenAI-compatible API uses the same request format for every model, routing only means changing the model field.

2. Send less context

Input tokens add up quickly, because chat apps and agents resend the whole conversation with every message.

  • Start new conversations for new topics instead of continuing a long thread.
  • Trim the history. Keep the system prompt and the last few turns, and replace older turns with a short summary.
  • Send only the relevant parts of documents and code. Retrieval (search first, then send the matching chunks) is usually cheaper than pasting whole files.
  • Shorten the system prompt. It is sent with every request, so every word in it is paid for many times.

3. Cap output length

Set max_tokens (or max_output_tokens for the Responses API) so a runaway answer cannot cost more than you expect. Ask for the format you need: "Answer in one sentence" or "Return JSON only" cuts output tokens directly.

resp = client.chat.completions.create(
    model="deepseek-v4.1-flash",
    messages=[
        {"role": "system", "content": "Reply in at most two sentences."},
        {"role": "user", "content": "Summarize this ticket: ..."},
    ],
    max_tokens=200,
)

Reasoning models also spend tokens thinking before they answer, and that thinking is billed as output. Use them where the reasoning helps, not for simple lookups.

4. Reuse cached prompts

Many models offer prompt caching: when a request starts with the same text as a recent request, the repeated part is billed at a lower cache-read rate. To benefit, put the fixed parts (system prompt, tool definitions, long reference documents) at the start, and the parts that change at the end. Where a model has cache prices, its page in the marketplace lists them.

5. Do not pay for the same answer twice

If your app asks the same question often, such as a product FAQ, store the answer in your own cache and return it without calling the API.

6. Batch small jobs

Instead of one request per item, put several short items in one request and ask for a list of results. The instructions are sent once instead of many times. Keep batches small enough that one bad item does not force you to redo the whole batch.

7. Measure per request

You cannot reduce what you do not measure. Every API response includes a usage field with the input and output token counts:

print(resp.usage.prompt_tokens, resp.usage.completion_tokens)

In AIDiscount, the Usage page in the dashboard lists the model, token counts and amount charged for every request. Use separate API keys for separate apps or team members to see which one is spending the most.

8. Compare the price per token

The same model can cost different amounts from different providers. AIDiscount shows the price per million tokens and, where it applies, how it compares with the official list price, on each model's page. Check the current rate in the marketplace before you choose, because prices change.

Try it with AIDiscount. One API key works with OpenAI- and Anthropic-compatible tools. Pay as you go, no monthly fee.
Create a free accountRead the API docs

Related guides

Languages

English · 简体中文 · 繁體中文 · 日本語 · 한국어 · Español · Français · Deutsch · Português · Русский