ai-api.md — opusjake_os ARTICLE
// OPUSJAKE BLOG · AI API

AI API in 2026: How to Pick One and Wire It Up Properly

2026-08-227 MIN READBY JAKE SCHINCARIOL · AI ARCHITECT
WIRE IT RIGHT
ai apillm apirate limitsprompt cachingapi costs

An AI API is four decisions, not one purchase: which model tier handles which job, what you cache, whether the work is synchronous or batched, and what your code does when a call fails. Get those right and the vendor barely matters. Get them wrong and you will pay three times too much for a service that goes down every time traffic spikes. Here are the current numbers, the arithmetic, and the wrapper that holds it together.

TL;DR

  • Verified 22 August 2026 on Anthropic's pricing docs: Haiku 4.5 at $1/$5, Sonnet 5 at $2/$10, Opus 5 at $5/$25, Fable 5 at $10/$50 per million input/output tokens. OpenAI's published pricing puts gpt-5.6-luna at $0.20/$1.20 and gpt-5.6-sol at $4/$20. Gemini 3.7 Flash is $0.75/$3.75 through 31 December 2026.
  • Prompt caching bills a cache read at 0.1x the base input rate. A 5 minute cache write costs 1.25x, a 1 hour write costs 2x. The Batch API takes 50 percent off both directions, and the two discounts stack.
  • On most Claude models, cache reads do not count toward your input tokens per minute limit. Caching 80 percent of a 4,000 token prompt moves a 2M ITPM ceiling from 500 requests a minute to 2,500.
  • Not every 429 is a rate limit. The spend cap 429 carries no retry-after and error_code: enforced_spend_limit_reached. Retrying it fails until 00:00 UTC on the first of the next month.
  • Menlo Ventures, publishing 9 December 2025, put enterprise generative AI spend at $37 billion with $12.5 billion flowing to foundation model APIs, and estimated Anthropic at 40 percent of enterprise LLM spend against OpenAI's 27 and Google's 21.

Pick the model after you price the job

Start with a real workload instead of a leaderboard. Say a support triage endpoint: 100,000 calls a month, roughly 4,000 input tokens and 600 output tokens each. That is 400 million input tokens and 60 million output tokens.

Run it on Sonnet 5 at $2/$10 and you pay $800 plus $600, so $1,400 a month. Haiku 4.5 at $1/$5 gives $400 plus $300, so $700. Opus 5 at $5/$25 gives $2,000 plus $1,500, so $3,500. Same endpoint, a five times spread, and the only question that matters is whether the cheap tier passes your evals on this specific job. Run the test harness before you decide, not after the invoice.

The pattern that survives contact with production is a router, not a winner. Easy tickets go to Haiku, ambiguous ones escalate to Sonnet, and the handful that need real reasoning go to Opus. I walk through how to draw that line in how to choose an AI model.

Caching is the biggest single lever on the bill

Most of that 4,000 token prompt is not new. The system instructions, the classification rubric, the tool definitions, and the few-shot examples repeat on every call. Say 3,200 of the 4,000 tokens are fixed.

Pin that prefix with a cache breakpoint and the math changes. With a 90 percent warm cache hit rate on Sonnet 5: 288 million cached tokens read at $0.20 per million comes to $57.60, the 32 million written at the 5 minute rate of $2.50 per million comes to $80, and the 80 million genuinely new tokens at $2 come to $160. Output is untouched at $600. Total: $897.60, down from $1,400. That is 36 percent off for a change that touches one field in the request body.

Now send the same workload through the Batch API, since nobody is watching a triage queue in real time. The 50 percent discount stacks on top, so the month lands near $448.80. From $1,400 to under $450 without changing a single word of the prompt. More on the ordering of those levers in how to cut your AI API bill.

