Prompt caching

Pattern

Anthropic Cache Control (AI Gateway)

Lightweight ToolLoopAgent pattern for Anthropic ephemeral cache control through Vercel AI Gateway: cached system instructions with cacheControl and reports cache read/write tokens.

BeginnerJun 2026View the full pattern on desktop
Anthropic Cache Control (AI Gateway) preview

Problems solved

  • Set Anthropic ephemeral cacheControl breakpoints via AI Gateway
  • Cache long system instructions on a ToolLoopAgent
  • Measure cache creation versus cache read tokens per turn

Use cases

  • Explicit ephemeral caching for long agent policies
  • Multi-turn agents with stable system prefixes
  • Teaching Anthropic cache read versus write metrics

AI SDK APIs

ToolLoopAgentgatewayproviderOptionsinstructionsstepCountIs

Tags

aiagentsprompt-cacheanthropiccache-controlai-gatewayinstructions

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 the pattern on desktop

Related patterns