-
Notifications
You must be signed in to change notification settings - Fork 46
fix(provider): scope Anthropic context-1m beta header to 1M models #605
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,7 @@ export namespace Provider { | |
|
|
||
| const CUSTOM_LOADERS: Record<string, CustomLoader> = { | ||
| async anthropic() { | ||
| const longContextBeta = "context-1m-2025-08-07" | ||
| return { | ||
| autoload: false, | ||
| options: { | ||
|
|
@@ -103,9 +104,30 @@ export namespace Provider { | |
| // TODO: Add adaptive thinking headers when @ai-sdk/anthropic supports it: | ||
| // adaptive-thinking-2026-01-28,effort-2025-11-24,max-effort-2026-01-24 | ||
| "anthropic-beta": | ||
| "claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14,context-1m-2025-08-07", | ||
| "claude-code-20250219,interleaved-thinking-2025-05-14,fine-grained-tool-streaming-2025-05-14", | ||
| }, | ||
| }, | ||
| async getModel(_sdk: any, modelID: string, options?: Record<string, any>) { | ||
| const input = { ...(options ?? {}) } | ||
| const headers = { ...(input["headers"] ?? {}) } | ||
| const raw = typeof headers["anthropic-beta"] === "string" ? headers["anthropic-beta"] : "" | ||
| const parts = raw | ||
| .split(",") | ||
| .map((item) => item.trim()) | ||
| .filter(Boolean) | ||
| .filter((item) => item !== longContextBeta) | ||
|
|
||
| if (modelID.toLowerCase().includes("1m")) { | ||
| parts.push(longContextBeta) | ||
| } | ||
|
|
||
| headers["anthropic-beta"] = parts.join(",") | ||
| const sdk = createAnthropic({ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CRITICAL: This creates a brand-new The This means Anthropic 1M-context models will likely fail or behave incorrectly because the new SDK won't have the API key, base URL, or timeout handling. Consider modifying the headers on the existing |
||
| ...input, | ||
| headers, | ||
| }) | ||
| return sdk.languageModel(modelID) | ||
| }, | ||
| } | ||
| }, | ||
| openai: async () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING: The check
modelID.toLowerCase().includes("1m")is fragile. It would match any model ID containing "1m" anywhere (e.g., a hypothetical model likeclaude-21marchorclaude-v1mini). Consider a more specific pattern like checking for-1m-or a suffix match to reduce false positives.