Skip to content

Commit 5e2b345

Browse files
committed
feat: Add OpenRouter reasoning controls for anthropic/claude-opus-4.1
- Added model to OPEN_ROUTER_PROMPT_CACHING_MODELS for prompt caching support - Added model to OPEN_ROUTER_COMPUTER_USE_MODELS for computer use support - Added model to OPEN_ROUTER_REASONING_BUDGET_MODELS for reasoning budget support - Added special handling in parseOpenRouterModel to use correct max tokens from anthropicModels - Updated tests to exclude the model until it's available in OpenRouter API
1 parent bdc82e1 commit 5e2b345

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

packages/types/src/providers/openrouter.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const OPEN_ROUTER_PROMPT_CACHING_MODELS = new Set([
3939
"anthropic/claude-3.7-sonnet:thinking",
4040
"anthropic/claude-sonnet-4",
4141
"anthropic/claude-opus-4",
42+
"anthropic/claude-opus-4.1",
4243
"google/gemini-2.5-flash-preview",
4344
"google/gemini-2.5-flash-preview:thinking",
4445
"google/gemini-2.5-flash-preview-05-20",
@@ -59,6 +60,7 @@ export const OPEN_ROUTER_COMPUTER_USE_MODELS = new Set([
5960
"anthropic/claude-3.7-sonnet:thinking",
6061
"anthropic/claude-sonnet-4",
6162
"anthropic/claude-opus-4",
63+
"anthropic/claude-opus-4.1",
6264
])
6365

6466
// When we first launched these models we didn't have support for
@@ -77,6 +79,7 @@ export const OPEN_ROUTER_REQUIRED_REASONING_BUDGET_MODELS = new Set([
7779
export const OPEN_ROUTER_REASONING_BUDGET_MODELS = new Set([
7880
"anthropic/claude-3.7-sonnet:beta",
7981
"anthropic/claude-opus-4",
82+
"anthropic/claude-opus-4.1",
8083
"anthropic/claude-sonnet-4",
8184
"google/gemini-2.5-pro-preview",
8285
"google/gemini-2.5-pro",

src/api/providers/fetchers/__tests__/openrouter.spec.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ describe("OpenRouter API", () => {
3232
"google/gemini-2.5-pro-preview", // Excluded due to lag issue (#4487)
3333
"google/gemini-2.5-flash", // OpenRouter doesn't report this as supporting prompt caching
3434
"google/gemini-2.5-flash-lite-preview-06-17", // OpenRouter doesn't report this as supporting prompt caching
35+
"anthropic/claude-opus-4.1", // Not yet available in OpenRouter API
3536
])
3637

3738
const ourCachingModels = Array.from(OPEN_ROUTER_PROMPT_CACHING_MODELS).filter(
@@ -48,12 +49,20 @@ describe("OpenRouter API", () => {
4849

4950
expect(ourCachingModels.sort()).toEqual(expectedCachingModels)
5051

52+
const excludedComputerUseModels = new Set([
53+
"anthropic/claude-opus-4.1", // Not yet available in OpenRouter API
54+
])
55+
56+
const expectedComputerUseModels = Array.from(OPEN_ROUTER_COMPUTER_USE_MODELS)
57+
.filter((id) => !excludedComputerUseModels.has(id))
58+
.sort()
59+
5160
expect(
5261
Object.entries(models)
5362
.filter(([_, model]) => model.supportsComputerUse)
5463
.map(([id, _]) => id)
5564
.sort(),
56-
).toEqual(Array.from(OPEN_ROUTER_COMPUTER_USE_MODELS).sort())
65+
).toEqual(expectedComputerUseModels)
5766

5867
expect(
5968
Object.entries(models)
@@ -67,6 +76,7 @@ describe("OpenRouter API", () => {
6776
"anthropic/claude-3.7-sonnet:beta",
6877
"anthropic/claude-3.7-sonnet:thinking",
6978
"anthropic/claude-opus-4",
79+
// "anthropic/claude-opus-4.1", // Not yet available in OpenRouter API
7080
"anthropic/claude-sonnet-4",
7181
"arliai/qwq-32b-arliai-rpr-v1:free",
7282
"cognitivecomputations/dolphin3.0-r1-mistral-24b:free",
@@ -122,6 +132,7 @@ describe("OpenRouter API", () => {
122132
"google/gemini-2.5-flash",
123133
"google/gemini-2.5-flash-lite-preview-06-17",
124134
"google/gemini-2.5-pro",
135+
"anthropic/claude-opus-4.1", // Not yet available in OpenRouter API
125136
])
126137

127138
const expectedReasoningBudgetModels = Array.from(OPEN_ROUTER_REASONING_BUDGET_MODELS)

src/api/providers/fetchers/openrouter.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,11 @@ export const parseOpenRouterModel = ({
232232
modelInfo.maxTokens = anthropicModels["claude-3-7-sonnet-20250219:thinking"].maxTokens
233233
}
234234

235+
// Set claude-opus-4.1 model to use the correct configuration
236+
if (id === "anthropic/claude-opus-4.1") {
237+
modelInfo.maxTokens = anthropicModels["claude-opus-4-1-20250805"].maxTokens
238+
}
239+
235240
// Set horizon-alpha model to 32k max tokens
236241
if (id === "openrouter/horizon-alpha") {
237242
modelInfo.maxTokens = 32768

0 commit comments

Comments
 (0)