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
Via ChatGPT API: $11.25 per month. Savings per month: $11.25.
Estimated budget
At official rates
per month
$22.50
Via ChatGPT API
per month
$11.25
Savings per month
$11.25
Savings per year
$135.00
The estimate uses the selected model's current prices without prompt caching. It shows the order of magnitude, not a cent-accurate future bill.
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.
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 shows | Where the bill grows | What to check first |
|---|---|---|
| Large prompts in RAG or chat | input_tokens | Retrieval, history, prompt caching |
| Answer longer than the UI needs | output_tokens | max_completion_tokens and response format |
| Many calls per action | retries or agent loop | Backoff, stop conditions, duplicates |
| One model serves every task | price of each token | Route 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.
| Priority | What to do | Difficulty |
|---|---|---|
| 1 | Connect to ChatGPT API | Low |
| 2 | Match the model to task complexity | Medium |
| 3 | Trim repeated context | Medium |
| 4 | Configure prompt caching | Hard |
| 5 | Cap response length | Medium |
| 6 | Configure retries and stop conditions | Hard |
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 API2. 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.
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.
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") },
],
});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.
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.
- 1Collect the set: 30-100 real requests from one feature, with no personal data.
- 2Measure the baseline for the metrics below on that set.
- 3Change exactly one variable: endpoint, model, context size, caching or response limit.
- 4Re-run the same set and compare the metrics against the baseline.
| Metric | How to measure | Keep the change if |
|---|---|---|
| Cost per action | Token cost ÷ number of successful actions | It drops noticeably, not by a couple of percent |
| Quality | Share of answers that pass your check or review | It stays at the baseline level |
| Latency | p95 response time | It does not grow in user-facing flows |
| Errors | Share of 4xx/5xx and retried calls | It 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.