Back to Guides

Reduce LLM API Costs Without Lowering Task Success

Measure LLM cost per accepted customer task, then test model routing, prompt caching and batch execution under realistic workloads.

John Potess11 min read
Illustrative cost per accepted task: 10 cents at baseline, 7 cents with a cache change, and 6.25 cents with a model change.

To reduce LLM API costs, start with cost per accepted customer task, not the cheapest token or request. Measure one outcome against a fixed quality bar and timing limit. Then test one fitting change: cache repeated context, batch work that can wait, adjust a model or effort setting, or revisit how the application runtime is billed. Keep a change only if the product still delivers the required result at a better cost.

A lower bill per request is not an improvement if more users receive unusable answers. Conversely, a lower cost per successful task can make a previously uneconomic feature worth offering, even when total monthly spend rises with usage.

Scope: This is a ShipFoundry-authored, documentation-based engineering guide. Anthropic, Vercel and ShipFoundry documentation was reviewed on November 9, 2026. The calculations below are invented teaching examples, not hands-on benchmark results or customer savings.

Measure the customer outcome, not just the model call

An API call is one priced operation. An agent run may include multiple model calls, tools and retries. A successful task is the result the customer actually needed, such as a structured product record whose required fields are correct and traceable to the supplied source. Those three units are not interchangeable.

For a fixed evaluation set:

Cost per accepted result = all variable spend for attempted work / number of results that meet the acceptance rule.

Include unsuccessful attempts in the numerator. Count each accepted customer task once in the denominator, even if it took several attempts. When relevant, count input and output tokens, cache writes and reads, external tools, required retries, queue or orchestration fees, and the compute used to serve the feature. If a human must correct failures, track that cost separately or include it consistently. Do not compare an estimate of model tokens in one setup with a fully loaded bill in another.

The distinctions matter:

  • Price per token describes a provider rate, not an application outcome.
  • Cost per attempt divides spend by all attempts, including failures.
  • Cost per accepted result divides spend by outcomes that actually pass the product's rules.
  • Whole-product margin also depends on revenue, fixed costs, support and how much the feature is used. Improving one unit cost does not prove margin improved.

Quality and timing remain gates, not optional footnotes. Define what a pass means, the minimum acceptable pass rate, and either a latency ceiling or completion deadline before evaluating a cheaper configuration.

Match the capability to the workload

A provider capability is an opportunity only if enough of the current workload can use it. The first investigation is often finding the eligible fraction, not changing code.

Capability Fit evidence Costs to count What to verify
Stable-prefix caching Long, identical context repeats within an eligible cache window Cache writes, reads, misses, uncached input and output Actual hits, minimum length, output quality and latency
Asynchronous batches Tasks can wait and the provider supports the batch route Batch usage, retries, expiry and orchestration Deadline, failure recovery and accepted outputs
Different model or effort Some tasks may need less reasoning than the default setting Input, output, tool calls, longer runs and retries Same evaluation set, quality floor and response time
Application runtime settings An I/O-heavy route has relevant billed compute usage Active CPU, provisioned memory and invocations Current deployment mode, p95 latency and full bill

For caching, Anthropic's prompt-caching documentation describes reusable prompt prefixes, separate write/read accounting, a five-minute default lifetime, and an optional one-hour lifetime at a different write cost. A repeated prefix is not a cache hit by definition. Confirm eligibility and inspect cache_creation_input_tokens and cache_read_input_tokens in real usage. A short or frequently changing prefix may never pay for a cache write.

For delayed work, Anthropic's Message Batches API documents a 50% reduction in eligible API processing prices relative to standard requests. It is asynchronous and can take up to 24 hours; expired requests and recovery work matter. That 50% is a provider-level price condition, not a promise that your entire feature will cost half as much.

For model choice, Anthropic's model-and-effort guidance explicitly evaluates cost per completed task. Its September 2026 tuning article discusses cache behavior, effort and prompt design. Those are provider examples, not proof that one model or effort level is optimal for your workload. Change one meaningful variable and rescore the same cases.

For runtime costs, Vercel Fluid Compute is one concrete example. Under its documented Functions pricing, active CPU time pauses while a function waits for external I/O, but provisioned memory remains billable while requests are in flight, and invocations count too. The configuration and overall bill still need checking. Fluid Compute became the default for new Vercel projects in April 2025, so do not treat its mere existence as a newly released cost opportunity.

Work through a product with two different task deadlines

