Draft — pending review · Updated 2026-11-28

Input Output Cache Token Guide for AI Developers

Draft — pending human review. Not yet reviewed or approved.

An input output cache token breakdown tracks three parts of every AI call. First, input tokens count the fresh prompt text you send. Second, cache tokens count repeated prompt text saved in fast storage for reuse. Third, output tokens count the new text the model writes back. Read all three fields in your usage logs to control spend.

What input, output, and cache tokens mean

By Content Team A token is a small piece of text, like a word or part of a word. An AI model splits all text into tokens before it reads or writes a reply. You can group those tokens into three clear buckets: input, output, and cache. Input tokens measure the fresh text in your prompt, which is the message you send to the model. Output tokens measure the new text the model writes back to you in its reply. Cache tokens track repeated input text held in a cache, which is fast storage for reuse. Thinking in three buckets helps you debug slow calls and high bills. A long reply can use more compute than a long prompt. A missed cache also forces the model to re-read static files on every call. Read our token counting guide to see how plain text splits into tokens.

How prompt caching splits input into writes and reads

Prompt caching splits your input into two phases: a cache write and a cache read. On the first call, the model reads your prefix, which is the fixed opening block, and saves it. That first step creates cache write tokens. On the next call, the model checks whether your request starts with the exact same prefix. When it matches, the model loads that saved state as a cache hit, meaning a match in memory. Those reused tokens appear in your logs as cache read tokens. Only the new text after the shared prefix counts as regular input tokens. In a sample code tool, static rules sit at the top while each new diff sits at the bottom. Output tokens stay separate because the model builds a brand-new reply on every call. This split lets you send rich context without paying full compute on every turn.

Reading usage fields in your API response

Every major model API returns a usage object, which is a JSON block that reports token counts. Log those numbers on every call instead of guessing from character length. Raw string length misleads you because code symbols and spaces split differently from plain English words. Look for four core fields in the response: input tokens, cache writes, cache reads, and output tokens. Some providers nest cache numbers inside a details object, while others place them at the top level. Map every provider key into one shared log format inside your backend code. Tracking all four counts together reveals bugs fast. High cache writes paired with zero cache reads show that your prefix changes on every request. High output counts show that your prompt lets the model ramble. Review our prompt caching patterns to map response fields across common developer SDKs.

Structuring prompts for steady cache hits

Good prompt order is the easiest way to turn regular input tokens into cache read tokens. A cache matches from the first byte forward, so constant text belongs at the very top. Put system rules, output format specs, and tool definitions first in every request. Place dynamic data, meaning values that change between calls, near the bottom of your prompt. User names, session IDs, search snippets, and fresh questions belong after the static block. In multi-turn chat, keep older messages untouched so the shared prefix stays valid. Keep your tool list in a fixed order too. If your code reads tools from a map, sort them by name before you build the call. That simple sort stops random key order from breaking your prefix. When every call shares the same static head, your cache hit rate climbs right away.

Common bugs that break your token cache

Small code bugs often break prompt caching without raising an error. Your app still runs, so you only notice the bug when you read token usage logs. Watch for three common mistakes that silently kill cache hits. First, putting a live clock or request ID in the system prompt changes the start every second. Move time and trace tags into a footer message at the end. Second, serializing JSON, which means turning a data object into text, without sorted keys shuffles field order. Sort JSON keys alphabetically before you send tool schemas. Third, dropping old chat turns from the front shifts every message after them. That shift breaks the cached prefix and triggers a fresh cache write on the next turn. Append new turns at the end and trim history only at fixed checkpoints.

Balancing input, output, and cache budgets

Smart token planning looks at the whole call instead of chasing cache hits alone. Output tokens take the most time per token because the model writes them one piece at a time. Clear output limits, like short JSON schemas, lower both cost and latency, which is total wait time. Prompt caching works best when a long static block repeats within the cache lifetime, or warm window. Short prompts or rare one-off jobs may sit below the minimum token threshold for caching. Leave those small calls as regular input tokens instead of forcing a cache write. Test your real payload in staging before you ship changes. Send two back-to-back calls and check that cache reads appear on the second usage block. Use our LLM cost optimization checklist to review prompt size, cache placement, and output caps.

Local hardware for token-heavy work

As an Amazon Associate I earn from qualifying purchases.

Frequently Asked Questions

Do output tokens ever get saved in a prompt cache?

No, output tokens never come straight from a prompt cache because each reply is freshly generated. However, if you add that reply to a chat history, it becomes input on the next turn. At that point, the model can cache it as part of your shared conversation prefix.

Why did my cache read count drop to zero?

A prompt cache requires an exact match from the very first token of your request. Adding a live timestamp, user ID, or shuffled tool key near the top breaks the match right away. Your cache entry may also expire if too much time passes between calls.

How do I check input, output, and cache tokens in code?

Read the usage object inside your API response payload after every call. Log regular input tokens, cache write tokens, cache read tokens, and output tokens into one table. Divide cache read tokens by total input tokens to see how often your static prefix hits memory.

When should I skip prompt caching?

Skip prompt caching when your shared prefix sits below your model provider's minimum cache size. You should also skip it for one-off prompts that never repeat across later calls. Writing a block to cache memory without reading it back wastes setup work.

Audit your next AI request payload today. Move static rules and tools to the top and log every input, output, and cache field. Use the developer tools on mydev.codes to check your token counts before you deploy.