Skip to content

fix(llm): correct gpt-4o-mini context window 200000 -> 128000 - #7294

Merged
Vidit-Ostwal merged 1 commit into
crewAIInc:mainfrom
Shxiao101:fix/gpt-4o-mini-context-window
Sep 7, 2026
Merged

fix(llm): correct gpt-4o-mini context window 200000 -> 128000#7294
Vidit-Ostwal merged 1 commit into
crewAIInc:mainfrom
Shxiao101:fix/gpt-4o-mini-context-window

Conversation

@Shxiao101

Copy link
Copy Markdown
Contributor

Related issue

Fixes #7293

Summary

gpt-4o-mini's official context window is 128,000 tokens (OpenAI announcement and API docs); litellm's own model database also reports max_input_tokens = 128000. The shared LLM_CONTEXT_WINDOW_SIZES table and the OpenAI/Azure provider-local tables list 200000 — apparently copied from the neighboring o3-mini / o4-mini entries (both 200000). The same tables list gpt-4o as 128000, so the smaller mini having a larger window is internally inconsistent.

Because get_context_window_size() applies CONTEXT_WINDOW_USAGE_RATIO = 0.85, crews using gpt-4o-mini resolved their usable window to 170000 instead of 108800 on all three provider paths (the litellm-path lookup in llm.py iterates without break, so gpt-4o-mini resolves to its own entry), letting conversation history grow past the model's real 128k limit and failing with API 400s on long-running crews.

This changes only the gpt-4o-mini value in three places — no key additions, removals, or reordering, so lookups for any other model are unaffected.

Note for review: open PR #6603 (longest-prefix matching) adds a test asserting gpt-4o-mini == 200000; if it merges first, its assertion needs the same correction.

Verification

  • Tests added or updated for the changed behavior → covered by the existing context-window tests (pytest lib/crewai/tests/test_llm.py -k context_window, 10 passed); happy to add a dedicated gpt-4o-mini regression test if preferred
  • Relevant tests and quality checks pass locally

Local checks:

import os
os.environ.setdefault("OPENAI_API_KEY", "test-key")
from crewai.llm import LLM

LLM(model="gpt-4o-mini", is_litellm=True).get_context_window_size()  # 170000 -> 108800
LLM(model="openai/gpt-4o-mini").get_context_window_size()            # 170000 -> 108800
  • uv run ruff check <changed files> and uv run ruff format --check <changed files>: clean
  • pytest lib/crewai/tests/test_llm.py -q: 89 passed, 3 skipped (2 pre-existing environment errors on Windows, reproduced on unmodified main)
  • Full-repo scan confirms the three changed entries are the only gpt-4o-mini window-size occurrences

Additional context

gpt-4o-mini's official context window is 128,000 tokens (OpenAI
announcement and API docs; litellm's model database agrees), but the
shared LLM_CONTEXT_WINDOW_SIZES table and the OpenAI/Azure provider-local
tables listed 200000 - apparently copied from the neighboring o3-mini /
o4-mini entries. With CONTEXT_WINDOW_USAGE_RATIO = 0.85, crews resolved
the usable window to 170000 instead of 108800, letting history grow past
the model's real 128k limit and failing with API 400s on long runs.

Fixes crewAIInc#7293
@coderabbitai

coderabbitai Bot commented Sep 6, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 67e22152-647b-4ea7-9696-7ebcf8b4917e

📥 Commits

Reviewing files that changed from the base of the PR and between 143e902 and 9478f42.

📒 Files selected for processing (3)
  • lib/crewai/src/crewai/llm.py
  • lib/crewai/src/crewai/llms/providers/azure/completion.py
  • lib/crewai/src/crewai/llms/providers/openai/completion.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

The change corrects the gpt-4o-mini context-window value from 200000 to 128000 in the shared LLM mapping and the OpenAI and Azure provider mappings.

Changes

Context window correction

Layer / File(s) Summary
Update context-window mappings
lib/crewai/src/crewai/llm.py, lib/crewai/src/crewai/llms/providers/openai/completion.py, lib/crewai/src/crewai/llms/providers/azure/completion.py
The gpt-4o-mini context-window value is changed from 200000 to 128000 in all three mappings. The OpenAI provider applies the usage ratio to the corrected value.

Suggested reviewers: lorenzejay, joaomdmoura

Merge Risk: ⚪ Minimal · up to 9478f

This corrects the gpt-4o-mini context limit across shared, OpenAI, and Azure paths, preventing oversized histories from exceeding the model limit. The change is ready to merge.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the correction to the gpt-4o-mini context window.
Description check ✅ Passed The description includes the related issue, problem rationale, affected paths, verification results, test status, and additional context.
Linked Issues check ✅ Passed The changes satisfy issue #7293 by updating gpt-4o-mini from 200000 to 128000 in the shared, OpenAI, and Azure tables. The expected resolved window is 108800.
Out of Scope Changes check ✅ Passed All changes are limited to the three context-window entries required by issue #7293. No unrelated code changes are reported.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Vidit-Ostwal Vidit-Ostwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approved. Official OpenAI docs list gpt-4o-mini at 128,000 context tokens (and 16,384 max output). The previous 200000 matches Tier 1 TPM, not the context window. The three table updates (LiteLLM, native OpenAI, Azure) are the right places and leave other model lookups alone.

@Vidit-Ostwal

Copy link
Copy Markdown
Contributor

Thanks for things, cheers

@Vidit-Ostwal
Vidit-Ostwal merged commit 7fe8317 into crewAIInc:main Sep 7, 2026
54 checks passed
@Shxiao101
Shxiao101 deleted the fix/gpt-4o-mini-context-window branch September 7, 2026 12:20
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] gpt-4o-mini context window is set to 200000 instead of the official 128000

2 participants