Input vs Output Tokens: Cut AI Costs Fast
Why token mix matters more than most teams think
When teams talk about AI cost, they usually ask, “Which model is cheapest?” That’s only half the story. For most API workloads, your bill is driven by input tokens plus output tokens, and the cheapest model can still get expensive if you send long prompts or request long answers. The right optimization is not just “use a smaller model,” but “control both sides of the token equation.”
A simple way to think about cost is:
total cost = input tokens × input rate + output tokens × output rate
Because output is often priced higher than input, a short prompt with a very long completion can cost more than a large prompt with a concise answer. That means you can save money by tightening prompts, limiting response length, and choosing the right model for the job.
A practical example: support reply generator
Imagine you are generating first-draft support replies. A common pattern is to paste the full ticket history, policy docs, and product notes into the prompt. That creates a huge input token count. If you also ask for a “detailed and helpful” response without a length cap, output tokens can balloon too.
Here is a lightweight way to structure the request with the OpenAI SDK using 59API as the relay base URL:
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.59api.com",
apiKey: process.env.API_KEY,
});
const response = await client.responses.create({
model: "gpt-4.1-mini",
input: "Summarize this customer issue in 3 bullets and draft a concise reply. Ticket: ...",
max_output_tokens: 180
});
Two choices here reduce cost immediately: the prompt asks for a specific format, and max_output_tokens keeps the answer short. In production, this often cuts output spending more effectively than changing models.
How to reduce input tokens without losing quality
- Trim context ruthlessly. Send only the latest messages, relevant fields, and the minimum policy text needed for the task.
- Summarize before you escalate. For long conversations, create a compact running summary instead of re-sending the entire thread every time.
- Use retrieval, not giant prompts. Fetch only the top 3–5 relevant docs or passages instead of dumping your whole knowledge base.
- Remove repetition. If your system prompt repeats brand voice, safety rules, and output format in every call, refactor it once and reuse it.
For example, instead of sending ten full product pages, you can precompute a summary object:
{
"product": "Acme CRM",
"issue": "login failure after password reset",
"policy": "Offer reset link, verify email, escalate after 2 failed attempts",
"tone": "friendly, concise"
}
Structured input like this is smaller, easier for the model to parse, and far cheaper than a raw transcript.
How to keep output tokens under control
Output is where many budgets drift. The fastest fix is to tell the model exactly what you want.
- Set a hard cap. Use max_output_tokens or the equivalent in your SDK.
- Ask for a bounded format. “Return 5 bullets” is cheaper than “explain in detail.”
- Prefer summaries over essays. If the user only needs a decision, don’t request full reasoning.
- Stream only when needed. Streaming improves UX, but it does not reduce token usage by itself.
A good pattern for chatbots is: answer in one paragraph, then optionally add a short action list. That keeps responses useful and predictable.
Balance cost with model choice
Not every task should use the same model. Small, repetitive tasks like classification, extraction, or short replies usually work well on lower-cost models. Harder reasoning or long-form synthesis may justify a stronger model. The best savings come from matching the model to the task and controlling the token budget around it.
This is where 59API stands out. It gives developers cheap, pay-as-you-go access to Claude models like Opus, Sonnet, Haiku, and Fable, plus GPT models, with native official-quality output and no artificial downgrade. Because it is compatible with Claude Code, Codex, and any OpenAI SDK, you can optimize token usage without rewriting your stack. The relay runs on the base URL https://api.59api.com, so switching is straightforward.
A simple workflow for cheaper AI calls
- Measure first. Log prompt size and completion size per request.
- Set per-endpoint budgets. For example, 300 input tokens and 120 output tokens for FAQ replies.
- Compress prompts. Replace verbose instructions with concise templates.
- Cap outputs. Make long answers an explicit opt-in.
- Use cheaper models where acceptable. Reserve premium models for the few calls that truly need them.
If you want to see how much your workload can drop when token mix is optimized, sign up for 59API and test the same prompts with a tighter prompt budget and lower-cost model routing. The referral rebate is a nice bonus once you start sharing it with your team or community.
The bottom line: input tokens are what you send, output tokens are what you ask for, and the cheapest AI system is the one that carefully balances both.
Prêt à commencer ?
Connectez Claude et GPT en quelques minutes aux prix les plus bas, sans bridage. Inscrivez-vous pour votre clé API.
Inscription gratuite