Skip to content
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/types/src/provider-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ const baseProviderSettingsSchema = z.object({

// Model verbosity.
verbosity: verbosityLevelsSchema.optional(),

// Generic large input tier toggle applied across providers that define tiers
// When enabled, Roo will select the highest contextWindow tier (e.g. "over 200k" / "1M") if available.
largeInputTierEnabled: z.boolean().optional(),
})

// Several of the providers share common model config properties.
Expand Down
22 changes: 22 additions & 0 deletions packages/types/src/providers/vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,17 @@ export const vertexModels = {
cacheReadsPrice: 0.3,
supportsReasoningBudget: true,
},
"claude-sonnet-4@20250514[1m]": {
maxTokens: 8192,
contextWindow: 1_000_000,
supportsImages: true,
supportsPromptCache: true,
inputPrice: 6.0,
outputPrice: 22.5,
cacheWritesPrice: 7.5,
cacheReadsPrice: 0.6,
supportsReasoningBudget: true,
},
"claude-sonnet-4-5@20250929": {
maxTokens: 8192,
contextWindow: 200_000,
Expand All @@ -187,6 +198,17 @@ export const vertexModels = {
cacheReadsPrice: 0.3,
supportsReasoningBudget: true,
},
"claude-sonnet-4-5@20250929[1m]": {
maxTokens: 8192,
contextWindow: 1_000_000,
supportsImages: true,
supportsPromptCache: true,
inputPrice: 6.0,
outputPrice: 22.5,
cacheWritesPrice: 7.5,
cacheReadsPrice: 0.6,
supportsReasoningBudget: true,
},
"claude-haiku-4-5@20251001": {
maxTokens: 8192,
contextWindow: 200_000,
Expand Down
30 changes: 30 additions & 0 deletions src/api/providers/__tests__/anthropic-vertex.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,6 +691,36 @@ describe("VertexHandler", () => {
expect(modelInfo.info.contextWindow).toBe(200_000)
})

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

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

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

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

it("honors custom maxTokens for thinking models", () => {
const handler = new AnthropicVertexHandler({
apiKey: "test-api-key",
Expand Down
41 changes: 35 additions & 6 deletions src/api/providers/anthropic-vertex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,32 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
model: id,
max_tokens: maxTokens ?? ANTHROPIC_DEFAULT_MAX_TOKENS,
temperature,
thinking,
// Cache the system prompt if caching is enabled.
system: supportsPromptCache
? [{ text: systemPrompt, type: "text" as const, cache_control: { type: "ephemeral" } }]
: systemPrompt,
messages: supportsPromptCache ? addCacheBreakpoints(messages) : messages,
stream: true,
}
// Only set thinking if defined to avoid adding an explicit undefined property
if (thinking) {
;(params as any).thinking = thinking
}

const stream = await this.client.messages.create(params)
// Enable 1M context beta when using [1m] variants or when explicitly enabled via settings for Sonnet 4/4.5
const use1m =
this.options.apiModelId?.endsWith("[1m]") === true ||
((id === "claude-sonnet-4@20250514" || id === "claude-sonnet-4-5@20250929") &&
this.options.anthropicBeta1MContext === true)
Comment on lines +102 to +106
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code checks this.options.anthropicBeta1MContext which doesn't exist in the Vertex provider settings schema. The vertexSchema in provider-settings.ts (line 238) doesn't include anthropicBeta1MContext - that property only exists in anthropicSchema (line 199). This creates a critical discrepancy: when users enable largeInputTierEnabled for Vertex Sonnet 4/4.5 models, the frontend will charge 1M pricing but the backend won't send the required anthropic-beta: context-1m-2025-08-07 header, resulting in users being charged for 1M context while only receiving 200K. The check should use this.options.largeInputTierEnabled instead to match the frontend logic in useSelectedModel.ts line 253.


let stream
if (use1m) {
stream = await this.client.messages.create(params, {
headers: { "anthropic-beta": "context-1m-2025-08-07" },
})
} else {
stream = await this.client.messages.create(params)
}

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

async completePrompt(prompt: string) {
Expand All @@ -189,7 +207,6 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
model: id,
max_tokens: maxTokens,
temperature,
thinking,
messages: [
{
role: "user",
Expand All @@ -200,8 +217,20 @@ export class AnthropicVertexHandler extends BaseProvider implements SingleComple
],
stream: false,
}
// Only set thinking if defined to avoid adding an explicit undefined property
if (thinking) {
;(params as any).thinking = thinking
}

// Enable 1M context beta when using [1m] variants or when explicitly enabled via settings for Sonnet 4/4.5
const use1m =
this.options.apiModelId?.endsWith("[1m]") === true ||
((id === "claude-sonnet-4@20250514" || id === "claude-sonnet-4-5@20250929") &&
this.options.anthropicBeta1MContext === true)

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

if (content.type === "text") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,109 @@ describe("useSelectedModel", () => {
})
})
})

describe("vertex provider pricing with region and [1m] tiers", () => {
beforeEach(() => {
// Keep other hooks stable/inert for Vertex path
;(mockUseRouterModels as any).mockReturnValue({
data: { openrouter: {}, requesty: {}, glama: {}, unbound: {}, litellm: {}, "io-intelligence": {} },
isLoading: false,
isError: false,
})
;(mockUseOpenRouterModelProviders as any).mockReturnValue({
data: {},
isLoading: false,
isError: false,
})
})

it("applies global pricing for Sonnet 4 under 200k (no [1m])", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "vertex",
apiModelId: "claude-sonnet-4@20250514",
vertexRegion: "global",
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.provider).toBe("vertex")
expect(result.current.id).toBe("claude-sonnet-4@20250514")
expect(result.current.info?.inputPrice).toBe(3.0)
expect(result.current.info?.outputPrice).toBe(15.0)
expect(result.current.info?.cacheWritesPrice).toBe(3.75)
expect(result.current.info?.cacheReadsPrice).toBe(0.3)
})

it("applies global pricing for Sonnet 4 over 200k ([1m])", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "vertex",
apiModelId: "claude-sonnet-4@20250514[1m]",
vertexRegion: "global",
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.provider).toBe("vertex")
expect(result.current.id).toBe("claude-sonnet-4@20250514[1m]")
expect(result.current.info?.inputPrice).toBe(6.0)
expect(result.current.info?.outputPrice).toBe(22.5)
expect(result.current.info?.cacheWritesPrice).toBe(7.5)
expect(result.current.info?.cacheReadsPrice).toBe(0.6)
})

