Skip to content
ChatGPT API
Documentation

Documentation

How to reduce ChatGPT API costs

Last updated:

ChatGPT API spend comes down to request volume, input and output tokens, model choice and repeated calls. Below is how a startup or product team cuts it several times over without losing quality. The fastest step is the same models at half the price.

Estimate your workload

Workload calculator

Choose a similar use case or enter your own numbers.

Real-world examples

You can adjust any value below

Count retries too10010,000,000
Prompt, history and documents100200,000
The actual generated answer5050,000

Via ChatGPT API: $11.25 per month. Savings per month: $11.25.

Estimated budget

At official rates

per month

$22.50

50%

Via ChatGPT API

per month

$11.25

Savings per month

$11.25

Savings per year

$135.00

Create an account

The estimate uses the selected model's current prices without prompt caching. It shows the order of magnitude, not a cent-accurate future bill.

How to calculate ChatGPT API cost

First, collect seven days of data

A total bill explains little. Log usage next to the product feature: a support reply, a document processing, an agent step, a report generation. After a week you will see which feature eats the budget and why.

TypeScript · cost per product feature
const startedAt = performance.now();
const res = await client.chat.completions.create({
  model,
  max_completion_tokens: maxCompletionTokens,
  messages,
});

analytics.track("llm_request", {
  feature: "support_reply",
  model: res.model,
  input_tokens: res.usage.prompt_tokens,
  output_tokens: res.usage.completion_tokens,
  latency_ms: Math.round(performance.now() - startedAt),
});

Find the main cost driver

Do not rewrite every prompt at once. Sort product features by spend and start with the top rows. The table below helps you pick the first experiment.

What the data showsWhere the bill growsWhat to check first
Large prompts in RAG or chatinput_tokensRetrieval, history, prompt caching
Answer longer than the UI needsoutput_tokensmax_completion_tokens and response format
Many calls per actionretries or agent loopBackoff, stop conditions, duplicates
One model serves every taskprice of each tokenRoute to a cheaper model

Optimization priorities

Start by connecting to ChatGPT API: it is the easiest way to cut the price of the same tokens by 50% immediately. Then move on to model selection, context, caching, and retry logic.

PriorityWhat to doDifficulty
1Connect to ChatGPT APILow
2Match the model to task complexityMedium
3Trim repeated contextMedium
4Configure prompt cachingHard
5Cap response lengthMedium
6Configure retries and stop conditionsHard

What to optimize

1. Connect to ChatGPT API

Use ChatGPT API instead of the official OpenAI API. You keep the same models, prompts and token volume while paying 50% less. To switch, get our API key and replace the endpoint.

Connect to ChatGPT API

2. Match the model to task complexity

Do not send classification, field extraction and simple transforms to the most expensive model. Check quality on your own set of examples and use a stronger model only for tasks where it genuinely improves the result.

TypeScript · model routing
const model = task.requiresDeepReasoning
  ? "gpt-5.6-sol"
  : "gpt-5.4-mini";

const res = await client.chat.completions.create({
  model,
  max_completion_tokens: task.requiresLongAnswer ? 1200 : 300,
  messages,
});

3. Trim repeated context

Do not send the whole conversation and every document on each request. Keep the relevant fragments, a summary of previous messages, and the instructions needed for the current step.

Without optimization

  • Full history
  • All documents
  • Repeated instructions

≈ 12,400 input tokens

After optimization

  • Short summary
  • 3 relevant fragments
  • Cached instructions

≈ 3,100 input tokens

−75% input tokens in this example

4. Use prompt caching

Keep stable instructions first and variable data last. For GPT-5.6, set a prompt_cache_key and an explicit cache breakpoint after a repeated prefix of at least 1,024 tokens. Account for both discounted cache reads and cache writes billed at 1.25× the uncached input rate: caching pays off only when the prefix is reused.

TypeScript · stable prefix for the cache
const res = await client.chat.completions.create({
  model: "gpt-5.6-sol",
  max_completion_tokens: 500,
  prompt_cache_key: "support-policy-v1",
  prompt_cache_options: { mode: "explicit" },
  messages: [
    {
      role: "system",
      content: [{
        type: "text",
        text: policyAndInstructions,
        prompt_cache_breakpoint: { mode: "explicit" },
      }],
    },
    { role: "user", content: relevantChunks.join("\n\n") },
  ],
});

Official OpenAI prompt caching documentation ↗

5. Cap the response length

Set a realistic max_completion_tokens and ask the model to answer in the format you need. The limit includes visible output and reasoning tokens. Streaming improves time to first token but does not by itself reduce the number of billed tokens.

TypeScript · limit and streaming
const stream = await client.chat.completions.create({
  model: "gpt-5.6-sol",
  max_completion_tokens: 300, // cap, including reasoning tokens
  stream: true,
  stream_options: { include_usage: true },
  messages: [
    { role: "system", content: "Return only compact JSON with fields summary and risk_level. No Markdown." },
    ...messages,
  ],
});

for await (const chunk of stream) {
  if (chunk.usage) console.log(chunk.usage.completion_tokens); // billed output tokens
}

6. Keep retries under control

Retry only transient errors and use exponential backoff. Do not re-run a successful request because of a UI error or a timeout in your own service.

Check that the savings did not cost you quality

Change one variable at a time and compare on the same set of requests - otherwise you cannot tell what produced the effect. 30-100 typical requests from one expensive feature is enough.

  1. 1Collect the set: 30-100 real requests from one feature, with no personal data.
  2. 2Measure the baseline for the metrics below on that set.
  3. 3Change exactly one variable: endpoint, model, context size, caching or response limit.
  4. 4Re-run the same set and compare the metrics against the baseline.
MetricHow to measureKeep the change if
Cost per actionToken cost ÷ number of successful actionsIt drops noticeably, not by a couple of percent
QualityShare of answers that pass your check or reviewIt stays at the baseline level
Latencyp95 response timeIt does not grow in user-facing flows
ErrorsShare of 4xx/5xx and retried callsIt does not grow after the change

ChatGPT API cost FAQs

What is the fastest way to reduce ChatGPT API costs?

Connect to ChatGPT API first: replacing the API key and endpoint immediately lowers the price of the same tokens by 50%. Then measure usage by product feature, trim context and responses, configure caching, and route simple tasks to a cheaper model.

Does streaming reduce API cost?

No. Streaming improves time to first token, but billing still depends on the input processed and output generated. Use max_completion_tokens and a compact response format to control cost.

When does prompt caching save money?

When many requests reuse the same long prefix. For GPT-5.6, a cacheable prefix must contain at least 1,024 tokens. Compare cached_tokens with cache_write_tokens: cache writes cost more than uncached input, so one-off or frequently changing prefixes may not save money.

How do I verify that an optimization did not hurt quality?

Save 30–100 representative requests without personal data, change one variable, and compare cost, quality, latency and errors on the same set. Keep the change only when output quality remains acceptable.

Next step

Start with the cheapest step: the same models at half the price, with no code to rewrite. Then compare prices and pick the right model for each task.