> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apiyi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# How Can I Use the API More Economically?

> A practical checklist for cutting API costs — model tiers, agent context, prompt constraints, cache billing, Skills, and image tools — plus a real Codex task breakdown showing that a large input does not mean a large bill.

## 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:

| Billing item | How it arises | Typical rate (`gpt-6.2-astra`) |
| - | - | - |
| Uncached input | Prompt tokens that did not hit cache | \$8 / 1M tokens |
| Cache read | The portion that hit a prefix cache | \$0.4 / 1M tokens (5% of input) |
| Cache write | A prefix newly written to cache | \$10 / 1M tokens (1.25× input) |
| Output | The generated completion | \$40 / 1M tokens (5× input) |

**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

> [!TIP]
>
> **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:

| Model | Tier | Input | Cache read | Output |
| - | - | -: | -: | -: |
| `gpt-5.6-luna` | 5.6 lightweight | \$0.2 | \$0.02 | \$1.2 |
| `gpt-6.2-sol` | 6.2 balanced | \$2 | \$0.1 | \$10 |
| `gpt-5.6-terra` | 5.6 balanced | \$2 | \$0.2 | \$12 |
| `gpt-6.2-astra` | 6.2 flagship | \$8 | \$0.4 | \$40 |

Estimated cost for the same token shape (about 47 turns, 2.2M input, 90% cache hits):

| Model | Estimated cost | Relative to astra |
| - | -: | -: |
| `gpt-5.6-luna` | about \$0.1 | about 3% |
| `gpt-6.2-sol` | about \$0.8 | about 25% |
| `gpt-5.6-terra` | about \$1.1 | about 32% |
| `gpt-6.2-astra` | about \$3.3 | 100% |

> [!WARNING]
>
> **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`.

> [!NOTE]
>
> 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.

> [!NOTE]
>
> 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](https://docs.apiyi.com/en/models/index.md). Listed prices match the official rates; after recharge bonuses, the effective price is about 83–91% of the listed price. See [Recharge Promotions](https://docs.apiyi.com/en/faq/recharge-promotions.md).

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?](https://docs.apiyi.com/en/faq/codex-claudecode-default-groups.md).

## 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?](https://docs.apiyi.com/en/faq/api-memory.md). For Codex's fixed costs, see [OpenAI Codex](https://docs.apiyi.com/en/scenarios/programming/codex-cli.md).

## 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:

```text theme={null}
Only work on the two images I specify: /path/a.png and /path/b.png.
Do not scan directories, do not read other files, do not modify code.
Put the person from a.png into the scene in b.png, keeping b.png's lighting and color.
Call /v1/images/edits directly with gpt-image-2.6-sunburst, and write the result to /path/out.png.
When done, reply only with the output path and the cost. Do not explain the process.
```

```text theme={null}
Do not run ls, find, grep, or any directory scan.
Use only the file paths and parameters I give you in the message.
If a path is missing, ask me — do not go looking for it.
```

```text theme={null}
Execute directly. Do not restate the request, do not compare options, do not print intermediate reasoning.
At the end, reply only with: what you did, the output file path, and any failure reason.
If a parameter is uncertain, pick the default and continue; do not stop to ask.
```

> [!TIP]
>
> 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](https://docs.apiyi.com/en/scenarios/programming/agent-image-generation.md).

## 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](https://docs.apiyi.com/en/api-capabilities/gpt-image-2/skills.md).

## 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](https://imagen.apiyi.com) (`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.

> [!NOTE]
>
> 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](https://docs.apiyi.com/en/models/index.md).

## 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_tokens` to cap a single response; see [What is max\_tokens?](https://docs.apiyi.com/en/faq/max-tokens.md)
* 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](https://docs.apiyi.com/en/faq/log-duration-vs-client-wait.md)

## 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?](https://docs.apiyi.com/en/faq/token-model-whitelist.md)
* Set balance alerts so abnormal consumption is visible immediately; see [How do I set up balance alerts?](https://docs.apiyi.com/en/faq/balance-alerts.md)
* 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](https://docs.apiyi.com/en/faq/recharge-promotions.md).

## 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?](https://docs.apiyi.com/en/faq/call-logs.md) and [How do I read the billing amount in the logs?](https://docs.apiyi.com/en/faq/log-billing-explained.md).

## FAQ

> [accordion] 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.

> [accordion] 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.

> [accordion] 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?](https://docs.apiyi.com/en/faq/cache-billing.md).

> [accordion] 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](https://docs.apiyi.com/en/models/index.md) as the source of truth.

> [accordion] 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](https://docs.apiyi.com/en/api-capabilities/claude-prompt-caching.md).

> [accordion] 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

> [card] [Model Pricing](https://docs.apiyi.com/en/models/index.md)
>
> Live pricing for every model, with per-token and per-call billing

> [card] [How do I choose an AI model?](https://docs.apiyi.com/en/faq/model-selection-guide.md)
>
> Pick by task, budget, and real-world results

> [card] [Reading billing in the logs](https://docs.apiyi.com/en/faq/log-billing-explained.md)
>
> Log columns, per-token vs per-call, pre-discount amounts

> [card] [Cache billing](https://docs.apiyi.com/en/faq/cache-billing.md)
>
> Trigger methods and hit prices across the three channels

> [card] [Natural-language image generation in agents](https://docs.apiyi.com/en/scenarios/programming/agent-image-generation.md)
>
> The full path from a chat request to the Images API, with prompt templates

> [card] [OpenAI Codex setup](https://docs.apiyi.com/en/scenarios/programming/codex-cli.md)
>
> base\_url, the responses protocol, and cost notes


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.