-
-
Notifications
You must be signed in to change notification settings - Fork 355
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,3 +1,5 @@ | ||||||||||||||||||
| import consola from "consola" | ||||||||||||||||||
|
|
||||||||||||||||||
| import { | ||||||||||||||||||
| type ChatCompletionResponse, | ||||||||||||||||||
| type ChatCompletionsPayload, | ||||||||||||||||||
|
|
@@ -48,11 +50,15 @@ export function translateToOpenAI( | |||||||||||||||||
|
|
||||||||||||||||||
| function translateModelName(model: string): string { | ||||||||||||||||||
| // Subagent requests use a specific model number which Copilot doesn't support | ||||||||||||||||||
| if (model.startsWith("claude-sonnet-4-")) { | ||||||||||||||||||
| return model.replace(/^claude-sonnet-4-.*/, "claude-sonnet-4") | ||||||||||||||||||
| } else if (model.startsWith("claude-opus-")) { | ||||||||||||||||||
| 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, | ||||||||||||||||||
|
||||||||||||||||||
| /(claude-(?:haiku|sonnet|opus)-\d+)-(\d+)(?:[.-]\d+)?/g, | |
| /(claude-\d+(?:-\d+)?-(?:haiku|sonnet|opus))-(\d{8})(?:[.-]\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 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.
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) |
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 thanimport {getModels}). For example, see the consistent pattern in files likesrc/auth.ts,src/routes/chat-completions/handler.ts, and many others. This inconsistency will likely be flagged by the linter.