Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 29, 2025

Description

This PR fixes issue #8379 where selecting Claude 4.5 Sonnet with the Anthropic provider results in a 404 error.

Problem

The Anthropic API expects the model ID to be claude-sonnet-4-5, but Roo Code was sending claude-4.5-sonnet, causing a 404 error:

404 {"type":"error","error":{"type":"not_found_error","message":"model: claude-4.5-sonnet"}}

Solution

  • Added model ID conversion in the AnthropicHandler class to map the internal claude-4.5-sonnet ID to the API-expected claude-sonnet-4-5 format
  • Preserved the original model ID for internal logic (switch statements for features like prompt caching)
  • Added test coverage to verify the correct model ID conversion

Changes

  • src/api/providers/anthropic.ts: Added model ID conversion logic in createMessage() and getModel() methods
  • src/api/providers/tests/anthropic.spec.ts: Added test to verify the model ID is correctly converted

Testing

  • ✅ All existing tests pass
  • ✅ Added new test specifically for Claude 4.5 Sonnet model ID conversion
  • ✅ Verified the conversion maintains all model capabilities (maxTokens, contextWindow, reasoning support)

Fixes #8379


Important

Fixes model ID format for Anthropic API by converting claude-4.5-sonnet to claude-sonnet-4-5 in AnthropicHandler.

  • Behavior:
    • Converts claude-4.5-sonnet to claude-sonnet-4-5 in AnthropicHandler to prevent 404 errors with Anthropic API.
    • Preserves original model ID for internal logic like prompt caching.
  • Testing:
    • Adds test in anthropic.spec.ts to verify model ID conversion.
    • Ensures all model capabilities are maintained post-conversion.
  • Files:
    • anthropic.ts: Implements model ID conversion in createMessage() and getModel().
    • anthropic.spec.ts: Adds test for model ID conversion.

This description was created by Ellipsis for 8154440. You can customize this summary. It will automatically update as commits are pushed.

- Map internal model ID claude-4.5-sonnet to API-expected claude-sonnet-4-5
- Update createMessage to use original model ID for switch statements
- Add test to verify correct model ID conversion
- Fixes #8379
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 29, 2025 19:51
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Sep 29, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 29, 2025
Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

Self-review activated: a robot refactoring its own model IDs to avoid 404s while questioning the nature of strings.


// Convert claude-4.5-sonnet to the format expected by Anthropic API
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

// 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.

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).

@@ -0,0 +1 @@
Subproject commit e46929b8d8add0cd3c412d69f8ac882c405a4ba9
Copy link
Contributor Author

Choose a reason for hiding this comment

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

P1: Unintended submodule/gitlink (.review/pr-8274). Please remove from the PR to avoid committing tooling artifacts.

@@ -0,0 +1 @@
Subproject commit 88a473b017af37091c85ce3056e444e856f80d6e
Copy link
Contributor Author

Choose a reason for hiding this comment

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

P1: Unintended tracked artifact (tmp/pr-8287-Roo-Code). Please remove from the PR and consider ignoring tmp/ in .gitignore.

@akraines
Copy link

image model id is claude-sonnet-4-5-20250929

@vladionescu
Copy link

image

@daniel-lxs daniel-lxs closed this Sep 29, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 29, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 29, 2025
@daniel-lxs daniel-lxs deleted the fix/claude-4-5-sonnet-model-id branch September 30, 2025 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[BUG] Sonnet 4.5 w/ Anthropic provider returning 404

6 participants