Skip to content

applyPromptCache

function applyPromptCache(
model,
sessionId,
messages): object;

Single wiring point for provider prompt caching, called by the driver streamText sites. Gated by the conservative detectors so non-matching providers are untouched:

  • Anthropic → applies cache_control breakpoints (caches the system+tools prefix + recent history; ~75% input-cost + TTFT off multi-turn turns).
  • OpenAI Responses → sets promptCacheKey (= sessionId, pins same-session turns to one cache slot) + truncation: 'auto' overflow safety net. Returns the (possibly transformed) messages + an optional providerOptions bag ready to spread into streamText. Default-on: both are no-ops on providers that ignore the fields.
Parameter Type

model

unknown

sessionId

string

messages

ModelMessage[]

object

messages: ModelMessage[];
optional providerOptions?: Record<string, Record<string, JSONValue>>;