samai-sdk
Reference

Prompt caching

Set promptCaching: true on a call to mark the system prompt and tool definitions as a reusable, cacheable prefix — useful in an agent loop where the same system prompt and tools get re-sent on every turn.

prompt-caching.ts
const result = await client.generate({
  model: "claude-sonnet-4-6",
  system: longStaticSystemPrompt,
  messages,
  tools,
  promptCaching: true,
});

console.log(result.usage.cacheReadTokens);  // tokens served from cache — billed at a fraction of input price
console.log(result.usage.cacheWriteTokens); // tokens written to the cache on this call

Provider support varies

Currently honored by anthropic() — it adds Anthropic's cache_control breakpoints to the system prompt and the last tool definition (which caches the entire tool list as one unit). It's a no-op on providers that don't need client-side cache configuration — OpenAI and Groq cache automatically server-side above a token threshold with nothing to set.