Skip to content

Commit 5435845

Browse files
fix(opencode): generate reasoning variants for all OpenRouter models. (anomalyco#30332)
Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Aiden Cline <aidenpcline@gmail.com>
1 parent e4ea2bf commit 5435845

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

packages/opencode/src/provider/transform.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -703,12 +703,11 @@ export function variants(model: Provider.Model): Record<string, Record<string, a
703703

704704
switch (model.api.npm) {
705705
case "@openrouter/ai-sdk-provider":
706-
if (!id.includes("gpt") && !id.includes("gemini-3") && !id.includes("claude")) return {}
707706
return Object.fromEntries(
708-
(id.includes("gpt") ? openaiCompatibleReasoningEfforts(id) : OPENAI_EFFORTS).map((effort) => [
709-
effort,
710-
{ reasoning: { effort } },
711-
]),
707+
(model.api.id.startsWith("openai/") || id.includes("gpt")
708+
? openaiCompatibleReasoningEfforts(model.api.id)
709+
: WIDELY_SUPPORTED_EFFORTS
710+
).map((effort) => [effort, { reasoning: { effort } }]),
712711
)
713712

714713
case "ai-gateway-provider": {
@@ -1202,6 +1201,9 @@ export function smallOptions(model: Provider.Model) {
12021201
return mergeDeep(base, small)
12031202
}
12041203
if (model.providerID === "openrouter" || model.providerID === "llmgateway") {
1204+
if (model.providerID === "openrouter" && small.reasoning?.effort === "low") {
1205+
return { reasoning: { effort: "none" } }
1206+
}
12051207
if (Object.keys(small).length === 0 && model.api.id.includes("google")) {
12061208
return { reasoning: { enabled: false } }
12071209
}

packages/opencode/test/provider/transform.test.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,7 +2666,7 @@ describe("ProviderTransform.variants", () => {
26662666
})
26672667

26682668
describe("@openrouter/ai-sdk-provider", () => {
2669-
test("returns empty object for non-qualifying models", () => {
2669+
test("returns widely supported efforts for other reasoning models", () => {
26702670
const model = createMockModel({
26712671
id: "openrouter/test-model",
26722672
providerID: "openrouter",
@@ -2677,7 +2677,8 @@ describe("ProviderTransform.variants", () => {
26772677
},
26782678
})
26792679
const result = ProviderTransform.variants(model)
2680-
expect(result).toEqual({})
2680+
expect(Object.keys(result)).toEqual(["low", "medium", "high"])
2681+
expect(result.medium).toEqual({ reasoning: { effort: "medium" } })
26812682
})
26822683

26832684
test("gpt models return OPENAI_EFFORTS with reasoning", () => {
@@ -2697,6 +2698,7 @@ describe("ProviderTransform.variants", () => {
26972698
})
26982699

26992700
for (const testCase of [
2701+
{ id: "openai/o3-mini", efforts: ["none", "minimal", "low", "medium", "high", "xhigh"] },
27002702
{ id: "openai/gpt-5.4", efforts: ["none", "low", "medium", "high", "xhigh"] },
27012703
{ id: "openai/gpt-5-pro", efforts: ["high"] },
27022704
{ id: "openai/gpt-5.5-pro", efforts: ["medium", "high", "xhigh"] },
@@ -2722,7 +2724,7 @@ describe("ProviderTransform.variants", () => {
27222724
})
27232725
}
27242726

2725-
test("gemini-3 returns OPENAI_EFFORTS with reasoning", () => {
2727+
test("gemini-3 returns widely supported efforts with reasoning", () => {
27262728
const model = createMockModel({
27272729
id: "openrouter/gemini-3-5-pro",
27282730
providerID: "openrouter",
@@ -2733,7 +2735,7 @@ describe("ProviderTransform.variants", () => {
27332735
},
27342736
})
27352737
const result = ProviderTransform.variants(model)
2736-
expect(Object.keys(result)).toEqual(["none", "minimal", "low", "medium", "high", "xhigh"])
2738+
expect(Object.keys(result)).toEqual(["low", "medium", "high"])
27372739
})
27382740

27392741
test("grok-4 returns empty object", () => {
@@ -3985,6 +3987,23 @@ describe("ProviderTransform.smallOptions - gpt-5 chat/search", () => {
39853987
}
39863988
})
39873989

3990+
test("ProviderTransform.smallOptions disables OpenRouter reasoning when the weakest effort is low", () => {
3991+
expect(
3992+
ProviderTransform.smallOptions({
3993+
providerID: "openrouter",
3994+
api: {
3995+
id: "anthropic/claude-sonnet-4.6",
3996+
npm: "@openrouter/ai-sdk-provider",
3997+
},
3998+
variants: {
3999+
low: { reasoning: { effort: "low" } },
4000+
medium: { reasoning: { effort: "medium" } },
4001+
high: { reasoning: { effort: "high" } },
4002+
},
4003+
} as any),
4004+
).toEqual({ reasoning: { effort: "none" } })
4005+
})
4006+
39884007
describe("ProviderTransform.smallOptions - google thinking controls", () => {
39894008
const createGoogleModel = (apiId: string) => {
39904009
const model = {

0 commit comments

Comments
 (0)