Imagine a small SaaS product that enriches product records each night and also offers an interactive, AI-assisted lookup. Both routes use a long set of instructions and source-format definitions, but they have different timing requirements.

For nightly enrichment, the product can queue work and accept completion by the next daily run. A batch API might fit, provided expired work can be retried or handled and the real completion distribution satisfies the deadline. Stable schema instructions may also create cacheable prefixes. Which lever is better depends on actual repeats, cache expiry and the cost of queue plumbing.

For interactive lookup, assume a product requirement of p95 response time no higher than three seconds. An asynchronous batch path is inappropriate for that response. Cache reuse or a different model setting may be candidates, but only if they maintain answer quality and the latency target. A model that produces a valid JSON object after ten seconds still fails this particular user experience.

The three-second target, nightly workflow and product are hypothetical. These routes are intentionally evaluated separately; averaging them into one cost metric could hide a failure in the interactive feature.

Illustrative cost per accepted result

Now freeze 1,000 attempted nightly enrichment tasks, each run once against the same acceptance rubric. In this invented example, a result passes only when the required structured fields are valid and factually supported by the supplied record. Assume the product requires at least 90% accepted results. Variable spend includes the same cost categories for every setup. This is not a real provider bill or an observed ShipFoundry result.

Setup Variable spend Accepted results Cost per accepted result
Baseline $90 900 of 1,000 $0.10
Candidate A: cache change $63 900 of 1,000 $0.07
Candidate B: model change $45 720 of 1,000 $0.0625

The arithmetic is $90 / 900 = $0.10 for the baseline; $63 / 900 = $0.07 for Candidate A; and $45 / 720 = $0.0625 for Candidate B. Candidate A, imagined here as a caching-only change, lowers the illustrative accepted-result cost by 30% without lowering the acceptance rate. That 30% is calculated from invented spending and is unrelated to Anthropic's documented batch pricing discount.

Candidate B, imagined as a cheaper-model change, looks less expensive at $0.0625 per accepted result. But 720 / 1,000 = 72%, below the required 90% acceptance floor. Reject it under the stated requirements, even before considering latency. Further retries, human correction or fallback execution might alter both the cost and the success rate; they must be measured rather than assumed away.

Also reject a candidate that breaks the deadline, a security constraint or a required provider policy, even if its quality score and dollar arithmetic pass. The economic decision is conditional on the full product acceptance contract.

Prepare your own cost experiment

Use this worksheet to decide what should be frozen before a coding agent changes anything. For a new product, substitute your own task, representative cases and requirements rather than reusing the article's 90% example.

Input Baseline Candidate Evidence needed
Task definition Write one accepted customer outcome Keep the same outcome Output schema and examples
Evaluation population Freeze representative input IDs Run the identical cases Input list and hard-case mix
Acceptance rule Define pass/fail and minimum rate Reuse the same grader and floor Scored outputs and audit notes
Latency or deadline Set p95 target or completion cutoff Keep that limit unchanged Timestamps, timeouts, expired jobs
Counted costs Record model, tool and runtime spend Count the same cost categories Usage receipts and cost rates
Retry policy Fix attempts and recovery rule Use the same policy Attempt logs and fallback costs

Start with a representative set that includes difficult and failure-prone inputs, not only easy examples. Capture actual model IDs, runtime settings, rate dates, request usage, failures, retries and run timestamps. For caching, reproduce the expected production mix of hits, misses and refreshes, including the cost of warming the cache. A conveniently warm test run alone will overstate savings if most production requests miss. OpenAI's published cost-and-quality optimization walkthrough provides another example of freezing quality, latency and cost criteria; its demonstration uses a simulated support workload, not the application described here.

Give your agent one bounded investigation

Copy this template into the agent that already works with your codebase. Replace the fields first. Its job is to inspect eligibility and design one safe experiment, not to rewrite the product or touch production automatically.

COST OPPORTUNITY INVESTIGATION

Product outcome: [the accepted customer task and why it matters]
Cost goal: [reduce cost per accepted task by X, or find out if a change is worthwhile]
Provider, model and settings today: [current real configuration]
Capability source: [official release/docs URL and publication or check date]
Workload evidence: [request volume, tokens, traces, cache hits, retries, spend]
Acceptance rule and minimum rate: [frozen rubric and required pass rate]
Timing constraint: [p95 response time or completion deadline]
Constraints: [allowed providers, architecture, privacy, uptime, budget]
Available access: [code, test data, logs; explicitly granted permissions]

