Skip to content

Commit a709b5d

Browse files
committed
feat(vertex): add [1m] variants for Claude Sonnet models and send anthropic-beta header on Vertex; restore base to 200k and add tests
1 parent eefe194 commit a709b5d

File tree

3 files changed

+59
-10
lines changed

3 files changed

+59
-10
lines changed

packages/types/src/providers/vertex.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,18 @@ export const vertexModels = {
164164
outputPrice: 5,
165165
},
166166
"claude-sonnet-4@20250514": {
167+
maxTokens: 8192,
168+
contextWindow: 200_000,
169+
supportsImages: true,
170+
supportsComputerUse: true,
171+
supportsPromptCache: true,
172+
inputPrice: 3.0,
173+
outputPrice: 15.0,
174+
cacheWritesPrice: 3.75,
175+
cacheReadsPrice: 0.3,
176+
supportsReasoningBudget: true,
177+
},
178+
"claude-sonnet-4@20250514[1m]": {
167179
maxTokens: 8192,
168180
contextWindow: 1_000_000,
169181
supportsImages: true,
@@ -176,6 +188,18 @@ export const vertexModels = {
176188
supportsReasoningBudget: true,
177189
},
178190
"claude-sonnet-4-5@20250929": {
191+
maxTokens: 8192,
192+
contextWindow: 200_000,
193+
supportsImages: true,
194+
supportsComputerUse: true,
195+
supportsPromptCache: true,
196+
inputPrice: 3.0,
197+
outputPrice: 15.0,
198+
cacheWritesPrice: 3.75,
199+
cacheReadsPrice: 0.3,
200+
supportsReasoningBudget: true,
201+
},
202+
"claude-sonnet-4-5@20250929[1m]": {
179203
maxTokens: 8192,
180204
contextWindow: 1_000_000,
181205
supportsImages: true,

src/api/providers/__tests__/anthropic-vertex.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,28 +691,30 @@ describe("VertexHandler", () => {
691691
expect(modelInfo.info.contextWindow).toBe(200_000)
692692
})
693693

694-
it("should return 1M context window for Claude Sonnet 4", () => {
694+
it("should return 1M context window for Claude Sonnet 4 [1m] variant", () => {
695695
handler = new AnthropicVertexHandler({
696-
apiModelId: "claude-sonnet-4@20250514",
696+
apiModelId: "claude-sonnet-4@20250514[1m]",
697697
vertexProjectId: "test-project",
698698
vertexRegion: "us-central1",
699699
})
700700

701701
const modelInfo = handler.getModel()
702+
// The provider strips the [1m] suffix when sending to API
702703
expect(modelInfo.id).toBe("claude-sonnet-4@20250514")
703704
expect(modelInfo.info).toBeDefined()
704705
expect(modelInfo.info.maxTokens).toBe(8192)
705706
expect(modelInfo.info.contextWindow).toBe(1_000_000)
706707
})
707708

708-
it("should return 1M context window for Claude Sonnet 4.5", () => {
709+
it("should return 1M context window for Claude Sonnet 4.5 [1m] variant", () => {
709710
handler = new AnthropicVertexHandler({
710-
apiModelId: "claude-sonnet-4-5@20250929",
711+
apiModelId: "claude-sonnet-4-5@20250929[1m]",
711712
vertexProjectId: "test-project",
712713
vertexRegion: "us-central1",
713714
})
714715

715716
const modelInfo = handler.getModel()
717+
// The provider strips the [1m] suffix when sending to API
716718
expect(modelInfo.id).toBe("claude-sonnet-4-5@20250929")
717719
expect(modelInfo.info).toBeDefined()
718720
expect(modelInfo.info.maxTokens).toBe(8192)

src/api/providers/anthropic-vertex.ts

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,29 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
8787
model: id,
8888
max_tokens: maxTokens ?? ANTHROPIC_DEFAULT_MAX_TOKENS,
8989
temperature,
90-
thinking,
9190
// Cache the system prompt if caching is enabled.
9291
system: supportsPromptCache
9392
? [{ text: systemPrompt, type: "text" as const, cache_control: { type: "ephemeral" } }]
9493
: systemPrompt,
9594
messages: supportsPromptCache ? addCacheBreakpoints(messages) : messages,
9695
stream: true,
9796
}
97+
// Only set thinking if defined to avoid adding an explicit undefined property
98+
if (thinking) {
99+
;(params as any).thinking = thinking
100+
}
98101

99-
const stream = await this.client.messages.create(params)
102+
// Enable 1M context beta when using [1m] variants
103+
const use1m = this.options.apiModelId?.endsWith("[1m]") === true
104+
105+
let stream
106+
if (use1m) {
107+
stream = await this.client.messages.create(params, {
108+
headers: { "anthropic-beta": "context-1m-2025-08-07" },
109+
})
110+
} else {
111+
stream = await this.client.messages.create(params)
112+
}
100113

101114
for await (const chunk of stream) {
102115
switch (chunk.type) {
@@ -171,8 +184,10 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
171184
// The `:thinking` suffix indicates that the model is a "Hybrid"
172185
// reasoning model and that reasoning is required to be enabled.
173186
// The actual model ID honored by Anthropic's API does not have this
174-
// suffix.
175-
return { id: id.endsWith(":thinking") ? id.replace(":thinking", "") : id, info, ...params }
187+
// suffix. Additionally, strip the optional [1m] suffix used to
188+
// denote the 1M context beta variant in Roo's model list.
189+
const normalizedId = id.replace(":thinking", "").replace("[1m]", "")
190+
return { id: normalizedId, info, ...params }
176191
}
177192

178193
async completePrompt(prompt: string) {
@@ -189,7 +204,6 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
189204
model: id,
190205
max_tokens: maxTokens,
191206
temperature,
192-
thinking,
193207
messages: [
194208
{
195209
role: "user",
@@ -200,8 +214,17 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
200214
],
201215
stream: false,
202216
}
217+
// Only set thinking if defined to avoid adding an explicit undefined property
218+
if (thinking) {
219+
;(params as any).thinking = thinking
220+
}
221+
222+
// Enable 1M context beta when using [1m] variants
223+
const use1m = this.options.apiModelId?.endsWith("[1m]") === true
203224

204-
const response = await this.client.messages.create(params)
225+
const response = use1m
226+
? await this.client.messages.create(params, { headers: { "anthropic-beta": "context-1m-2025-08-07" } })
227+
: await this.client.messages.create(params)
205228
const content = response.content[0]
206229

207230
if (content.type === "text") {

0 commit comments

Comments
 (0)