Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions .review/pr-8274
Submodule pr-8274 added at e46929
5 changes: 3 additions & 2 deletions src/api/providers/__tests__/anthropic.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,14 @@ describe("AnthropicHandler", () => {
expect(result.temperature).toBe(0)
})

it("should handle Claude 4.5 Sonnet model correctly", () => {
it("should handle Claude 4.5 Sonnet model correctly and convert ID to API format", () => {
const handler = new AnthropicHandler({
apiKey: "test-api-key",
apiModelId: "claude-4.5-sonnet",
})
const model = handler.getModel()
expect(model.id).toBe("claude-4.5-sonnet")
// The model ID should be converted to the format expected by Anthropic API
expect(model.id).toBe("claude-sonnet-4-5")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

P2: Good coverage for getModel() conversion. Consider adding a test that calls createMessage() with apiModelId: \"claude-4.5-sonnet\" and asserts the SDK is invoked with \"claude-sonnet-4-5\" (inspect the mock’s options.model).

expect(model.info.maxTokens).toBe(64000)
expect(model.info.contextWindow).toBe(200000)
expect(model.info.supportsReasoningBudget).toBe(true)
Expand Down
26 changes: 22 additions & 4 deletions src/api/providers/anthropic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,23 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
const cacheControl: CacheControlEphemeral = { type: "ephemeral" }
let { id: modelId, betas = [], maxTokens, temperature, reasoning: thinking } = this.getModel()

// Store the original model ID for switch statements
const originalModelId = modelId

// Convert claude-4.5-sonnet to the format expected by Anthropic API
Copy link
Contributor Author

Choose a reason for hiding this comment

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

P2: The model ID conversion logic is duplicated here and in getModel(). Suggest extracting a helper (e.g., mapInternalToApiModelId(id)) and using it in both places to avoid drift.

if (modelId === "claude-4.5-sonnet") {
modelId = "claude-sonnet-4-5" as any
Copy link
Contributor Author

Choose a reason for hiding this comment

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

P2: Type safety. Avoid as any here—prefer a precise type to prevent future regressions.

Suggested change
modelId = "claude-sonnet-4-5" as any
modelId = "claude-sonnet-4-5" as AnthropicModelId

}

// Add 1M context beta flag if enabled for Claude Sonnet 4 and 4.5
if (
(modelId === "claude-sonnet-4-20250514" || modelId === "claude-4.5-sonnet") &&
(originalModelId === "claude-sonnet-4-20250514" || originalModelId === "claude-4.5-sonnet") &&
this.options.anthropicBeta1MContext
) {
betas.push("context-1m-2025-08-07")
}

switch (modelId) {
switch (originalModelId) {
case "claude-4.5-sonnet":
case "claude-sonnet-4-20250514":
case "claude-opus-4-1-20250805":
Expand Down Expand Up @@ -113,7 +121,7 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
// https://github.com/anthropics/anthropic-sdk-typescript/commit/c920b77fc67bd839bfeb6716ceab9d7c9bbe7393

// Then check for models that support prompt caching
switch (modelId) {
switch (originalModelId) {
case "claude-4.5-sonnet":
case "claude-sonnet-4-20250514":
case "claude-opus-4-1-20250805":
Expand Down Expand Up @@ -275,8 +283,18 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
// reasoning model and that reasoning is required to be enabled.
// The actual model ID honored by Anthropic's API does not have this
// suffix.

// Map internal model IDs to Anthropic API model IDs
let apiModelId = id
if (id === "claude-3-7-sonnet-20250219:thinking") {
apiModelId = "claude-3-7-sonnet-20250219"
} else if (id === "claude-4.5-sonnet") {
// Convert claude-4.5-sonnet to the format expected by Anthropic API
apiModelId = "claude-sonnet-4-5" as AnthropicModelId
}

return {
id: id === "claude-3-7-sonnet-20250219:thinking" ? "claude-3-7-sonnet-20250219" : id,
id: apiModelId,
info,
betas: id === "claude-3-7-sonnet-20250219:thinking" ? ["output-128k-2025-02-19"] : undefined,
...params,
Expand Down
1 change: 1 addition & 0 deletions tmp/pr-8287-Roo-Code
Submodule pr-8287-Roo-Code added at 88a473
Loading