fix: handle vscode-lm-proxy model ID for claude provider - #19
Conversation
When provider is 'claude' and modelId is 'vscode-lm-proxy', properly resolve to the selected Claude Code Background model instead of throwing a 'model not found' error. Fixes issue where Claude Code endpoint failed with 404 when using vscode-lm-proxy as the model name.
There was a problem hiding this comment.
Pull request overview
This PR fixes a 404 error in the Claude Code endpoint by adding proper handling for the 'vscode-lm-proxy' model ID when using the Claude provider. The fix ensures that when vscode-lm-proxy is specified, the function resolves it to the selected Claude Code Background model.
Changes:
- Added Claude provider case in the
vscode-lm-proxyresolution block to map to the Background model - Updated the Claude-specific model routing logic to skip when
modelIdis'vscode-lm-proxy'(already resolved) - Added null-checking for the Background and Thinking model retrieval operations
| } else if (provider === 'claude') { | ||
| selectedModelId = modelManager.getClaudeCodeBackgroundModelId() |
There was a problem hiding this comment.
The choice to always use Background model for vscode-lm-proxy with Claude provider may not align with all use cases. Consider documenting why Background model is the default choice rather than Thinking model, or consider making this configurable. This is consistent with how OpenAI and Anthropic providers work (they each have a single default), but the Claude provider has two distinct model types (Background vs Thinking).
| const backgroundModel = modelManager.getClaudeCodeBackgroundModelId() | ||
| if (backgroundModel) { | ||
| selectedModelId = backgroundModel | ||
| } | ||
| } else if (modelId.includes('sonnet') || modelId.includes('opus')) { | ||
| selectedModelId = modelManager.getClaudeCodeThinkingModelId() | ||
| const thinkingModel = modelManager.getClaudeCodeThinkingModelId() | ||
| if (thinkingModel) { | ||
| selectedModelId = thinkingModel | ||
| } |
There was a problem hiding this comment.
The null-checking added here is good defensive programming. However, if these methods return null, selectedModelId retains its previous value (the original modelId), which will likely fail at line 78-80 when calling vscode.lm.selectChatModels(). Consider throwing an error with a clear message when the required model configuration is missing, rather than silently continuing with an invalid model ID.
Problem
The Claude Code endpoint (
POST /anthropic/claude/v1/messages) fails with a 404 error when using"model": "vscode-lm-proxy"in the request. The error indicates the model is not found in the VSCode Language Model API.Root Cause
The
getVSCodeModel()function insrc/server/handler.tswas missing a case to handleprovider === 'claude'whenmodelId === 'vscode-lm-proxy'. This caused the function to pass'vscode-lm-proxy'directly tovscode.lm.selectChatModels()instead of resolving it to the actual selected Claude Code Background model.Solution
Added a check in the
if (modelId === 'vscode-lm-proxy')condition to handle the Claude provider by resolving to the selected Claude Code Background model, matching the behavior for OpenAI and Anthropic providers.Changes
src/server/handler.ts: Added Claude provider handling ingetVSCodeModel()functionTesting
The fix allows the Claude Code endpoint to properly resolve and use the selected Claude model when
vscode-lm-proxyis specified as the model name.