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.

Vladimír NeporAuthorVladimír Nepor
PublishedUpdated
The price list shows the price per request. The workflow decides the bill: how much context is sent, how often a step is repeated, which model gets which step and what is cached. The real number is the cost per valid result.Price per requestinput · $/1M tokensoutput · $/1M tokenswhat the price list showsWorkflowcontext × attemptsmodel per stepcache and batches÷ valid resultswhere savings come fromCost per result≈ 10×difference in theworked example (ch. 01)01 · ANATOMYWhere the cost comes fromcontext, output, retrieschapter →02 · STRATEGIESBuy, build, hybridsubscription × API × agentchapter →06 · LEVERSSeven cost leverscontext, cascade, cache, retrieschapter →07 · DECISIONHow to choosea decision treechapter →
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

  1. Measure the result - cost of a finished, verified output, not of one model call
  2. Pick a strategy - a ready-made tool on a subscription, your own API workflow, or a hybrid with an agent
  3. Trim the context - send only what the step needs and cache the stable part
  4. Tier the models - plain code and a cheap model first, a strong model only for what fails
  5. Control retries - attempt limits, local fixes and validation outside the model

What do you need to solve?

QuestionWhere 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 →
As of October 2026

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.

ComponentWhat it consists ofHow to reduce it
Inputtask, instructions, documents, conversation history, tool outputshorter context, retrieving the relevant parts, caching
Outputthe answer and the model's reasoning (thinking), even when hiddenlower effort, a concise format, structured output
Retriesa new attempt pays the full input and output againfix only the broken part, fix locally, limit attempts
Reviewthe time of a person who checks and corrects the outputautomatic validation, tests, clear acceptance criteria

Worked example: same model, a tenth of the cost

Worked example for one result: before optimisation it costs 36 cents (context 10, output 2, retries 24), after optimisation about 3.5 cents (context 0.88, output 2, retries 0.58). The saving comes from context and retries, not from the model price.context (input)outputretriesBefore36 ¢50k context · 3 attemptsAfter≈ 3.5 ¢12k context (8k cached) · 1.2 attempts0122436cost of one valid result in US centssame model · same output quality
One processed document on Claude Sonnet 5.5 ($2 input, $10 output, $0.10 cache read per 1M tokens). The saving comes from context and retries. The output cost stays the same.

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.

What the number leaves out

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.

Schematic: a subscription grows in steps (higher plan, more seats) and is not meant for large-scale automation. The API starts higher because of development and operations and then grows with volume. Hybrid uses subscriptions for people and the API for the repeated process. The break-even point sits where the process is stable and repeated.large-scale automationoutside subscription usemonthly costvolume of repeated work →break-evenBuy · subscriptionsteps: higher plan, more seatsBuild · APIfixed dev and ops + tokensHybrid
A schematic without specific numbers. A subscription grows in steps and is meant for people's work. The API costs more up front for development and operations but scales with volume. The break-even point sits where the process is stable and repeated.
The cost of the work around the model

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

Prices excluding VAT as of October 2026. Providers do not publish exact limits and adjust them over time.
SubscriptionMonthlyCoding agentLimits
Claude Pro$20Claude Codefive-hour window + weekly limit
Claude Maxfrom $100Claude Code, higher limitsfive-hour window + weekly limit
ChatGPT Plus$20Codexmessage limits in a five-hour window
ChatGPT Profrom $100Codex, higher limitshigher 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 -p and 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
The rules change

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

Anthropic price list as of 2026-10-15. Haiku 5.5 costs five times more above 100 thousand input tokens. The other models include the full 1M window at the same price.
Model (Anthropic)Input / 1M tokensOutput / 1M tokensTypical use
Claude Haiku 5.5$0.10$0.50classification, extraction, simple high-volume steps
Claude Sonnet 5.5$2$10everyday work, agents, code
Claude Opus 5.5$4$20demanding tasks, planning, long agentic runs
Claude Fable 5.1$10$50the 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

Anthropic, OpenAI and Google all offer caching and batches. Exact multipliers differ by provider and model.
MechanismHow much it savesWhen it fits
Prompt cachingcache 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 outputwork that is not urgent: overnight processing, reports, bulk extraction
Effort levelfewer reasoning tokens, shorter answerssimple, routine steps
Fast mode2× surchargeonly where response speed earns money
US-only processing (Anthropic)1.1× surchargewhen 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.

The cache is tied to the model

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 does not replace workflow design

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.

Cascade: a task first goes to plain code (parser, rules), then to a cheap model or lower effort. A validator decides whether the result is usable. Only what fails moves to a stronger model, and only then to a person.✓ resultPlain codeparser, rulesvalidatorfailedCheap modelor lower effortvalidatorfailedStrong modelhigher effortvalidatorfailedPersonadds a rulecheapestmost expensive
A cascade: every step has a validator and only what fails moves on. Most of the work is handled by plain code or a cheap model. Only the exceptions reach the most expensive stages.
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.

Key takeaways
  • 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.

Decision tree: Does a person keep deciding? Yes: a ready-made tool on a subscription. No: Is the process stable and repeated? No: run it by hand in a ready-made tool first. Yes: Does the task need a repository, terminal or files? Yes: hybrid, an agent run by a script with your own validation. No: your own API workflow.Does a person keep deciding?Stable and repeated process?Repo, terminal, files?yesnonoyesyesnoBUYReady toolchat or agenton a subscriptionBUY, FOR NOWManual firstin a ready-made tool,then measureHYBRIDManaged agentagent from a scriptown validationBUILDOwn APIAPI workflowmodel cascade
A decision tree for one process. In a company, all three paths usually run side by side for different tasks.
  • 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
The most common outcome: a combination

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.

Key takeaways
  • 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

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.

Contact us