Skip to content

Commit 005f172

Browse files
committed
fix: ensure Vertex Claude Sonnet 1M context window is fully supported in streaming and UI (PR #7848)
1 parent 29781ca commit 005f172

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/api/providers/anthropic-vertex.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
104104
: systemPrompt,
105105
messages: supportsPromptCache ? addCacheBreakpoints(messages) : messages,
106106
stream: true,
107+
// Enable 1M context window if flag is set and model matches
108+
...(id === ANTHROPIC_VERTEX_1M_CONTEXT_MODEL_ID && this.options.vertex1MContext
109+
? { additionalModelRequestFields: { anthropic_beta: ["context-1m-2025-08-07"] } }
110+
: {}),
107111
}
108112

109113
const stream = await this.client.messages.create(params)
@@ -220,6 +224,9 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
220224
},
221225
],
222226
stream: false,
227+
...(id === ANTHROPIC_VERTEX_1M_CONTEXT_MODEL_ID && this.options.vertex1MContext
228+
? { additionalModelRequestFields: { anthropic_beta: ["context-1m-2025-08-07"] } }
229+
: {}),
223230
}
224231

225232
const response = await this.client.messages.create(params)

webview-ui/src/components/ui/hooks/useSelectedModel.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,16 @@ function getSelectedModel({
214214
}
215215
case "vertex": {
216216
const id = apiConfiguration.apiModelId ?? vertexDefaultModelId
217-
const info = vertexModels[id as keyof typeof vertexModels]
218-
return { id, info }
217+
const baseInfo = vertexModels[id as keyof typeof vertexModels]
218+
// Apply 1M context for Claude Sonnet 4 when enabled
219+
if (id === "claude-sonnet-4@20250514" && apiConfiguration.vertex1MContext && baseInfo) {
220+
const info: ModelInfo = {
221+
...baseInfo,
222+
contextWindow: 1_000_000,
223+
}
224+
return { id, info }
225+
}
226+
return { id, info: baseInfo }
219227
}
220228
case "gemini": {
221229
const id = apiConfiguration.apiModelId ?? geminiDefaultModelId

0 commit comments

Comments
 (0)