Skip to main content

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:
  1. Using the most expensive model for trial and error
  2. Restarting the same task repeatedly, which rebuilds the cache from zero
  3. Asking a text model to figure out an image API on its own
Fix them in this order and most unnecessary spend disappears:
  • Test with gpt-5.6-luna or gpt-6.2-sol; move to gpt-6.2-astra only 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
A large input does not mean a large bill. Cached input bills at 5% of the input price, so tens of thousands of input tokens can cost a few cents. Cache writes and output are the expensive parts. Do not judge a bill by the input-tokens column alone.

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):
The 6.2 generation has only gpt-6.2-astra and gpt-6.2-sol — there is no 6.2-luna or 6.2-terra. For a cheaper tier, use the 5.6-generation gpt-5.6-luna / gpt-5.6-terra, or simply gpt-6.2-sol.
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.
Some model groups carry additional discounts. Availability depends on your console token group — see What’s the difference between the Codex, ClaudeCode, and Default groups?.

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
In this case, the first request of every new conversation carried 29k–34k input tokens. That prefix has to be written to cache again; at 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:
Put recurring constraints in the project’s AGENTS.md instead of repeating them every time. But AGENTS.md itself is read on every turn, so keep it to a few dozen lines — do not paste an entire spec into it.
For the full workflow breakdown and more templates, see Natural-Language Image Generation in AI Agents.

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 a SKILL.md plus a script:
  • Default model gpt-image-2.6-all at 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
Once installed, the agent runs the script directly instead of reading docs and writing scaffolding. A Skill does not make cost zero: images are still billed per image or per image token, and the agent’s text turns are still billed. What it removes is the exploration cost. See GPT-Image Series Agent Skill.

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.

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:
  1. In the console logs, look at four columns: input, output, cache reads, cache writes
  2. Export by model, by day, and by token to see which one is growing
  3. Check the request path first: /v1/responses is a text call; only /v1/images/* is an image call
  4. Recompute one request from the returned usage × the unit price and confirm it matches the logged amount
For what each log column means, see How do I view my call records? and How do I read the billing amount in the logs?.

FAQ

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.
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.
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?.
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.
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.
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.

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