From 7715c57912bc84a358f23c89923834e5d5476c3b Mon Sep 17 00:00:00 2001 From: John Costa Date: Wed, 11 Mar 2026 21:24:01 -0700 Subject: [PATCH 1/2] Map context_length for OpenRouter models 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 #2347 --- .../ai/chat/providers/OpenRouterProvider/OpenRouterProvider.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/src/services/ai/chat/providers/OpenRouterProvider/OpenRouterProvider.ts b/src/backend/src/services/ai/chat/providers/OpenRouterProvider/OpenRouterProvider.ts index b12ed90a76..57685c822b 100644 --- a/src/backend/src/services/ai/chat/providers/OpenRouterProvider/OpenRouterProvider.ts +++ b/src/backend/src/services/ai/chat/providers/OpenRouterProvider/OpenRouterProvider.ts @@ -186,6 +186,7 @@ export class OpenRouterProvider implements IChatProvider { id: `openrouter:${model.id}`, name: `${model.name} (OpenRouter)`, aliases: [model.id, model.name, `openrouter/${model.id}`, model.id.split('/').slice(1).join('/')], + context: model.context_length, max_tokens: model.top_provider.max_completion_tokens, costs_currency: 'usd-cents', input_cost_key: 'prompt', From 2a1ad7cb5d9fd6568add1c351e9f9778b234aeb8 Mon Sep 17 00:00:00 2001 From: John Costa Date: Thu, 12 Mar 2026 12:02:25 -0700 Subject: [PATCH 2/2] Add context field to MistralAI and OpenAI model definitions 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) --- .../providers/MistralAiProvider/models.ts | 16 ++++++++++ .../chat/providers/OpenAiProvider/models.ts | 29 ++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/backend/src/services/ai/chat/providers/MistralAiProvider/models.ts b/src/backend/src/services/ai/chat/providers/MistralAiProvider/models.ts index 279bdcbed1..a0929edb9b 100644 --- a/src/backend/src/services/ai/chat/providers/MistralAiProvider/models.ts +++ b/src/backend/src/services/ai/chat/providers/MistralAiProvider/models.ts @@ -16,6 +16,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'mistral-medium', 'mistralai/mistral-medium-2508', ], + context: 131072, max_tokens: 131072, description: 'Update on Mistral Medium 3 with improved capabilities.', provider: 'mistral', @@ -42,6 +43,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'mistral-tiny-2312', 'mistralai/open-mistral-7b', ], + context: 32768, max_tokens: 32768, description: 'Our first dense model released September 2023.', provider: 'mistral', @@ -69,6 +71,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'mistral-tiny-latest', 'mistralai/open-mistral-nemo', ], + context: 131072, max_tokens: 131072, description: 'Our best multilingual open source model released July 2024.', provider: 'mistral', @@ -95,6 +98,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'mistral-large-pixtral-2411', 'mistralai/pixtral-large-2411', ], + context: 131072, max_tokens: 131072, description: 'Official pixtral-large-2411 Mistral AI model', provider: 'mistral', @@ -120,6 +124,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'codestral-latest', 'mistralai/codestral-2508', ], + context: 256000, max_tokens: 256000, description: 'Our cutting-edge language model for coding released August 2025.', provider: 'mistral', @@ -145,6 +150,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'devstral-small-latest', 'mistralai/devstral-small-2507', ], + context: 131072, max_tokens: 131072, description: 'Our small open-source code-agentic model.', provider: 'mistral', @@ -171,6 +177,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'devstral-medium-latest', 'mistralai/devstral-medium-2507', ], + context: 131072, max_tokens: 131072, description: 'Our medium code-agentic model.', provider: 'mistral', @@ -197,6 +204,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'mistral-small-latest', 'mistralai/mistral-small-2506', ], + context: 131072, max_tokens: 131072, description: 'Our latest enterprise-grade small model with the latest version released June 2025.', provider: 'mistral', @@ -222,6 +230,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'magistral-medium-latest', 'mistralai/magistral-medium-2509', ], + context: 131072, max_tokens: 131072, description: 'Our frontier-class reasoning model release candidate September 2025.', provider: 'mistral', @@ -247,6 +256,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'magistral-small-latest', 'mistralai/magistral-small-2509', ], + context: 131072, max_tokens: 131072, description: 'Our efficient reasoning model released September 2025.', provider: 'mistral', @@ -267,6 +277,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'voxtral-mini-latest', 'mistralai/voxtral-mini-2507', ], + context: 32768, max_tokens: 32768, description: 'A mini audio understanding model released in July 2025', provider: 'mistral', @@ -287,6 +298,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'voxtral-small-latest', 'mistralai/voxtral-small-2507', ], + context: 32768, max_tokens: 32768, description: 'A small audio understanding model released in July 2025', provider: 'mistral', @@ -312,6 +324,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'mistral-large-2512', 'mistralai/mistral-large-2512', ], + context: 262144, max_tokens: 262144, description: 'Official mistral-large-2512 Mistral AI model', provider: 'mistral', @@ -337,6 +350,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'ministral-3b-latest', 'mistralai/ministral-3b-2512', ], + context: 131072, max_tokens: 131072, description: 'Ministral 3 (a.k.a. Tinystral) 3B Instruct.', provider: 'mistral', @@ -362,6 +376,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'ministral-8b-latest', 'mistralai/ministral-8b-2512', ], + context: 262144, max_tokens: 262144, description: 'Ministral 3 (a.k.a. Tinystral) 8B Instruct.', provider: 'mistral', @@ -382,6 +397,7 @@ export const MISTRAL_MODELS: IChatModel[] = [ 'ministral-14b-latest', 'mistralai/ministral-14b-2512', ], + context: 262144, max_tokens: 262144, description: 'Ministral 3 (a.k.a. Tinystral) 14B Instruct.', provider: 'mistral', diff --git a/src/backend/src/services/ai/chat/providers/OpenAiProvider/models.ts b/src/backend/src/services/ai/chat/providers/OpenAiProvider/models.ts index f64a4b71aa..227cc65f71 100644 --- a/src/backend/src/services/ai/chat/providers/OpenAiProvider/models.ts +++ b/src/backend/src/services/ai/chat/providers/OpenAiProvider/models.ts @@ -22,7 +22,8 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 25, completion_tokens: 1500, }, - max_tokens: 1_050_000, // this is used for context length calculations so its misnamed from when OpenAI max_tokens and content_length were the same value + context: 1_050_000, + max_tokens: 1_050_000, }, { puterId: 'openai:openai/gpt-5.3-codex', @@ -41,6 +42,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 17.5, completion_tokens: 1400, }, + context: 128_000, max_tokens: 128000, responses_api_only: true, }, @@ -62,6 +64,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 18, completion_tokens: 1400, }, + context: 128_000, max_tokens: 128000, responses_api_only: true, }, @@ -83,6 +86,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 17.5, completion_tokens: 1400, }, + context: 128_000, max_tokens: 16384, }, { @@ -102,6 +106,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ prompt_tokens: 2100, completion_tokens: 16800, }, + context: 128_000, max_tokens: 16384, responses_api_only: true, }, @@ -123,6 +128,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 17.5, completion_tokens: 1400, }, + context: 128_000, max_tokens: 128000, }, { @@ -143,6 +149,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 13, completion_tokens: 1000, }, + context: 128_000, max_tokens: 128000, }, { @@ -163,6 +170,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 13, completion_tokens: 1000, }, + context: 128_000, max_tokens: 128000, responses_api_only: true, }, @@ -184,6 +192,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 3, completion_tokens: 200, }, + context: 128_000, max_tokens: 128000, responses_api_only: true, }, @@ -205,6 +214,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 13, completion_tokens: 1000, }, + context: 128_000, max_tokens: 16384, }, { @@ -225,6 +235,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 13, completion_tokens: 1000, }, + context: 128_000, max_tokens: 128000, }, { @@ -245,6 +256,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 3, completion_tokens: 200, }, + context: 128_000, max_tokens: 128000, }, { @@ -265,6 +277,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 1, completion_tokens: 40, }, + context: 128_000, max_tokens: 128000, }, { @@ -285,6 +298,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 13, completion_tokens: 1000, }, + context: 128_000, max_tokens: 16384, }, { @@ -305,6 +319,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 125, completion_tokens: 1000, }, + context: 128_000, max_tokens: 16384, }, { @@ -316,6 +331,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ knowledge: '2023-09', release_date: '2024-07-18', aliases: ['openai/gpt-4o-mini'], + context: 128_000, max_tokens: 16384, costs_currency: 'usd-cents', input_cost_key: 'prompt_tokens', @@ -345,6 +361,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 750, completion_tokens: 6000, }, + context: 200_000, max_tokens: 100000, }, { @@ -364,6 +381,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ prompt_tokens: 110, completion_tokens: 440, }, + context: 128_000, max_tokens: 65536, }, { @@ -383,6 +401,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ prompt_tokens: 15000, completion_tokens: 60000, }, + context: 200_000, max_tokens: 100000, }, { @@ -403,6 +422,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 50, completion_tokens: 800, }, + context: 200_000, max_tokens: 100000, }, { @@ -423,6 +443,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 50, completion_tokens: 8000, }, + context: 200_000, max_tokens: 100000, responses_api_only: true, }, @@ -444,6 +465,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 55, completion_tokens: 440, }, + context: 200_000, max_tokens: 100000, }, { @@ -463,6 +485,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ prompt_tokens: 110, completion_tokens: 440, }, + context: 200_000, max_tokens: 100000, }, { @@ -483,6 +506,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 50, completion_tokens: 800, }, + context: 1_047_576, max_tokens: 32768, }, { @@ -503,6 +527,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 10, completion_tokens: 160, }, + context: 1_047_576, max_tokens: 32768, }, { @@ -523,6 +548,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ cached_tokens: 2, completion_tokens: 40, }, + context: 1_047_576, max_tokens: 32768, }, { @@ -537,6 +563,7 @@ export const OPEN_AI_MODELS: IChatModel[] = [ prompt_tokens: 7500, completion_tokens: 15000, }, + context: 128_000, max_tokens: 32768, }, ];