Skip to content

fix: infer correct context window for OpenRouter-proxied models (#86)#88

Merged
bobmatnyc merged 1 commit intomainfrom
fix/issue-86-openrouter-context-window
Feb 22, 2026
Merged

fix: infer correct context window for OpenRouter-proxied models (#86)#88
bobmatnyc merged 1 commit intomainfrom
fix/issue-86-openrouter-context-window

Conversation

@bobmatnyc
Copy link
Copy Markdown
Owner

Summary

Follow-up to PR #87. The previous fix handled google:model-name but Sasha (@dietrichson) reported he's actually using openrouter:google/gemini-3.1-pro-preview, which still showed 128K instead of 1M+ tokens.

Root Cause

The fallback system uses DEFAULT_CONTEXT_WINDOWS['openrouter'] (128,000) for ALL unregistered OpenRouter models, regardless of the underlying model vendor. So openrouter:google/gemini-3.1-pro-preview got 128K instead of Gemini's actual 1,048,576.

Fix

Added pattern-matching in getEnhancedModelMapping() fallback to infer the correct context window from the underlying model vendor in the OpenRouter model path:

Pattern Context Window
google/gemini-* 1,048,576
anthropic/claude-* 200,000
openai/gpt-4o* 128,000
openai/o[134]* 200,000
meta-llama/llama-3* 131,072
deepseek/* 65,536
mistralai/* 131,072
qwen/* 131,072

Test plan

  • 567 tests pass (3 new regression tests added)
  • ESLint + TypeScript type check pass
  • openrouter:google/gemini-3.1-pro-preview → 1,048,576 tokens ✅
  • openrouter:anthropic/claude-99 → 200,000 tokens ✅
  • openrouter:deepseek/deepseek-r2 → 65,536 tokens ✅

Fixes #86

🤖 Generated with Claude Code

When users specify models like `openrouter:google/gemini-3.1-pro-preview`,
the fallback system was using OpenRouter's generic 128K default instead of
Gemini's actual 1,048,576 token context window.

Added pattern-matching in getEnhancedModelMapping() fallback to infer the
correct context window from the underlying model vendor name:
- google/gemini-* → 1,048,576 tokens
- anthropic/claude-* → 200,000 tokens
- openai/gpt-4o* → 128,000 tokens
- openai/o[134]* → 200,000 tokens
- meta-llama/llama-3* → 131,072 tokens
- deepseek/* → 65,536 tokens
- mistralai/* → 131,072 tokens
- qwen/* → 131,072 tokens

Added 3 regression tests for OpenRouter context inference.

Fixes #86

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bobmatnyc bobmatnyc merged commit 118a6e7 into main Feb 22, 2026
4 of 5 checks passed
@bobmatnyc bobmatnyc deleted the fix/issue-86-openrouter-context-window branch February 22, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: context limit for Gemini incorrectly reported

1 participant