Prompt caching
Pattern
BEG·Jun 26

Anthropic Cache Control (AI Gateway)

Lightweight ToolLoopAgent pattern for Anthropic ephemeral cache control through Vercel AI Gateway: prepareCall injects a cached system breakpoint and reports cache read/write tokens.

View Full Pattern on Desktop
Anthropic Cache Control (AI Gateway) preview

Problems Solved

  • Anthropic cacheControl breakpoints via AI Gateway
  • Inject cached system prefix with prepareCall on ToolLoopAgent
  • Measure cache creation vs cache read tokens per turn

Use Cases

  • Explicit ephemeral caching for long agent system prompts
  • Multi-turn agents with stable policy prefixes
  • Teach cache read vs cache write metrics

AI SDK APIs

ToolLoopAgentgatewayproviderOptionsprepareCallstepCountIs

Tags

aiagentsprompt-cacheanthropiccache-controlai-gatewayprepareCall

Requirements

Node.js
24+
Memory
256MB
Other
  • Vercel AI Gateway API key

Environment Variables

External Services

anthropic

Ready to use?

View the full interactive pattern with live preview and copy the source code.

View Pattern on Desktop
End of Pattern