Short answer
An API bill has four parts: uncached input, cache reads, cache writes, and output (per-call models are priced per call). In agent workflows, the usual waste is not the unit price. It is three habits:- Using the most expensive model for trial and error
- Restarting the same task repeatedly, which rebuilds the cache from zero
- Asking a text model to figure out an image API on its own
- Test with
gpt-5.6-lunaorgpt-6.2-sol; move togpt-6.2-astraonly after the approach is settled - Open a new conversation when you switch tasks, not in the middle of one
- Constrain what the agent may read and which tools it may call
- Generate images through the Images API or a Skill, not by letting a text model explore first
- Use the logs to see whether the money went to input, output, cache writes, or cache reads
First: where one request’s money goes
A text request is usually billed across four items:
Real breakdown: on 2026-11-27 at 10:08 (UTC+8), a user doing image compositing in Codex sent one
gpt-6.2-astra request with about 58k input and about 300 output tokens. About 56k input tokens hit cache (96.5%), and the request cost about $0.055:
- Cache reads: about 56k × $0.4/M ≈ $0.022
- Cache writes: about 2,000 × $10/M ≈ $0.020
- Output: about 300 × $40/M ≈ $0.012
- Uncached input billed at $8/M: only a handful of tokens
Option 1: Tier your models — cheap first, flagship last
For the same task, get the workflow and prompts working on a cheaper tier first, then move to the flagship for the final output:
Estimated cost for the same token shape (about 47 turns, 2.2M input, 90% cache hits):
These estimates hold the token volume constant; they do not mean a cheaper model can do the same work. The right pattern is: the cheap tier handles trial and error, the flagship handles the final output.
Model prices match the official rates and may change with them; the table above is for reference only. The authoritative source is the Model Pricing tab in the top navigation: Model Pricing. Listed prices match the official rates; after recharge bonuses, the effective price is about 83–91% of the listed price. See Recharge Promotions.
Option 2: Control agent context, but do not restart constantly
In agents such as Codex and Claude Code, opening a new conversation clears the message history, but not the fixed layers:- The system prompt and tool definitions
- Project rules (
AGENTS.md/CLAUDE.md) - Current project context and directory information
gpt-6.2-astra’s $10 / 1M rate, that is about $0.3 each time.
More importantly, this task saw four cache writes from zero (the initial cold start plus three rebuilds) in 59 minutes, with gaps ranging from 1 minute to 25 minutes. Together they cost about $1.23; the three rebuilds alone accounted for about $0.95 — nearly a third of the astra bill. Some gaps exceeded the cache’s readable window; others were new conversations with a different cache key.
What to do:
- Open a new conversation when you switch tasks, so the previous task’s context does not leak in
- Finish one task in one run; do not interrupt and restart repeatedly
- If you step away for a few minutes, accept one cache rebuild when you return — but do not restart several times in a row
AGENTS.md and Codex’s local memories are read and billed as input on every turn; see Does the API have memory like ChatGPT?. For Codex’s fixed costs, see OpenAI Codex.
Option 3: Use prompts to bound the agent
An agent decides which files to read and which commands to run. Writing the boundary into the prompt directly reduces wasted input:Option 4: Let the agent use a Skill instead of exploring the API
Without a Skill, an agent asked to “blend these images” tends to explore first: find files, read code, look up the API, write a sample script, try parameters. All of that bills as text tokens, and it may run for a long time without ever calling the image endpoint. APIYI’s GPT-Image Skills package the “how to call the API” knowledge into aSKILL.md plus a script:
- Default model
gpt-image-2.6-allat a flat $0.025 per image — the cheapest way to iterate - One script covers 11 models plus 1 alias, with text-to-image, multi-image fusion, and local repaint
- Multi-image fusion accepts up to 16 input images
Option 5: Do not route image work through a text model
Image work has dedicated endpoints:/v1/images/generations for text-to-image and /v1/images/edits for edits and multi-image fusion. Image models bill per image or per image token, usually far less than letting a text model take the long way around.
If you do not need an agent for image work, use AI Image Master (imagen.apiyi.com): the same APIYI key and the same image endpoints, with only image API charges and no text-model charges. It is suitable for validating prompts, comparing models, and small batches; for production batches, still call the API so you can monitor, retry, and reconcile.
AI Image Master is a web test bench, not a cheaper channel. Images still bill at the price of the image model you select; see Model Pricing.
Option 6: Keep output and retries under control
gpt-6.2-astra output costs $40 / 1M tokens, five times the $8 / 1M input rate. Telling the agent to “skip the explanation and just execute” is often more effective than trimming input.
- Use
max_tokensto cap a single response; see What is max_tokens? - Ask for “the result and only the necessary explanation”
- Check the logs before retrying: a request that the gateway completed but your client timed out on is still billed, so a blind retry can pay twice. See The log says the call completed and billed, but the client got no response
Option 7: Backstop with token whitelists and balance alerts
- Restrict test tokens to a model whitelist containing only cheap tiers, so they cannot accidentally call a flagship model; see Do tokens need a model whitelist?
- Set balance alerts so abnormal consumption is visible immediately; see How do I set up balance alerts?
- Keep production and test tokens separate so you can measure and disable them independently
Recharge bonuses: listed prices unchanged, effective price about 83–91%
Model prices match the official rates item by item, converted at the fixed 1:7 rate. The fixed rate is not a discount rate. The savings come from recharge bonuses, not from a lower model unit price. Recharge bonuses come in 10% / 12% / 15% / 20% tiers, which work out to about 91 / 89 / 87 / 83% of the listed price. For the exact tiers, validity, and stacking rules, see Recharge Promotions.Self-check list
When a bill looks higher than expected, check in this order:- In the console logs, look at four columns: input, output, cache reads, cache writes
- Export by model, by day, and by token to see which one is growing
- Check the request path first:
/v1/responsesis a text call; only/v1/images/*is an image call - Recompute one request from the returned
usage× the unit price and confirm it matches the logged amount
FAQ
Why does a new conversation still start with tens of thousands of input tokens?
Why does a new conversation still start with tens of thousands of input tokens?
A new conversation clears the message history, but the system prompt, tool definitions,
AGENTS.md, and project context are read again. In this case every new conversation started with 29k–34k input tokens. That is the agent’s fixed base, not leftovers from the previous conversation.Why is the input large but the bill small?
Why is the input large but the bill small?
Cached input bills at 5% of the input price. In this case one request had about 58k input tokens, 96.5% of which hit cache, so the input side cost only about $0.04. Judge cost by “uncached input + cache write + output”, not by total input alone.
Why did the cache miss?
Why did the cache miss?
Three common causes: the prefix changed (a different system prompt, tool definition, or project rule), you were away longer than the cache’s readable window, or a new conversation produced a different cache key. Keep the prefix stable and finish a task in one run and the hit rate improves noticeably. See Does APIYI support cache billing?.
Why do OpenAI models have cache write charges?
Why do OpenAI models have cache write charges?
OpenAI cache-write billing depends on the generation: GPT-5.5 and earlier write for free; GPT-5.6 / GPT-6.x bill writes at 1.25× the input price (astra: $10 / 1M), recorded in the log as
cache_creation. That is the official cache-billing rule, not an extra relay fee; use the actual log and Model Pricing as the source of truth.Why is Claude more expensive inside Codex?
Why is Claude more expensive inside Codex?
Claude has no native
/v1/responses endpoint, so inside Codex it can only run in OpenAI-compatible chat mode. cache_control cannot be sent, cache reads and writes stay at zero, and the full context is re-billed at the normal rate every turn. Long tasks multiply the bill. See Claude Prompt Caching Billing Guide.Will a cheaper model do a worse job?
Will a cheaper model do a worse job?
Tiering does not mean the cheap model does all the work. The cheap tier gets the workflow, prompts, and parameters working; the flagship produces the final output once the approach is settled. That controls trial-and-error cost without sacrificing final quality.
Related docs
Model Pricing
Live pricing for every model, with per-token and per-call billing
How do I choose an AI model?
Pick by task, budget, and real-world results
Reading billing in the logs
Log columns, per-token vs per-call, pre-discount amounts
Cache billing
Trigger methods and hit prices across the three channels
Natural-language image generation in agents
The full path from a chat request to the Images API, with prompt templates
OpenAI Codex setup
base_url, the responses protocol, and cost notes