Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit ec40a48

Browse files
committed
fix: preserve custom model name in Anthropic provider instead of falling back to default
1 parent 137d3f4 commit ec40a48

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

src/api/providers/__tests__/anthropic.spec.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,39 @@ describe("AnthropicHandler", () => {
343343
expect(model.info.inputPrice).toBe(6.0)
344344
expect(model.info.outputPrice).toBe(22.5)
345345
})
346+
347+
it("should pass through custom/unknown model IDs instead of falling back to default", () => {
348+
const handler = new AnthropicHandler({
349+
apiKey: "test-api-key",
350+
apiModelId: "qwen/qwen3.6-plus",
351+
})
352+
const model = handler.getModel()
353+
expect(model.id).toBe("qwen/qwen3.6-plus")
354+
// Should use default model info as fallback for unknown models
355+
expect(model.info).toBeDefined()
356+
expect(model.info.contextWindow).toBeDefined()
357+
})
358+
359+
it("should use default model ID when no model ID is provided at all", () => {
360+
const handler = new AnthropicHandler({
361+
apiKey: "test-api-key",
362+
apiModelId: undefined,
363+
})
364+
const model = handler.getModel()
365+
expect(model.id).toBeDefined()
366+
// Should fall back to anthropicDefaultModelId, not an empty string
367+
expect(model.id).not.toBe("")
368+
})
369+
370+
it("should preserve custom model ID when using custom base URL", () => {
371+
const handler = new AnthropicHandler({
372+
apiKey: "test-api-key",
373+
anthropicBaseUrl: "http://localhost:3000/api",
374+
apiModelId: "my-custom-model",
375+
})
376+
const model = handler.getModel()
377+
expect(model.id).toBe("my-custom-model")
378+
})
346379
})
347380

348381
describe("reasoning block filtering", () => {

src/api/providers/anthropic.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,11 @@ export class AnthropicHandler extends BaseProvider implements SingleCompletionHa
334334

335335
getModel() {
336336
const modelId = this.options.apiModelId
337-
let id = modelId && modelId in anthropicModels ? (modelId as AnthropicModelId) : anthropicDefaultModelId
338-
let info: ModelInfo = anthropicModels[id]
337+
const isKnownModel = modelId !== undefined && modelId in anthropicModels
338+
let id: string = isKnownModel ? (modelId as AnthropicModelId) : modelId || anthropicDefaultModelId
339+
let info: ModelInfo = isKnownModel
340+
? anthropicModels[modelId as AnthropicModelId]
341+
: anthropicModels[anthropicDefaultModelId]
339342

340343
// If 1M context beta is enabled for supported models, update the model info
341344
if (

0 commit comments

Comments
 (0)