-
-
Notifications
You must be signed in to change notification settings - Fork 352
Fixed a 400 error when using the new Claude code model. #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Fixed a 400 error that occurred when using the new Claude code model. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR aims to fix a 400 error when using the new Claude code model by implementing a more general regex-based approach to translate Claude model names to formats supported by GitHub Copilot.
Key changes:
- Replaces specific model name checks with a single regex pattern to transform Claude model names
- Adds logging to track model name transformations
- Minor formatting changes to import statements and variable inlining in
utils.ts
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/routes/messages/non-stream-translation.ts |
Refactored translateModelName function to use a regex pattern for transforming Claude model names from formats like claude-sonnet-4-20250115 to claude-sonnet-4.20250115, and added console logging for debugging |
src/lib/utils.ts |
Formatting changes: removed spaces in import statements and inlined a variable in cacheModels function |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return model.replace(/^claude-opus-4-.*/, "claude-opus-4") | ||
| if (model.startsWith("claude")) { | ||
| const newModel = model.replaceAll( | ||
| /(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g, |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex pattern does not match the actual Anthropic Claude model naming format. Anthropic models use the format claude-{version}-{variant}-{date} (e.g., claude-3-5-sonnet-20241022), but this regex expects claude-{variant}-{version}-{date} format.
The pattern /(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g would match something like claude-sonnet-4-20250115 but not claude-3-5-sonnet-20241022. This means the regex will not transform most Claude model names as intended, causing them to pass through unchanged when they should be transformed.
Consider updating the regex to match the actual Anthropic model format, or verify what specific model names from Claude Code need to be transformed.
| /(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g, | |
| /(claude-\d+(?:-\d+)?-(?:haiku|sonnet|opus))-(\d{8})(?:[.-]\d+)?/g, |
| consola.log("Use Model:", model, newModel) | ||
| return newModel | ||
| } | ||
| consola.log("Use Model:", model) |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These log statements will be emitted on every request, which could create excessive noise in production logs. Consider using a debug-level log (e.g., consola.debug) instead of consola.log, or removing these logs entirely once the feature is stable. Production logs should typically be reserved for errors, warnings, and important informational messages rather than routine processing details.
| consola.log("Use Model:", model, newModel) | |
| return newModel | |
| } | |
| consola.log("Use Model:", model) | |
| consola.debug("Use Model:", model, newModel) | |
| return newModel | |
| } | |
| consola.debug("Use Model:", model) |
| const newModel = model.replaceAll( | ||
| /(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g, | ||
| "$1.$2", | ||
| ) | ||
| consola.log("Use Model:", model, newModel) | ||
| return newModel |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new model name translation logic lacks test coverage. Given that this PR aims to fix a 400 error with Claude model names, tests should be added to verify that the regex correctly transforms various Claude model name formats (e.g., claude-sonnet-4-20250115 to claude-sonnet-4.20250115). Tests should also verify that models not matching the pattern are passed through unchanged. Consider adding tests in tests/anthropic-request.test.ts that specifically test the translateModelName function with various input formats.
| import {getModels} from "~/services/copilot/get-models" | ||
| import {getVSCodeVersion} from "~/services/get-vscode-version" | ||
|
|
||
| import { state } from "./state" | ||
| import {state} from "./state" |
Copilot
AI
Jan 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The import statement formatting is inconsistent with the rest of the codebase. The project uses spaces around braces in imports (e.g., import { getModels } rather than import {getModels}). For example, see the consistent pattern in files like src/auth.ts, src/routes/chat-completions/handler.ts, and many others. This inconsistency will likely be flagged by the linter.
|
@mrhanhan Hi, have you test on the Opus 4.5 with thinking? When I testing, it got following error. I didn't figure out where goes wrong. ` ERROR Error occurred: Failed to create chat completions ERROR HTTP error: { error: |
This method uses regular expressions to replace Claude code and the default requested model name with the corresponding fixed version of the model from GitHub Copilot.
#156 issues fixed