The seven layers of a production AI API wrapperA numbered stack showing the seven components that sit between an application and an AI API: router, budget, cache, timeout, retry, fallback, and ledger, with the cache layer highlighted as the largest cost lever.// FIG 1 · WRAPPERSeven layers between your app and the AI API01ROUTERone model per job class02BUDGETcap max_tokens per route03CACHE0.1x on every cache read04TIMEOUTfail fast, never hang05RETRYhonor retry-after first06FALLBACKsame schema, other model07LEDGERrequest-id, tokens, costSkip any one of these and the integration works in the demo, then fails the month it gets busy.

Rate limits are a throughput budget, not an error

Every AI API meters three things at once: requests per minute, input tokens per minute, and output tokens per minute. Whichever runs out first is your real ceiling, and it is almost never the one on the marketing page.

Take the Start tier for Claude Sonnet 5, which Anthropic's rate limit docs list at 1,000 RPM, 2,000,000 ITPM, and 400,000 OTPM. Our triage call uses 4,000 input and 600 output tokens. On input, 2,000,000 divided by 4,000 caps you at 500 requests a minute. On output, 400,000 divided by 600 caps you at 666. So the advertised 1,000 RPM is decoration. Input is the binding constraint at 500.

Now add caching. The docs are explicit that on most Claude models, cache_read_input_tokens do not count toward ITPM. Cache 3,200 of the 4,000 tokens and only 800 count. That is 2,000,000 divided by 800, or 2,500 requests a minute, a five times throughput gain from the same change that cut the bill by a third.

Two more things worth knowing. Limits use a token bucket that refills continuously rather than resetting on the minute, so a burst can trip a limit you are technically under. And max_tokens does not factor into OTPM at all, since output is metered as it is actually generated. Setting a generous ceiling costs you nothing in throughput. If you are already fighting 429s, how to handle LLM rate limits covers the client side in more depth.

Failure policy: what to retry, what to stop, what to reroute

Blind retries are the most common bug in AI API integrations, and they are expensive because a retried 400 burns the same input tokens as a successful call. Anthropic's error reference sorts the codes cleanly, and the sorting is what your code needs.

Retry policy by HTTP status codeSix rows pairing an AI API HTTP status code with the correct client action, marked green where a retry is appropriate and red where retrying will always fail.// FIG 2 · FAILURE POLICYWhat to retry, what to stop, what to reroute429 + retry-afterwait the header, then retry429, no retry-afterspend cap. stop and alert500 · 529backoff with jitter, cap at 5504 timeoutswitch to streaming or batch413 too largetrim the input. never retry400 invalidfix the request. never retryHalf of production API failures are retries of calls that were never going to succeed.

The row that catches people is the second one. A 429 usually means slow down, and the official SDKs already retry it twice with exponential backoff while honoring retry-after. But the spend cap 429 arrives with the same rate_limit_error type, no retry-after, and a message saying when access resumes. Branch on error.details.error_code so your pager fires instead of your retry loop.

Two habits pay for themselves here. Log the request-id header on every call, successful or not, because it is the only thing support can act on. And set a hard client timeout, since the Messages API returns 504 on long requests and the docs recommend streaming or the Batch API for anything running past ten minutes. If you want the fuller picture on instrumenting this, see AI agent observability.

The wrapper is the product, not the prompt

Everything above collapses into one module that sits between your application and the vendor. Figure 1 is the whole contract: route, budget, cache, timeout, retry, fall back, and log. Write it once and every new feature inherits it.

Two design notes that save rework. First, make the output contract a schema, not a hope, so your fallback model is a drop-in rather than a rewrite. Structured output is what makes multi-vendor routing survivable. Second, keep the wrapper vendor-agnostic at the boundary and vendor-specific inside. Caching semantics, thinking parameters, and tool formats differ between providers and will keep differing. Your application should not know that.

Where this actually lands

Adoption is still early enough that a working integration is a real advantage. The US Census Bureau's Business Trends and Outlook Survey, reported 26 May 2026, put overall AI use among US businesses at 17 to 20 percent between December 2025 and May 2026, with 37 percent of firms above 250 employees using it and under 20 percent of firms with four or fewer employees doing the same. Meanwhile Menlo Ventures measured $12.5 billion flowing into foundation model APIs during 2025.

