Skip to content

Add context field to OpenRouter, MistralAI, and OpenAI models#2653

Open
costajohnt wants to merge 2 commits intoHeyPuter:mainfrom
costajohnt:fix/openrouter-context-window
Open

Add context field to OpenRouter, MistralAI, and OpenAI models#2653
costajohnt wants to merge 2 commits intoHeyPuter:mainfrom
costajohnt:fix/openrouter-context-window

Conversation

@costajohnt
Copy link
Copy Markdown

@costajohnt costajohnt commented Mar 12, 2026

Summary

  • Map context_length from OpenRouter's API response to the context field in the model list, matching the pattern used by all other providers
  • Add context field to all 16 MistralAI hardcoded model definitions
  • Add context field to all 27 OpenAI hardcoded model definitions

All 9 providers now consistently expose context window sizes via the context field.

Context values by provider family:

  • MistralAI: 32k–262k depending on model (matches documented context windows)
  • OpenAI GPT series: 128k (GPT-4o, GPT-5.x)
  • OpenAI o-series: 128k (o1-mini) or 200k (o1, o3, o4-mini)
  • OpenAI GPT-4.1: 1,047,576
  • OpenAI GPT-5.4: 1,050,000

Closes #2347

Test plan

  • Verify OpenRouter models include context in the model list API response
  • Verify MistralAI models include context field
  • Verify OpenAI models include context field
  • Confirm no regressions for other providers (Claude, DeepSeek, Gemini, Groq, TogetherAI, XAI already had context)

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 12, 2026

CLA assistant check
All committers have signed the CLA.

@costajohnt costajohnt marked this pull request as ready for review March 12, 2026 04:25
@ProgrammerIn-wonderland
Copy link
Copy Markdown
Collaborator

we should probably support this "context" field in more models too

@costajohnt costajohnt changed the title Map context_length for OpenRouter models Add context field to OpenRouter, MistralAI, and OpenAI models Mar 12, 2026
Copy link
Copy Markdown

@codeCraft-Ritik codeCraft-Ritik left a comment

Choose a reason for hiding this comment

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

Great work! The implementation is clean and easy to understand.

OpenRouter's API returns context_length for each model, but it was not
being mapped to the context field in the model list response. This
caused the context window size to be missing for all OpenRouter models.

Closes HeyPuter#2347
Addresses reviewer feedback to support the context field in more
providers. All 9 providers now consistently expose context window
sizes via the context field.

- MistralAI: 16 models (context matches known window sizes)
- OpenAI: 27 models (128k for GPT series, 200k for o-series,
  1M+ for GPT-4.1 and GPT-5.4)
@costajohnt costajohnt force-pushed the fix/openrouter-context-window branch from 4311c4c to 2a1ad7c Compare March 21, 2026 19:21
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.

Missing context window data for openrouter models

4 participants