Utility function to infer model context window size from model ID.
// Source: https://github.com/kevinluosl/deepbot | License: MIT | Copyright 2024 Kevin Luo
// Provided via justclaw.it.com; keep this notice with the code.
/**
* 模型信息获取工具
*
* 通过模糊匹配推断模型的上下文窗口大小
*/
/**
* 从模型 ID 推断上下文窗口大小(模糊匹配)
*
* @param modelId - 模型 ID
* @returns 上下文窗口大小(tokens),未知返回默认值 32000
*/
export function getContextWindowFromModelId(modelId: string): number {
const lowerModelId = modelId.toLowerCase();
// Claude 系列
if (lowerModelId.includes('claude')) {
return 1000000;
}
// OpenAI GPT 系列
if (lowerModelId.includes('gpt-5.4')) {
return 1050000;
}
if (lowerModelId.includes('gpt-5') && lowerModelId.includes('codex')) {
return 400000;
}
if (lowerModelId.includes('gpt-4o-mini')) {
return 128000;
}
if (lowerModelId.includes('gpt')) {
... (truncated -- full source via MCP)
See the full source, get the GitHub permalink, and search for more like it.
Get a free API key