Every Token Counts
Your app works. Now it has users, and two questions come up quickly: how much is this costing? and why does that answer take so long? Both come down to a few choices: which model you call, how much text you send and get back, whether repeated text is cached, and how hard you ask the model to think. This lesson shows how each one works on Gloo and how to measure it.Core Concepts
How a Request Is Priced
You pay per token, at the rate of the model you call. Input tokens (what you send) and output tokens (what the model writes) have separate rates, listed per million tokens. The rates come from the public model catalog,GET /platform/v2/models. Each model’s pricing object has input and output, each with rate_per_1m_tokens. These are list prices. What you pay depends on the endpoint:
Every response tells you what it used, in
usage. On the Responses endpoints that’s input_tokens and output_tokens; on Chat Completions, prompt_tokens and completion_tokens.
Prompt Caching
Many requests start with the same text: a long system prompt, a shared document, the early turns of a conversation. Prompt caching lets the provider reuse its work on that repeated beginning, called the prompt prefix. Cached tokens are billed at a discounted rate, and responses arrive faster. How you turn it on depends on the provider:
For the discount to apply, the repeated text has to come first. Put your instructions and any shared documents at the start, and the parts that change, such as the user’s question, at the end.
Rates differ by provider. For example, Anthropic cache reads cost 10% of the input rate on most models and less on some newer ones (5% on Claude Opus 5.5 and Sonnet 5.5, 2.5% on Claude Fable 5.1), while cache writes cost 125% (for
5m) or 200% (for 1h). Most OpenAI models charge nothing to write the cache, though some newer ones do. The Prompt Caching guide explains each provider, and the models endpoint lists every model’s exact rates.
Choosing a Model
Pick a model for each job:- Start from what the task needs. Check the catalog for the capabilities you rely on (
supports_tools,supports_vision,supports_reasoning) and acontext_windowbig enough for your inputs. - Compare rates. Models that can do the job may differ a lot in price.
- Test with your own prompts. Run a handful of real examples through two or three candidates and compare quality, speed and cost. The Chat Playground is a quick way to try them, and the Model Explorer compares them side by side, with speed ratings.
- Pin the model in production. A fixed model ID means routing never swaps in a different model. When a pinned model is retired, its requests go to a replacement that can be priced differently, so check your models for deprecations (Lesson 9’s Models Come and Go).
Reasoning Effort
Reasoning models think before they answer, and that thinking is billed as output tokens, whether or not you see it. More effort usually means a better answer on hard problems, and also more tokens and a longer wait. (AI 102’s Models That Think Before They Answer explains reasoning from the start.) On the Responses and Chat Completions endpoints, you set it withreasoning: {"effort": ...} (or reasoning_effort on Chat Completions). The levels run from none through minimal, low, medium, high and xhigh to max. Four things to know:
- Send a level the model lists. Each model’s
reasoning.effort_levelsin the catalog shows the levels it runs as sent. A level it doesn’t list isn’t guaranteed: the request may run and list it inignored_params, or return400. - Many models reason by default. With no setting, a model does what its provider does by default, and you pay for that reasoning too. The catalog’s
thinks_by_defaulttells you which ones. nonedoesn’t always turn reasoning off. It does on models whoseeffort_levelsincludenone. On others, such as Claude 5 models, it isn’t reliable, and the reasoning they do is still billed.- Reasoning uses your output limit. It counts toward
max_output_tokens(ormax_tokens). A high effort with a small limit can use it all before the answer starts.
Get Started
This script looks up a model’s rates and reasoning levels in the catalog, sends a request at a level the model lists, and estimates what it cost at list price.Python
Turn On Caching
For an Anthropic model on the guarded Completions endpoint, add one header:cURL
prompt_cache_key to the body, and change it when you change the system prompt:
cached_tokens in the response’s usage (input_tokens_details.cached_tokens on Responses, prompt_tokens_details.cached_tokens on Chat Completions), and compare your input costs over time in the billing dashboard.
Go further: the Prompt Caching tutorial restructures a prompt so it hits the cache, turns caching on for Claude and OpenAI models and measures the savings. The Reasoning tutorial picks an effort level the model supports, sizes the output limit and catches cut-off answers.
Good to Know
- Measure before you optimize. Log
usagefor every request so you know where tokens go. Conversation history (Lesson 2) grows with every turn, so watch long chats. - Stable text first, changing text last. This one habit helps caching on every provider.
- Failover means fewer cache hits for a while. Caches are held by each provider, so a request served by a different provider doesn’t read the cache built on the original one.
- Check
ignored_params. When an effort isn’t applied as sent, the response lists it there. Match on theparamslist, not thereasontext. - Stream for speed you can feel. Streaming (Lesson 1) doesn’t make the answer cheaper, but the first words appear much sooner.
Key Takeaway
Cost is tokens times the model’s rate, plus 6.5% on guarded endpoints and Grounded Completions. Lower it by choosing a model that fits the task, putting repeated text first so it can be cached, and setting a reasoning effort the model lists, no higher than the task needs. Measure withusage on every response and check real spend in Studio.
Learn more
- Pricing at a Glance and Billing & Plans: how credits and pricing work
- Prompt Caching: every provider’s caching type, rates and best practices
- Reasoning: effort levels, defaults by model family and the output limit
- Prompt Caching tutorial and Reasoning tutorial: step-by-step projects in Python and TypeScript
- Endpoint Types: Choosing a model: pinning, capabilities and deprecation
What’s next
In the last lesson, you’ll handle rate limits and errors, see how failover keeps your app running, and keep up with model changes.Lesson 9: Production-Ready
Rate limits and retries, failover and routing, and model lifecycle.

