LLM-Driven Extraction of Unstructured Data — Built for API Deployments & ETL Pipeline Workflows
Python ai-agentsdata-engineeringdocument-aigenerative-aiidpjson-extractionllmmcp-serverocrpdf-extractionprompt-engineeringstructured-output
UN-3130 [FEAT] - Add Support for 1M context for Anthropic LLM adapters (#1732)
Praveen Kumarf1cd75c1c96b
diff --git a/unstract/sdk1/src/unstract/sdk1/adapters/base1.py b/unstract/sdk1/src/unstract/sdk1/adapters/base1.pyindex 983d80ff8..85cdd4e84 100644--- a/unstract/sdk1/src/unstract/sdk1/adapters/base1.py+++ b/unstract/sdk1/src/unstract/sdk1/adapters/base1.py@@ -535,6 +535,22 @@ class AnthropicLLMParameters(BaseChatCompletionParameters):if not enable_thinking and has_thinking_config:enable_thinking = True+ # Handle extended context (1M tokens) configuration+ enable_extended_context = adapter_metadata.get("enable_extended_context", False)++ # If enable_extended_context is not explicitly provided but extra_headers+ # with context-1m is present, assume it was enabled in a previous validation+ extra_headers = adapter_metadata.get("extra_headers", {}) or {}+ anthropic_beta = str(extra_headers.get("anthropic-beta", ""))+ has_extended_context_header = (+ "extra_headers" in adapter_metadata+ and adapter_metadata.get("extra_headers") is not None+ and "anthropic-beta" in extra_headers+ and "context-1m" in anthropic_beta+ )+ if not enable_extended_context and has_extended_context_header:+ enable_extended_context = True+# Create a copy to avoid mutating the original metadataresult_metadata = adapter_metadata.copy()@@ -552,10 +568,15 @@ class AnthropicLLMParameters(BaseChatCompletionParameters):result_metadata["temperature"] = 1# Create validation metadata excluding control fields+ exclude_fields = (+ "enable_thinking",+ "budget_tokens",+ "thinking",+ "enable_extended_context",+ "extra_headers",+ )validation_metadata = {- k: v- for k, v in result_metadata.items()- if k not in ("enable_thinking", "budget_tokens", "thinking")+ k: v for k, v in result_metadata.items() if k not in exclude_fields}validated = AnthropicLLMParameters(**validation_metadata).model_dump()@@ -564,6 +585,10 @@ class AnthropicLLMParameters(BaseChatCompletionParameters):if enable_thinking and "thinking" in result_metadata:validated["thinking"] = result_metadata["thinking"]+ # Add extra_headers for extended context (1M tokens) if enabled+ if enable_extended_context:+ validated["extra_headers"] = {"anthropic-beta": "context-1m-2025-08-07"}+return validated@staticmethoddiff --git a/unstract/sdk1/src/unstract/sdk1/adapters/llm1/static/anthropic.json b/unstract/sdk1/src/unstract/sdk1/adapters/llm1/static/anthropic.jsonindex 335d90b12..52381d6cf 100644--- a/unstract/sdk1/src/unstract/sdk1/adapters/llm1/static/anthropic.json+++ b/unstract/sdk1/src/unstract/sdk1/adapters/llm1/static/anthropic.json@@ -51,7 +51,13 @@"type": "boolean","title": "Enable Extended Thinking","default": false,- "description": "Enhance reasoning for complex tasks with step-by-step transparency. Available only for Claude 3.7 Sonnet."+ "description": "Enhances reasoning for complex tasks with step-by-step transparency. For more information checkout Anthropic's official [doc](https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking)."+ },+ "enable_extended_context": {+ "type": "boolean",+ "title": "Enable Extended Context (1M)",+ "default": false,+ "description": "Enables 1M token context window (beta). Available for Sonnet 4 and 4.5. [Learn more](https://platform.claude.com/docs/en/build-with-claude/context-windows#1-m-token-context-window)"}},"allOf": [