it("applies regional pricing for Sonnet 4.5 under 200k in us-east5", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "vertex",
apiModelId: "claude-sonnet-4-5@20250929",
vertexRegion: "us-east5",
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.provider).toBe("vertex")
expect(result.current.id).toBe("claude-sonnet-4-5@20250929")
expect(result.current.info?.inputPrice).toBe(3.3)
expect(result.current.info?.outputPrice).toBe(16.5)
expect(result.current.info?.cacheWritesPrice).toBe(4.13)
expect(result.current.info?.cacheReadsPrice).toBe(0.33)
})

it("applies regional pricing for Sonnet 4.5 over 200k ([1m]) in us-east5", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "vertex",
apiModelId: "claude-sonnet-4-5@20250929[1m]",
vertexRegion: "us-east5",
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.provider).toBe("vertex")
expect(result.current.id).toBe("claude-sonnet-4-5@20250929[1m]")
expect(result.current.info?.inputPrice).toBe(6.6)
expect(result.current.info?.outputPrice).toBe(24.75)
expect(result.current.info?.cacheWritesPrice).toBe(8.25)
expect(result.current.info?.cacheReadsPrice).toBe(0.66)
})

it("applies global pricing for Sonnet 4.5 over 200k ([1m]) in non-regional areas (e.g., us-central1)", () => {
const apiConfiguration: ProviderSettings = {
apiProvider: "vertex",
apiModelId: "claude-sonnet-4-5@20250929[1m]",
vertexRegion: "us-central1", // treated as global pricing per rules
}

const wrapper = createWrapper()
const { result } = renderHook(() => useSelectedModel(apiConfiguration), { wrapper })

expect(result.current.provider).toBe("vertex")
expect(result.current.id).toBe("claude-sonnet-4-5@20250929[1m]")
expect(result.current.info?.inputPrice).toBe(6.0)
expect(result.current.info?.outputPrice).toBe(22.5)
expect(result.current.info?.cacheWritesPrice).toBe(7.5)
expect(result.current.info?.cacheReadsPrice).toBe(0.6)
})
})
Loading