- Vrealmatic
- AI
- Cost Optimization
AI Cost Optimization: the right model, tool and workflow
Where the cost really comes from, when to use a subscription or the API, and seven levers that cut cost without losing quality
A practical guide to reducing AI cost by design: limit context, use caching and batches, avoid unnecessary retries and route each task to the right tool. Including a worked example and the current subscription rules.
Contents
00 · Overview
Cost optimization at a glance
The cheapest AI does not come from picking the cheapest model. Costs grow in the workflow: oversized context, repeated attempts, a strong model on simple steps and manual fixes. The number that matters is the cost per valid result, not the price per request.
In short
- Measure the result - cost of a finished, verified output, not of one model call
- Pick a strategy - a ready-made tool on a subscription, your own API workflow, or a hybrid with an agent
- Trim the context - send only what the step needs and cache the stable part
- Tier the models - plain code and a cheap model first, a strong model only for what fails
- Control retries - attempt limits, local fixes and validation outside the model
What do you need to solve?
| Question | Where to find the answer |
|---|---|
| Why does AI cost more than the price list suggests? | Where the cost comes from → |
| Subscription or API? | Buy, build, hybrid → |
| May I run Claude Code or Codex from a script? | Subscriptions and agents → |
| What discounts does the API offer? | API pricing → |
| Is OpenRouter worth it? | Routers → |
| Where exactly can we save? | Cost levers → |
| Which path fits our process? | Decision → |
Model prices change several times a year. They mostly fall, but not always. Treat the specific numbers here as an illustration of the ratios and check the current price lists linked at the end before you decide.
01 · Anatomy
Where the cost really comes from
One model call costs input tokens times the input price plus output tokens times the output price. A result often needs more calls, a check and a fix. That is why cost is measured at the level of a finished output.
| Component | What it consists of | How to reduce it |
|---|---|---|
| Input | task, instructions, documents, conversation history, tool output | shorter context, retrieving the relevant parts, caching |
| Output | the answer and the model's reasoning (thinking), even when hidden | lower effort, a concise format, structured output |
| Retries | a new attempt pays the full input and output again | fix only the broken part, fix locally, limit attempts |
| Review | the time of a person who checks and corrects the output | automatic validation, tests, clear acceptance criteria |
Worked example: same model, a tenth of the cost
Before: the workflow sends the whole document and the rules, 50 thousand tokens. The output has 2 thousand tokens. It often fails the format check, so a task needs three attempts on average. Total: 36 cents per result.
After: the workflow selects only the relevant parts (12 thousand tokens). Stable instructions and rules (8 thousand tokens) are read from the cache. A parser fixes format errors without the model, so only every fifth task needs a new attempt. Total: about 3.5 cents.
Human time. If a cheaper setup leads to more manual fixes, it ends up more expensive. Track the share of outputs that passed without intervention as well.
02 · Strategies
Buy, build, hybrid
A subscription and the API are not just two price lists. They are a decision about what to buy ready-made and what to run yourself. In practice there are three strategies.
- Buy
A ready-made tool on a subscription
For work where a person keeps deciding: writing, analysis, research, development. You also pay for the interface, history, file handling and built-in features. Costs are predictable, limits too.
- Build
Your own API workflow
For a stable, repeated process. You pay per use and control context, models, budgets, validation and fallbacks. Example: AI SEO Optimizer.
- Hybrid
Your own control plus a ready-made agent
Your system prepares the task and rules, launches an agentic tool from the terminal and checks the result with its own layer. You do not build the agent from scratch and control stays with you.
Implementation cost is often underestimated with the API. A ready-made tool already handles files, step approvals, context recovery and history. With the API you design, build and maintain these yourself. The API becomes cheaper only with repeated or large volume.
03 · Agents
Subscriptions, agents and the terminal
Agentic tools such as Claude Code, Codex or Gemini CLI are more than a chat with a model. They understand a project folder, edit files, run commands and show the changes. They are part of regular subscriptions, so the line between a ready-made tool and the API is blurring.
What a subscription includes
| Subscription | Monthly | Coding agent | Limits |
|---|---|---|---|
| Claude Pro | $20 | Claude Code | five-hour window + weekly limit |
| Claude Max | from $100 | Claude Code, higher limits | five-hour window + weekly limit |
| ChatGPT Plus | $20 | Codex | message limits in a five-hour window |
| ChatGPT Pro | from $100 | Codex, higher limits | higher or no five-hour limit |
Limits are set for the ordinary work of one person. For an individual who uses AI heavily, a subscription is usually much cheaper than the same work through the API. It is not meant for large-scale automation.
Running from a script
Both main tools have a non-interactive mode: claude -p and codex exec. Your system prepares a working directory, the task and the rules, runs the agent as a process and takes its output. You reuse what the agent already does well: repository work, the terminal, diffs and context recovery.
When a subscription, when an API key
A subscription is enough
- your own scripts and automation over your own work
claude -pand the Claude Agent SDK for your own use, within subscription limits- an internal tool where every user signs in with their own account
You need an API key
- a product or service for other users, including ones built on the Agent SDK
- reselling or sharing subscription limits among several people
- CI and public repositories: OpenAI recommends an API key for
codex exec
Anthropic explicitly allows claude -p and the Agent SDK within a subscription, but reserves subscription sign-in for ordinary use of its own apps. Third parties may not offer Claude account sign-in in their products. Check the provider's current terms before putting a hybrid into production.
Validation must sit outside the agent
When AI makes changes on its own, checking them must not depend only on the agent that made them. A safer setup is your own validation layer: tests, allowed paths, diff checks, static analysis, budgets and, where needed, human approval. This is where your own backend has an edge over just launching the agent. Audit and the decision to accept stay with you.
04 · Pricing
API pricing: model tiers, discounts and surcharges
API price lists include several discounts and surcharges on top of the base price. The biggest savings come not from switching provider but from using these mechanisms well.
The price range across model tiers
| Model (Anthropic) | Input / 1M tokens | Output / 1M tokens | Typical use |
|---|---|---|---|
| Claude Haiku 5.5 | $0.10 | $0.50 | classification, extraction, simple high-volume steps |
| Claude Sonnet 5.5 | $2 | $10 | everyday work, agents, code |
| Claude Opus 5.5 | $4 | $20 | demanding tasks, planning, long agentic runs |
| Claude Fable 5.1 | $10 | $50 | the hardest reasoning and longest tasks |
There is a hundredfold difference between the cheapest and the most expensive model. Prices within a tier keep falling: Opus cost $15 / $75 in version 4.1 and $4 / $20 today. OpenAI and Google have a similar range.
Discounts and surcharges
| Mechanism | How much it saves | When it fits |
|---|---|---|
| Prompt caching | cache reads at 0.05–0.1× the input price; writes 1.25× (5 min) or 2× (1 h) | stable instructions, rules, documents, tools and history that repeat |
| Batch processing (Batch API) | 50% off input and output | work that is not urgent: overnight processing, reports, bulk extraction |
| Effort level | fewer reasoning tokens, shorter answers | simple, routine steps |
| Fast mode | 2× surcharge | only where response speed earns money |
| US-only processing (Anthropic) | 1.1× surcharge | when contracts or data rules require it |
Model reasoning (thinking) is billed as output at all three providers, even when you do not see it. The effort level therefore controls cost directly. On Claude Opus 5.5, for example, reasoning cannot be switched off and effort is the only control of its depth.
When a workflow switches between models, each has its own cache, so a model cascade loses part of the caching saving. Before you build one, measure the simpler option: one strong model at lower effort. With new models it often performs as well and costs less.
05 · Routers
OpenRouter as a layer between apps and models
OpenRouter is a layer between your application and the models. It offers one API for hundreds of models from dozens of providers, request routing and fallbacks. It does not improve model quality; it handles model choice and availability.
- Fees: model calls are billed at the provider's price. OpenRouter charges 5.5% on credit purchases by card. With your own provider key (BYOK) it is free up to $25 thousand a month and 5% above that.
- Routing: providers of the same model can be sorted by price, throughput or latency. The auto router picks a model by task type.
- Data: you can exclude providers that store data or require zero data retention (ZDR).
- Cache: works through the router at provider prices. The router keeps requests on the same provider so the cache stays warm.
When it makes sense
- you compare models without rewriting the application
- you need a fallback during outages or rate limits
- you route simple tasks to cheaper models
- you want one bill and one integration
What to watch
- another operational dependency and another data processor
- the same model may behave differently across providers
- provider-specific features may be unavailable
- for sensitive data, set allowed providers and a data policy
A router makes model choice and experiments easier. It pays off most where tasks are split by difficulty and you know which step needs a cheap, fast or strong model.
06 · Levers
Seven cost levers
Costs rarely grow because of the wrong model. They grow because the workflow has no context budget, repeats the same steps, uses a strong model for simple tasks and lets an agent run without a clear end. Start with levers that do not reduce quality: context, caching and retries. Only then lower effort or the model tier.
1. A context budget · no quality loss
A large context window is not free. Each step should have a limit on how much context it may use and where it comes from. For documents, repositories and knowledge bases, retrieve the relevant parts first, summarise long sources and send the model only what the step needs.
2. Caching and a stable prompt prefix · no quality loss
Caching works on a matching prompt prefix. Put the stable parts first: instructions, rules, tool descriptions. Put the changing parts after them: the date, request ID, the actual question. A single change at the start invalidates the whole cache.
Store your own intermediate results too: extractions, summaries, classifications and embeddings. Do not pay twice for the same analysis of the same document.
3. Retry limits · no quality loss
A new attempt pays the full input and output again. If only part of the result is wrong, fix only that part. An automated process needs limits on attempts, runtime, changed files and cost, plus clear behaviour when a limit is hit.
4. Local fixes with ordinary tools · no quality loss
An almost-correct result does not have to go back to the model. For HTML, XML, JSON, Markdown or code, use a parser, formatter, sanitizer or linter. An unclosed element or a badly escaped character is cheaper to fix locally. Structured output against a schema prevents format errors altogether.
5. Batches for anything that can wait · 50% off
Overnight document processing, regular reports or bulk content edits do not need an answer within a second. The batch API is half price at the main providers and the discount stacks with caching.
6. Effort and model cascading · measure quality
Not every step needs the strongest model or the highest effort. Classification, extraction or format conversion is often handled by a cheap model or plain code. Keep the strong model for planning, complex decisions and the final synthesis.
First try lowering effort on a single model. Build a cascade only when measurement shows it pays off. Step down gradually and measure quality on a sample of real tasks after each change.
7. Validation and cost per result · measure continuously
Tests, validators, diff rules and allowed paths are not only safety features. They reduce failed outputs, manual fixes and repeated calls.
Track the cost of a finished output: a resolved request, a processed document, an approved change. A cheaper model that needs five attempts is not cheaper.
- Context, caching and retries first. They do not reduce quality and save the most.
- Batches for everything that can wait.
- Lower effort and model tier only while measuring quality.
07 · Decision
How to choose the right path
Start by asking where unnecessary work happens. If the result comes out of a dialogue and needs human judgement, a ready-made tool is usually cheaper. If the process has stable inputs, outputs, validation and repeated volume, the API pays off. If you want a ready-made agent's abilities with control on your side, choose a hybrid.
- Buy
A ready-made tool
- you need to start quickly
- the work is creative, exploratory or irregular
- the value is in the interface and built-in features
- the process is not clearly defined yet
- Build
An API workflow
- stable inputs and outputs
- frequent or large volume
- you need cost per task, customer or document
- AI is part of an application or backend
- Hybrid
Your own control + an agent
- the task needs a repository, terminal or files
- validation must stay outside the agent
- the backend controls inputs, limits, audit and acceptance
- you do not want to build an agent from scratch
People use ready-made tools for work that needs judgement. The API handles the repeated part of the process. A hybrid layer launches an agent where its abilities fit. A router or your own layer switches models by price, quality and availability.
08 · Checklist
A checklist for one process
Go through one specific process. Every “no” is a place where you probably pay more than you have to.
- You measure cost per finished result, not per request.
- Every step has a context budget.
- You send the model only the relevant parts of the input.
- The stable prompt prefix really is stable and gets cached.
- The model does not do what plain code can do.
- Simple steps go to a cheaper model or lower effort.
- The process has limits on attempts, runtime and cost.
- You fix format errors locally, without regenerating.
- Work that can wait goes through the batch API.
- Validation sits outside the agent that produced the result.
- You know whether a person, an application or an agent uses AI, and pick a subscription or the API accordingly.
- You know which data goes to which provider.
09 · Summary
Summary
AI cost optimization is not a hunt for the cheapest model. It is the design of a process that sends no unnecessary context, does not use an expensive model for simple steps, does not repeat the same work and measures the cost of a usable result.
Only then does it make sense to choose between a ready-made tool, the API, a hybrid agent launch and a router. The price list matters, but the real saving comes from the workflow architecture.
- Do not ask what the model costs. Ask what a valid result costs.
- Subscriptions for people's work, the API for a repeated process, a hybrid for an agent under your own control.
- The biggest savings: shorter context, caching, fewer retries and batches.
- Validation outside the model saves money and lowers risk.
Sources
Sources and further reading
Price lists and terms this article is based on (as of 2026-10-15):
- Anthropic: API pricingModel prices, caching, batches and surcharges.
- Claude Code: legal and complianceSubscription sign-in, API keys and the Agent SDK.
- OpenAI: API pricingModel prices, caching, Batch and Flex.
- Google: Gemini API pricingModel prices, context caching and batches.
- OpenRouter: FAQFees, credits and BYOK.
- OpenRouter: provider routingProvider sorting, data policy and ZDR.
Further reading
- Value vs. security when using AIBoundaries for AI tools, data, permissions and agents.
- AI Automation: Process First, AI SecondFinding suitable workflows and moving step by step to controlled automation.
- Automation serverAn environment where AI workflows run under your own control.
- AI Assistant for Human WorkA personal AI assistant set up around an employee's real work.
How to cite this publication (APA 7)Nepor, V. (2026, October 15). AI Cost Optimization: Use the Right Model, Tool, and Workflow. Vrealmatic. https://vrealmatic.com/ai/cost-optimization
Want to make AI cheaper without making it worse?
We map your AI workflows, design the right mix of subscriptions and API usage, set limits and model routing, and measure the cost per result.