Inspect the actual application and report:
1. What share of this workload is eligible for this capability, with evidence?
2. Is the capability already enabled, partially active or automatically applied?
3. What baseline measurements and representative evaluation set are required?
4. What is the smallest candidate that changes only one important variable?
5. What usage, retry, queue, tool or runtime costs are missing from estimates?
6. What quality, timing, compliance or reliability regressions are plausible?
7. How should baseline and candidate be scored on identical cases?
8. Recommend: run a bounded experiment, adopt after a passing test,
   investigate further, or make no change. Explain why.

Separate measurements from estimates. State whether any savings refer
only to token rates, attempts, accepted tasks or the whole product.
Do not make paid calls, change production settings or deploy without
separate owner authorization.

If the result is a credible candidate, run it in an authorized environment with the same inputs, scoring and constraints. Keep the baseline artifacts, including unsuccessful responses. Have your agent report the conclusion and limitations, not just a new configuration file.

Sometimes the right optimization is no change

An update does not necessarily create engineering work. Four outcomes can justify keeping the product as it is:

  • The benefit is already live. Vercel reported on October 27, 2026 that changes to Vercel Agent sessions reduced its average session cost by 67% and required no customer action. That is a vendor-reported result for Vercel Agent, not a measured reduction in your application's cost or an instruction to migrate it.
  • The setting is already enabled. Vercel's Fluid Compute defaults, an existing cache configuration or an adopted model release may leave nothing to implement.
  • The eligible workload is too small. A tiny stable-prefix fraction or a handful of tasks might not repay engineering time, maintenance or operational complexity.
  • The requirement rules it out. A seconds-long interactive response cannot be moved into a slow batch just to claim a lower API price. A lower-effort model that misses the acceptance floor is not an improvement.

Your existing provider reports and a small evaluation script may be enough for a one-off decision. If the real problem is attributing many providers' charges to customers or workflows, use billing instrumentation or a cost-observability tool. ShipFoundry does not replace those measurements.

Make cost improvements part of product development

The recurring job is finding capabilities that make a particular feature more affordable without weakening its result. A provider may change batch behavior, a model may become viable for an extraction step, or a runtime may bill an I/O-heavy route differently. The same evaluation method tells you whether that change is worth adopting.

ShipFoundry connects source-linked changes in a product's existing tools and platforms to its stated goals, constraints and stack. A cost goal can make a newly useful capability worth investigating. ShipFoundry supplies the lead and an agent handoff; your agent examines the actual code, and you control evaluation, permissions, implementation and release. It is not a bill reader, a cost-anomaly monitor or an automatic optimization engine.

If you only need to measure a one-time price change, keep your current instrumentation and run the worksheet above. If you repeatedly miss relevant changes across the stack you already use, a context-specific opportunity workflow becomes more useful.

Frequently asked questions

Is a cheaper model always cheaper per completed task?

No. A lower rate can be offset by extra tokens, longer agent runs, retries, tool calls or failures. Compare all costs divided by results that pass the same quality and timing requirements. Test a smaller model or lower effort on a fixed evaluation set before switching.

When does prompt caching pay off?

When sufficiently long, stable context is reused often enough during the applicable cache lifetime to outweigh writes and misses. Check the provider's minimum cacheable length, TTL and per-model prices, then inspect real read and write token counts rather than assuming every request hits.

Which tasks can wait for batch execution?

Background work with an explicit completion window and a plan for expired or failed jobs is a candidate. An interactive request with a seconds-long latency target is not. Anthropic says its Message Batches can take up to 24 hours, so an overnight queue with a hard morning deadline needs careful validation or a fallback.

Can a platform improvement already apply automatically?

Yes. Verify the deployed version, plan and configuration before opening an implementation task. For example, Vercel said its October 2026 efficiency changes to Vercel Agent sessions were already live and required no action. That was a vendor claim about its own Agent product, not every application running on Vercel.

Does ShipFoundry inspect bills or implement the optimization?

No. ShipFoundry matches external stack changes to a project's confirmed context and goals, then provides a source-linked lead for the owner's existing agent. The agent must inspect the real app under the owner's permissions. The owner is responsible for cost measurements, evaluation, approval, implementation and deployment.

Find the next improvement that passes your product's test

Start with the outcome and constraints, not a provider price list. Find stack improvements that fit your product's cost goal by preparing your project context with your existing agent. Then investigate only the opportunities that could make a real customer task cheaper without making it worse.

Get the Stack Changes Worth Using.

One concise note on what changed, why it matters, and where it could improve your product.

No spam. Unsubscribe anytime.