Read those two numbers together and the picture is clear. Money is pouring into the API layer, and most businesses have not wired one up yet. The gap is not access. Anyone can get a key in four minutes. The gap is the boring layer that turns a key into something that runs on Monday morning when the queue is full.

The bottom line

Pick the cheapest tier that passes your evals, cache the fixed prefix, batch anything nobody is waiting on, and branch your error handling on the actual status code. Those four moves took our example workload from $1,400 a month to under $450 and raised the throughput ceiling five times over. None of them required a better prompt. The prompt is the part you will rewrite twenty times. The wrapper is the part that decides whether any of that rewriting reaches a user.

Build the wrapper this week, then put it on a loop. Grab WRITE LOOPS NOT PROMPTS for the pattern that turns a working API call into a repeatable system, and join the newsletter for the next teardown.

// FREQUENTLY ASKED
How much does an AI API cost in 2026?

Prices are published per million tokens and split between input and output. Checked on 22 August 2026, Anthropic's pricing docs list Claude Haiku 4.5 at $1 input and $5 output per million tokens, Claude Sonnet 5 at $2 and $10, Claude Opus 5 at $5 and $25, and Claude Fable 5 at $10 and $50. OpenAI's published API pricing lists gpt-5.6-luna at $0.20 and $1.20, gpt-5.6-terra at $2 and $12, and gpt-5.6-sol at $4 and $20. Google prices Gemini 3.7 Flash at $0.75 and $3.75 through 31 December 2026. The sticker price is the least interesting part of the bill. Caching and batching move it far more than switching vendors does.

What is the difference between an AI API and a chatbot subscription?

A subscription buys a seat for a person. An API buys capacity for a program. The seat includes the app, memory, file handling, and connectors, and it is priced flat. The API charges per token, has no interface, and expects you to handle authentication, retries, rate limits, logging, and cost tracking yourself. The switching point is repetition. If the same task runs more than about twenty times a week and a human is not reading every output, move that one task to the API and leave everything else on the seat. Running your whole company through an API because it looks cheaper per unit is how teams end up rebuilding a chat app badly.

How do I handle AI API rate limits?

Read the headers instead of guessing. The Claude API returns anthropic-ratelimit-input-tokens-remaining, anthropic-ratelimit-output-tokens-remaining, and matching reset timestamps in RFC 3339 format on every response, so your client can slow down before it gets a 429 rather than after. When a 429 does arrive it normally carries a retry-after header telling you exactly how many seconds to wait. There is one important exception: a 429 caused by hitting your tier's monthly spend cap has no retry-after and carries error_code enforced_spend_limit_reached. Retrying that one fails until the calendar month rolls over, so it needs an alert, not a backoff loop.

Should I use the batch API or the regular one?

Use batch for anything a human is not waiting on. Anthropic's Batch API applies a 50 percent discount to both input and output tokens, and OpenAI's batch pricing is likewise about half the standard rate. That discount stacks with prompt caching, so a workload that is both cacheable and asynchronous can land near a third of its naive cost. The tradeoff is latency and shape: batch is asynchronous, you poll for results, and it suits classification, enrichment, summarization backfills, and evaluation runs. Anything a user is staring at stays on the synchronous endpoint. Most teams that complain about their API bill are running a nightly job through a real-time endpoint.

What belongs in a production AI API wrapper?

Seven things, and none of them are prompts. A router that maps job class to model so cheap work never touches the expensive tier. A token budget that caps max_tokens per route. A caching layer that pins the fixed prefix so repeated context bills at 0.1x. A hard timeout so a slow call fails instead of hanging. A retry policy that honors retry-after and adds jitter. A fallback path to a second model with the same output schema. And a ledger that logs the request id, token counts, and cost per call. The prompt lives above all of that and changes weekly. The wrapper changes twice a year.

// BUILD WITH OPUSJAKE

OpusJake is Jake Schincariol's operating system for building with AI: agents, workflows, prompts, and the free resources behind them. Get the next move every week.

STATUS · ONLINE · OPUSJAKE © OPUSJAKE // CRT V1