Skip to content

Conversation

@stevenvo
Copy link

@stevenvo stevenvo commented Jan 2, 2026

Summary

This PR adds support for enabling 1M token context windows for Claude Sonnet 4.5 through environment variables for both Anthropic direct and Vertex AI Anthropic providers.

Note: Currently only Claude Sonnet 4.5 supports 1M token context windows. All other Claude models (Opus 4, Haiku 4.5, etc.) remain at 200K tokens according to models.dev.

Changes

  • Anthropic Direct: Add ANTHROPIC_1M_CONTEXT=true env var to enable 1M context for Sonnet 4.5

    • Preserves existing beta headers (claude-code, interleaved-thinking, fine-grained-tool-streaming)
    • Prepends context-1m-2025-08-07 beta when enabled
  • Vertex AI Anthropic: Add VERTEX_ANTHROPIC_1M_CONTEXT=true env var to enable 1M context for Sonnet 4.5

    • Sets anthropic-beta: context-1m-2025-08-07 header when enabled
  • Model Detection: Regex pattern specifically matches Claude Sonnet 4.5 variants only

    • Matches patterns: claude-sonnet-4.5, claude-sonnet-4-5, claude-sonnet-4.5-20250929
    • Automatically sets context limit to 1,000,000 tokens when env var is enabled

Testing

  • ✅ All existing provider tests pass (66 tests)
  • ✅ TypeScript compilation successful
  • ✅ No type errors

Usage

```bash

For Anthropic direct (Sonnet 4.5 only)

export ANTHROPIC_1M_CONTEXT=true

For Vertex AI Anthropic (Sonnet 4.5 only)

export VERTEX_ANTHROPIC_1M_CONTEXT=true
```

- Add ANTHROPIC_1M_CONTEXT env var for Anthropic direct API
- Add VERTEX_ANTHROPIC_1M_CONTEXT env var for Vertex AI Anthropic
- Only applies to Claude Sonnet 4.5 models (not Opus 4 or Haiku)
- Sets context limit to 1,000,000 tokens when enabled
- Adds context-1m-2025-08-07 beta header when enabled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant