langchain-ai/langchain-google

Enabling 1 Million token context window for Claude 4.5

Open

#1,234 opened on Oct 8, 2025

View on GitHub
 (3 comments) (4 reactions) (0 assignees)Python (461 forks)auto 404
anthropic-vertexhelp wantedvertexai

Repository metrics

Stars
 (392 stars)
PR merge metrics
 (PR metrics pending)

Description

As documented here, we can enable enlarged context window by using a beta header. The way I understand to do this from here with init_chat_model is:

init_chat_model(model='claude-sonnet-4-5@20250929', {'model_provider': 'google_anthropic_vertex', 'additional_headers': {'anthropic-beta': 'context-1m-2025-08-07'}})

But I always get this error when I try to submit something > 200k tokens:

Error code: 413 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'Prompt is too long'}, 'request_id': 'req_vrtx_011CTucweqqUPTN2rooW5KYk'}

Should this work through this library? Maybe there's a different way? I'd be happy to document this if I can get some clarification

Contributor guide