Context editing is currently supported for Anthropic models only. The configuration is ignored when routing to other providers.
Why Context Editing
Prevent Context Overflow
Automatically clear old tool results before hitting context limits
Reduce Token Costs
Keep only relevant context, reducing input tokens on subsequent calls
Enable Long Sessions
Run AI agents for longer periods without manual context management
Quick Start
Enable context editing with a simple configuration. The AI Gateway handles the translation to Anthropic’s native format.Configuration Options
Thecontext_editing object supports two strategies for managing context:
Clear Tool Uses
Automatically clear old tool use results when context grows too large:Clear Thinking
Manage thinking/reasoning blocks in multi-turn conversations:Complete Example
Here’s a full configuration for a long-running coding agent:Responses API Support
Context editing works with both the Chat Completions API and the Responses API:Default Behavior
Whencontext_editing.enabled is true but no specific strategies are provided, the AI Gateway uses sensible defaults:
Related Features
- Reasoning - Extended thinking that benefits from context editing
- Prompt Caching - Cache static context for cost savings
- Sessions - Track and analyze long-running agent sessions
Learn More
Anthropic Context Editing Documentation