Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion src/api/providers/fetchers/__tests__/openrouter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
OPEN_ROUTER_REQUIRED_REASONING_BUDGET_MODELS,
} from "@roo-code/types"

import { getOpenRouterModelEndpoints, getOpenRouterModels } from "../openrouter"
import { getOpenRouterModelEndpoints, getOpenRouterModels, parseOpenRouterModel } from "../openrouter"

nockBack.fixtures = path.join(__dirname, "fixtures")
nockBack.setMode("lockdown")
Expand Down Expand Up @@ -251,4 +251,52 @@ describe("OpenRouter API", () => {
nockDone()
})
})

describe("parseOpenRouterModel", () => {
it("sets horizon-alpha model to 32k max tokens", () => {
const mockModel = {
name: "Horizon Alpha",
description: "Test model",
context_length: 128000,
max_completion_tokens: 128000,
pricing: {
prompt: "0.000003",
completion: "0.000015",
},
}

const result = parseOpenRouterModel({
id: "openrouter/horizon-alpha",
model: mockModel,
modality: "text",
maxTokens: 128000,
})

expect(result.maxTokens).toBe(32768)
expect(result.contextWindow).toBe(128000)
})

it("does not override max tokens for other models", () => {
const mockModel = {
name: "Other Model",
description: "Test model",
context_length: 128000,
max_completion_tokens: 64000,
pricing: {
prompt: "0.000003",
completion: "0.000015",
},
}

const result = parseOpenRouterModel({
id: "openrouter/other-model",
model: mockModel,
modality: "text",
maxTokens: 64000,
})

expect(result.maxTokens).toBe(64000)
expect(result.contextWindow).toBe(128000)
})
})
})
5 changes: 5 additions & 0 deletions src/api/providers/fetchers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,10 @@ export const parseOpenRouterModel = ({
modelInfo.maxTokens = anthropicModels["claude-3-7-sonnet-20250219:thinking"].maxTokens
}

// Set horizon-alpha model to 32k max tokens
if (id === "openrouter/horizon-alpha") {
modelInfo.maxTokens = 32768
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add test coverage for this new model override? The existing test file at src/api/providers/fetchers/tests/openrouter.spec.ts has comprehensive assertions for other model-specific overrides (like Claude 3.7 Sonnet models on lines 184-209), but doesn't include a test case for the horizon-alpha model. Adding something like expect(models["openrouter/horizon-alpha"].maxTokens).toEqual(32768) would ensure this override works as expected.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be beneficial to define this as a named constant to make the intent clearer? While this follows the existing pattern used for other model overrides in the same file, something like const HORIZON_ALPHA_MAX_TOKENS = 32768 could improve readability and maintainability.

}

return modelInfo
}