Skip to content
Blog
November 15, 2026Architecture15 min read

Why a session locks one model family: tokenizer, prompt cache, tool dialect and refusals

Four properties that differ between provider families, what breaks when one changes mid-session, and why Pleach pins the family and transport at session start. Price, error handling and calibration are covered too, including what the lock does not hold fixed.

byPleach maintainers

Drafted by an AI agent, from the Pleach docs, vendor documentation and the sources it cites; reviewed by a maintainer before publishing.

No @pleach/* package is on npm yet. Each name holds a 0.0.1 placeholder until its first release, so the code here describes the source, not an install that works today. Package status

A session locks one provider family because four properties of a model call differ between families, and each one breaks something when it changes mid-conversation: the tokenizer, the prompt cache, the tool-call schema and the way refusals arrive. A per-call router can always find a model that is up. It can't carry the session's history, cache and budget across to a family that reads all three differently.

This post walks through each property, what goes wrong when it moves, and what Pleach's family lock does about it. It also covers the three things people expect a lock to hold that it doesn't fully hold: the price, the error vocabulary and the calibration of the model's numbers. For how a recorded fallback looks during an audit review, see reconstructing an agent decision for audit trail review.

What the lock pins, and what each property protects

PropertyWhat it decidesWhat breaks if it changes mid-sessionWhat the lock does not cover
TokenizerHow many tokens a prompt costs and whether it fitsContext-window budgets and cost estimates computed on the old countTokenizer changes inside one family
Prompt-cache keyWhether the next call reads a cached prefixThe cache is gone; the next call pays full input, and on some providers a write premiumCache expiry and prefix edits within the session
Tool-call dialectThe schema a tool definition and a tool call useTool history and definitions in the wrong shape for the new modelSchema differences between two APIs of one vendor
Refusal patternHow a declined request arrivesA retry loop that treats a refusal as success, or retries it foreverCalibration, judgment and wording differences between models

The family-locked routing page lists those four as the properties frozen at session start, alongside one Transport. The rest of this post takes them in turn.

Why lock at session start rather than per call?

A single stateless call can go anywhere. A gateway that retries a failed summary on another vendor's model loses nothing, because nothing came before it.

An agent session is not stateless. By the third turn it holds a message history with tool calls and tool results in it, a system prompt and tool catalog that a provider may have cached, and token counts the runtime used to decide what to keep in context. All of that was produced in one family's format and measured by one family's rules.

Routing per call treats each request as independent, so it can't see that state. Locking per session treats the session as the unit that owns it. In Pleach the lock holds for the session's lifetime. A real provider change goes through sessions.updateProviderModel, which re-locks the session and saves the new provider and model as a new session version. The worked example below shows what that change does to a live chat.

Worked example: switching from Claude to GPT mid-chat

Say a user is twelve turns into a chat on an Anthropic model. The agent has called a search tool four times, and the system prompt and tool catalog sit in Anthropic's prompt cache. Then the user picks an OpenAI model from a menu, or the host decides to move them. Here's what each locked property does at that moment.

Tokenizer. The whole history is now counted by a different tokenizer. Context fit and the remaining budget were computed on the old count, so anything kept or dropped was decided on the wrong number. Anthropic's advice, even for a move between two of its own models, is to recount prompts against the model you plan to use [1].

Prompt cache. The cached prefix stays behind. A cache is held by the provider that wrote it, and both vendors isolate caches by organization [2][3]. The thirteenth turn pays the full input rate on the whole history, and caching it on the new provider means writing that prefix again.

Tool dialect. The four earlier tool calls are Anthropic tool_use blocks, with results to match. The new request has to carry them, and the tool catalog, as OpenAI function tools [5][6]. That translation has to be right for every tool in the history.

Refusals and errors. The retry loop now branches on different signals. Overload arrives as a 503 rather than a 529, and a refusal arrives as a refusal field rather than stop_reason: "refusal" [6][8][9][10]. A loop tuned for the first family misreads the second.

None of that is a reason to forbid the switch. It's a reason to make it a visible step.

In Pleach the switch is a call to sessions.updateProviderModel. It re-locks the session and saves the new provider and model as a new session version, and the session's stored record carries its locked provider and model (session lifecycle). Nothing widens silently mid-turn. Every call after the re-lock writes a row with the provider and transport that ran, so the turn where the family changed is visible in the ledger. From then on, the lock and the in-family cascade apply to the new family.

The docs don't describe the runtime re-expressing earlier tool calls in the new dialect, or recounting the history for you. Treat both as the host's job to check before relying on them.

Compare a cross-family fallback that switches on its own. The same four things change, but on a failed call rather than a choice, in the middle of a turn, with no new session version. Whatever record exists sits with the gateway, not with the session. That's the case the lock rules out.

The tokenizer decides what a prompt costs

Every provider bills and limits in tokens, and tokenizers differ. The same text is a different number of tokens on different models, so a budget counted on one model is wrong on another.

The gap is not only between vendors. Anthropic's token-counting docs state that Claude 4.7 and later models use a newer tokenizer, and that the same input produces approximately 30 percent more tokens than on earlier models. The same page tells you to recount prompts against the model you plan to use rather than reuse counts measured on an earlier one [1].

That matters in two places. Context management decides what to drop based on a count, so a count from the wrong tokenizer can overflow the window or drop history it didn't need to. Cost estimates multiply tokens by a rate, so the estimate moves with the tokenizer even when the rate doesn't.

Pleach's lock freezes the family's token-count semantics for the session. Be clear about its grain: a family pins a tokenizer family, not one exact count. Anthropic's own documentation shows one vendor shipping two tokenizers. So Pleach doesn't rely on an estimate surviving a fallback. Each provider dispatch writes a per-call row with the input and output token counts the provider reported, retries included. A fallback that lands on a model with a different tokenizer shows up as a count change on the row, not as a silent budget error. See model resolution matrix → per-call rows.

The prompt-cache key decides whether you pay cache rates

Prompt caching is where a mid-session switch costs the most money, and it costs it quietly.

On the Claude API, a cache covers the full prefix of tools, system and messages, in that order. Cache reads are priced at 0.1 times the base input price, with some newer models priced lower. Writes cost 1.25 times base for a 5-minute lifetime and 2 times base for a 1-hour one. Changing a tool definition invalidates the entire cache [2]. On OpenAI, caching is on by default for supported models, reuse requires the entire rendered prefix to match, and cached tokens are reported in usage.input_tokens_details.cached_tokens. OpenAI's list of settings that affect the cached prefix includes the model itself: a different model can use different weights and caching behaviour [3].

A cache lives with one provider and one organization. Move a long session from one family to another and its first call on the new provider reads nothing from cache. It pays the full input rate on the whole history. On Anthropic, rebuilding the cache adds the write premium on top.

Pleach keeps one prompt-cache identity per session, and the fingerprint that keys the runtime's own cache and replay includes the family. The family-lock page states that family and transport are both in that key, so calls with the same prompt and tools but a different family or transport never share an entry [4]. On the provider side, each per-call row carries cachedInputTokens and, from v42, cacheWriteTokens, so cache behaviour per call is a column you can read. A call that read from cache prices those tokens at the cache-read rate when the model has one; cached tokens with no cache-read rate leave the row unpriced rather than priced wrong. See auditable call row → cache writes.

Price: what the lock bounds and what it doesn't

The lock doesn't freeze the price, and the difference matters.

What the lock does hold is the basis the price is computed on. @pleach/core/pricing keys rates on (family × callClass), and computeTurnCost returns null rather than guessing when a cell is missing (pricing math). With the family locked, a session's calls price against one family's rates, counted by one tokenizer, with one provider's cache rules deciding which tokens get the cache-read rate.

The transport lock keeps billing on one credential. A session on anthropic with byok-native that exhausts the user's own key records a providerCascade row with outcome.status: "exhausted". It does not flip to the deployment's credentials and bill the operator instead (model resolution matrix → transports). Families without a native provider collapse a native request to its OpenRouter equivalent at resolve time, and the transport that ran is recorded on the row, so the collapse is visible.

What the lock doesn't hold is the model. When a call fails, the cascade moves to the next rung in the same family, and the docs' own example is claude-opus to claude-sonnet. Those are different prices. The lock bounds the move to a short ladder of known models; it doesn't stop the rate changing.

Pleach records the change instead of preventing it. A fallbackStep row carries originalModel and attemptModel, and each per-call row carries the requested and served model. When an upstream serves a different model than the one requested and only the requested model's rates are known, the row omits the cost with costOmitted: "served-model-mismatch" rather than pricing it at the wrong rate (auditable call row).

The tool-call dialect decides whether the turn parses

Tool calling is where a cross-family switch fails loudest.

Anthropic defines a tool with name, description and input_schema, a JSON Schema object for the parameters, and returns calls as tool_use content blocks [5]. OpenAI's Chat Completions API wraps the same information differently: a tool is { type: "function", function: { name, description, parameters, strict } } [6]. OpenAI's Responses API uses a third, flatter shape, with type, name, description, parameters and strict at the top level [7].

Those differences reach past the request. A session's history holds the model's earlier tool calls and your tool results, written in the dialect of the model that made them. Switch families mid-tool-loop and the runtime has to translate the whole history, plus the tool catalog, into the new shape. That translation has to be right on the turn where something has already failed.

This is the reason the Pleach cascade is strict. The family-lock page says it plainly: a tool-call dialect that worked on Anthropic would fail mid-session if the cascade widened to OpenAI. Keeping one conversation on one dialect removes that failure mode, and it makes any change of family a step the host takes on purpose.

The lock doesn't remove every schema difference. Two APIs from one vendor can differ, as OpenAI's do, and that's a provider wiring choice rather than a family one. See providers for the transport layer.

Errors and refusals decide what the retry loop does

A retry loop branches on what comes back. Families signal the same events differently, so a loop written against one family's signals misreads another's.

Take overload and rate limits. The Claude API returns 429 with rate_limit_error when an organization hits a rate limit or a spend cap, and 529 with overloaded_error when the API is temporarily overloaded. Errors arrive as JSON with a top-level error object carrying a type and a message [8]. OpenAI also uses 429, but under it sit distinct causes: requests sent too quickly, a request rate that rose too fast, an exhausted credit balance, and organization or project spend limits [9]. Some of those clear with backoff and some won't clear at all. OpenAI's overload is a 503, "Model temporarily overloaded" [9].

Refusals differ more. On Claude, a classifier refusal is a normal HTTP 200 response with stop_reason: "refusal", not an error [10]. On OpenAI's Chat Completions API, a refusal is a refusal string on the response message [6]. A loop that only checks HTTP status treats both as success. A loop that matches one family's refusal shape misses the other's.

Pleach's lock freezes the refusal pattern for the session, so the shape a refusal arrives in doesn't change under the loop. The runtime also maps provider failures onto one set of codes the host branches on, documented in error codes:

CodeMeaningWhat the runtime does
5001, 5002Provider not configured, auth failedTerminal; no rung succeeds
5003Rate limitedCascade to the next in-family rung
5006, 5007Stream error, timeoutRetry before giving up to 5008
5008Cascade exhaustedEvery in-family rung failed; the host picks a different family

The error enum has no dedicated safety-refusal code. A provider-side refusal surfaces through the ordinary provider-error path, as a 5006 stream error or a non-clean finishReason (error codes). The lock keeps the refusal shape stable; it doesn't give refusals their own branch.

The in-family direction also lines up with the vendor's own guidance for refusals. Anthropic's refusals page says you can usually still get an answer by sending the same request to another Claude model [11]. That's a move inside one family.

What happens when the family runs out

The cascade is one function, pickNextInFamily(family, currentModel, triedModels). It returns the next rung in the same family, or null when every rung has been tried (providers → family-strict cascade).

Each in-family attempt writes a fallbackStep row with inFamily: true. When the ladder is exhausted, the runtime records a family-exhausted delivery outcome. The turn is served as a notice rather than counted as an error, and the event log carries 5008. The host then chooses: ask the user to pick another family, wait for capacity, or re-lock with sessions.updateProviderModel. No row crosses into another family's cell on its own.

Models outside the matrix get the same principle with a smaller ladder. A gateway alias, a BYOK slug or an unrecognized id derives no family, so there is no column to walk. The runtime keeps the served model and re-streams it at most sameModelRetryCap times per turn, default 3. The old cross-family fallback for those models is an opt-in, legacyNonMatrixFallback, deprecated and removed in 1.0.0 (models no family derives from).

The runtime's packages aren't installable yet — each @pleach/* name holds a placeholder until its first release, so the mechanisms here describe the source rather than a release you can add today. See packages for status.

What the lock does not freeze: calibration

A confidence score, a classifier threshold and a relevance cutoff are each tuned against one model. The lock doesn't make those numbers comparable across a fallback, and the docs say so.

Calibration belongs to a model, not to a prompt or a family. Guo and colleagues showed that modern neural networks are often poorly calibrated, and that a fix such as temperature scaling is fitted on held-out data for one network [12]. The GPT-4 technical report measured an expected calibration error of 0.007 for the pre-trained model on an MMLU subset and 0.074 after post-training [13]. That's one lineage at two stages, with a roughly tenfold difference in how well stated confidence tracked accuracy.

So an in-family fallback still moves the basis of any threshold. Opus to Sonnet is a different calibration, and the cascade does exactly that on a provider failure.

What the lock adds is that the move is bounded and written down. The set of models a threshold can meet is the family's ladder, and every move lands as a fallbackStep row plus per-call rows with the requested and served model side by side. The turn where a threshold's basis changed is a query over your own rows. The family-lock page recommends alerting on requested-versus-served disagreement rather than on the error rate, because a fallback that succeeds produces no error.

The per-model threshold table and the recalibration stay yours to keep.

Checking that the lock held

A lock is only useful if a leak is visible. Pleach gives you three places to look.

Each AuditableCall.call carries the provider and transport that ran, after resolution. A familyLock row lands at the resolution boundary with the requested family and whether it mismatched. And under the matrix, a providerCascade row whose source isn't the documented carve-out shouldn't exist:

-- Should return zero rows for a healthy matrix-resolved fleet.
WHERE payload.kind = 'providerCascade'
  AND payload.source != 'imperative-carve-out'

Per-call rows are where a leak shows first. A call.provider that differs from the session's locked family means another family served the call. The runtime attributes that field from the served model's own family prefix first, so a cross-family serve is reported rather than hidden behind the lock. Exclude rows marked "unresolved", which mean the family couldn't be attributed.

There's one documented exception. A host may run plan generation on its own configured planner model, outside the lock, and that call writes an identifiable row with stage: "anchor-plan" and callClass: "utility". Alert on everything except that row. See family-locked routing → on the audit row for the field shapes.

When a family lock is the wrong choice

The lock trades availability for consistency. When the whole family is down, a locked session stops and asks, where a cross-family gateway would have answered. That trade suits a multi-turn session with tools, a cached prefix and a budget. For a stateless, single-shot call with no tools and no number that gates a decision, a cross-family fallback costs little.

Key takeaways

  • A session holds family-specific state. Its history, cache and token budget were all produced under one family's rules, and a per-call router can't move them.
  • A mid-chat switch is a re-lock, not a fallback. sessions.updateProviderModel saves a new session version, and the rows after it name the new provider.
  • The tokenizer sets the count. Counts differ across families and sometimes inside one; Anthropic documents about 30 percent more tokens on its newer tokenizer.
  • A switch discards the cache. The first call on a new provider pays full input on the whole prefix, and changing tool definitions invalidates an Anthropic cache entirely.
  • Tool schemas don't transfer. input_schema and function.parameters are different shapes, and the history is written in one of them.
  • The lock bounds price; it doesn't freeze it. An in-family rung is a different model at a different rate, recorded per call.
  • Calibration still moves. The lock makes the change bounded and queryable, not harmless.

References

  1. Token counting — Anthropic, platform documentation. Claude 4.7 and later models use a newer tokenizer producing approximately 30 percent more tokens; recount against the model you plan to use. Accessed 2026-11-15.
  2. Prompt caching — Anthropic, platform documentation. Prefix order tools, system, messages; cache-read and cache-write multipliers; tool-definition changes invalidate the entire cache. Accessed 2026-11-15.
  3. Prompt caching — OpenAI, API documentation. On by default for supported models; the entire rendered prefix must match; cached_tokens usage field; the model as a setting that affects the cached prefix. Accessed 2026-11-15.
  4. Family-locked routing → in the fingerprint — Pleach docs. Family and transport in the fingerprint cache key.
  5. Define tools — Anthropic, platform documentation. Tool definitions with name, description and input_schema; tool_use content blocks. Accessed 2026-11-15.
  6. Create chat completion — OpenAI, API reference. Function tools as type: "function" with a nested function object; the refusal field on the response message. Accessed 2026-11-15.
  7. Function calling — OpenAI, API documentation. The Responses API function tool shape with top-level name, description, parameters and strict. Accessed 2026-11-15.
  8. Claude API errors — Anthropic, platform documentation. 429 rate_limit_error, 529 overloaded_error, and the error JSON shape. Accessed 2026-11-15.
  9. Error codes — OpenAI, API documentation. The causes behind 429, and 503 "Model temporarily overloaded". Accessed 2026-11-15.
  10. Handling stop reasons — Anthropic, platform documentation. The refusal stop reason, returned as a normal HTTP 200 response. Accessed 2026-11-15.
  11. Refusals and fallback — Anthropic, platform documentation. A refused request can usually be answered by sending it to another Claude model. Accessed 2026-11-15.
  12. On Calibration of Modern Neural Networks — Guo, Pleiss, Sun and Weinberger, ICML 2017. Modern networks are poorly calibrated; temperature scaling as a single-parameter fix. Accessed 2026-11-15.
  13. GPT-4 Technical Report — OpenAI, 2023. Calibration of the pre-trained and post-trained model on an MMLU subset, ECE 0.007 and 0.074. Accessed 2026-11-15.

Frequently asked

Why lock the model family per session instead of choosing per call?

Because a session carries state that belongs to one family. Its history holds tool calls in one provider's schema, its prompt prefix sits in one provider's cache, and its token budget was counted with one tokenizer. A per-call choice can pick a model that is up, but it can't move that state. Pleach locks one provider family and one transport at session start and changes them only through an explicit re-lock.

Does locking the family freeze the price of a session?

No. Rates in Pleach's pricing math are keyed by family and call class, so the lock keeps a session on one family's rates and one credential. A fallback inside the family still changes the model, and a different model is usually a different price. Each fallback and each provider call writes its own row, so the cost of the change is recorded, not prevented.

Does the same family always mean the same tokenizer?

Not exactly. Anthropic documents that Claude 4.7 and later models use a newer tokenizer that produces roughly 30 percent more tokens for the same text than earlier models. A family pins the tokenizer family, not one exact count. Pleach records the token counts the provider reported on every call, so a count change after a fallback shows up on the row.

Can a user switch from one provider's model to another partway through a chat?

Yes, as an explicit step. In Pleach the host calls sessions.updateProviderModel, which re-locks the session and saves the new provider and model as a new session version, and the rows after it record the provider that ran. The switch still costs something: the history is counted by a new tokenizer, the prompt cache stays with the old provider, and earlier tool calls are in the old schema. When every model in the locked family fails, the runtime does not switch on its own; it records a family-exhausted outcome (error code 5008) and the host decides.

Does a family lock keep confidence scores and thresholds valid?

No. Two models in one family are two calibrations, and an in-family fallback still changes the model. What the lock adds is that the change stays inside a short, known list of models and lands as a row naming the requested and served model, so the decisions made on the new basis can be found with a query.

model fallbackprovider routingtokenizerprompt cachingtool callingllm error handling

More posts