Skip to main content
Context editing enables automatic management of conversation context by intelligently clearing old tool uses and thinking blocks. This can greatly reduce costs in long-running sessions with minimal tradeoffs in context performance.
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

The context_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

When context_editing.enabled is true but no specific strategies are provided, the AI Gateway uses sensible defaults:

  • 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