Skip to content

fix(openrouter): correct reserved tokens for google/gemini-2.5-pro-preview #3896

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
8 changes: 8 additions & 0 deletions src/api/providers/__tests__/openrouter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ describe("OpenRouterHandler", () => {
expect(result.reasoningBudget).toBeUndefined()
expect(result.temperature).toBe(0)
})
it("sets maxTokens to 66000 for google/gemini-2.5-pro-preview", async () => {
const handler = new OpenRouterHandler({
openRouterApiKey: "test-key",
openRouterModelId: "google/gemini-2.5-pro-preview",
})
const result = await handler.fetchModel()
expect(result.maxTokens).toBe(66000)
})
})

describe("createMessage", () => {
Expand Down
6 changes: 5 additions & 1 deletion src/api/providers/fetchers/openrouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,11 @@ export async function getOpenRouterModels(options?: ApiHandlerOptions): Promise<
id,
model,
modality: architecture?.modality,
maxTokens: id.startsWith("anthropic/") ? top_provider?.max_completion_tokens : 0,
maxTokens: id.startsWith("anthropic/")
Copy link

Choose a reason for hiding this comment

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

The nested ternary for maxTokens reduces clarity. Consider extracting the condition (and using a named constant for 66000) to improve maintainability.

? top_provider?.max_completion_tokens
: id === "google/gemini-2.5-pro-preview"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does openrouter just not include this number? Is that a bug?

Copy link
Author

Choose a reason for hiding this comment

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

let me check it thoroughly

Copy link
Author

Choose a reason for hiding this comment

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

after doing some debugging ive hit a wall, the model file we fetch from openrouter does have it as 66k but without this i see 209k and hardcoding is showing 66k correctly. am still trying to figure it out why its happening with gemini or its an issue for all models in openrouter

? 66000
: 0,
supportedParameters: supported_parameters,
})
}
Expand Down