Skip to content

fix(cost-map): lower openai chat-latest max_input_tokens to the 272000 the API enforces - #54260

Merged
kerry-berri merged 1 commit into
mainfrom
litellm-providers/price-sync-openai
Nov 24, 2026
Merged

kerry-berri merged 1 commit into
mainfrom
litellm-providers/price-sync-openai

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

OpenAI refuses chat-latest prompts above 272000 input tokens but our cost map said 400000. This sets the row to the limit the model page states and the API enforces.

Details

Link to Devin session: https://app.devin.ai/sessions/fbee90f9dcb145e98d41754319056a24
Open in Devin Desktop: https://app.devin.ai/desktop/session/fbee90f9dcb145e98d41754319056a24?variant=devin
Requested by: @kerry-berri

TLDR

Problem this solves:

  • chat-latest advertises a 400000 token input limit
  • OpenAI rejects chat-latest prompts above 272000 tokens

How it solves it:

  • Sets max_input_tokens to 272000 on chat-latest
  • No other field or row changes, both cost map files stay identical

User Flow

Before: a developer reading the limit of chat-latest from the proxy is told a prompt size that OpenAI refuses

  1. They send GET https://litellm-domain/v1/model/info and read max_input_tokens: 400000 for chat-latest
  2. They send POST https://litellm-domain/v1/chat/completions with model chat-latest and a prompt of about 280000 tokens
  3. OpenAI answers 400 with "Input tokens exceed the configured limit of 272000 tokens"

After: the limit the proxy reports is the one OpenAI enforces

  1. They send GET https://litellm-domain/v1/model/info and read max_input_tokens: 272000 for chat-latest
  2. They keep prompts at or under 272000 tokens and the request is accepted

Rows changed

One row, kind page, applied under ruling openai-chat-latest-max-input-272000 (recorded 2026-11-24 by the cost tracking bot from live API evidence, not by a human)

Key Field Before After Evidence
chat-latest max_input_tokens 400000 272000 https://developers.openai.com/api/docs/models/chat-latest.md fetched raw on 2026-11-24 states "400,000 context window", "Maximum input tokens: 272,000" and "128,000 max output tokens"

The ruling also quotes the API itself. A chat-latest call on /v1/chat/completions returned "Input tokens exceed the configured limit of 272000 tokens. Your messages resulted in 280007 tokens" (request req_d5517510b8d84e5e8a1f446c81364384), and on /v1/responses an input of 271125 tokens returned 200 while about 272040 tokens returned context_length_exceeded. Those calls were made by the ruling's author and were not repeated in this PR

max_output_tokens stays 128000, and the ruling covers only the bare openai chat-latest key, so azure and chatgpt rows are untouched

ChatGPT subscription rows

https://developers.openai.com/codex/models changed in markup only. Its codex -m ids are still gpt-6-astra, gpt-6-luna, gpt-6.1-sol, gpt-6.1-terra, gpt-6.2-astra and gpt-6.2-sol, each already has a chatgpt/ row, and the three dated ChatGPT sign-in retirements on the page (gpt-5.4 on 2026-08-31, gpt-5.3-codex-spark on 2026-09-14, gpt-5.5 on 2026-10-14) are already on their rows

Delisted by the provider

Ids missing from the list API with no date in the catalog and no mention on https://developers.openai.com/api/docs/deprecations, left for a human: daybreak-blue-latest, daybreak-red-latest, gpt-daybreak-blue-latest, gpt-daybreak-red-latest, gpt-4o-mini-search-preview, gpt-4o-search-preview, gpt-5.5-cyber, gpt-5.6, gpt-5.6-cyber, gpt-6-cyber, gpt-6-rosalind, gpt-rosalind-discovery, gpt-rosalind-research, omni-moderation-csam-latest. gpt-6-astra-law and gpt-6.2-astra-law were added from the pricing page before the list API carried them (ruling openai-gpt-6-astra-law-add-from-pricing-page). The other delisted ids in the diff already carry a deprecation_date

Coverage gaps and not delistings: openai/container (container pricing pseudo key) and text-embedding-ada-002-v2 (alias of text-embedding-ada-002)

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Before and after through a live proxy with a real OpenAI key on 2026-11-24. The before proxy ran at the merge base e35ef28 and the after proxy at 664a18c, each from its own checkout with its own Rust extension built by maturin build --release, because the bundled cost map is compiled into the extension. Both ran one worker with no Redis and no database, since the change is a single catalog value read at startup. Before the fix the proxy reports 400000, passes a 360010 token prompt to OpenAI and OpenAI refuses it at 272000. After the fix the proxy reports 272000 and the router pre-call check refuses the same prompt before it is sent

== openai before, proxy at e35ef280
GET /v1/model/info 200 chat-latest max_input_tokens = 400000
POST /v1/chat/completions 400 {"error":{"message":"litellm.ContextWindowExceededError: litellm.BadRequestError: ContextWindowExceededError: OpenAIException - Input tokens exceed the configured limit of 272000 tokens. Your messages resulted in 360010 tokens. Please reduce the length of the messages.\nmodel=chat-latest. context_wi
== openai after, proxy at 664a18cd
GET /v1/model/info 200 chat-latest max_input_tokens = 272000
POST /v1/chat/completions 400 {"error":{"message":"litellm.ContextWindowExceededError: litellm.BadRequestError: litellm._pre_call_checks: Context Window exceeded for given call. No models have context window large enough for this call.\nModel=openai/chat-latest, Max Input Tokens=272000, Got=360977\nmodel=chat-latest. context_win
Proxy command, config and client
export LITELLM_LOCAL_MODEL_COST_MAP=True LITELLM_DANGEROUSLY_PERMIT_WEAK_OR_UNSET_MASTER_KEY=true OPENAI_API_KEY=...
env -u DATABASE_URL SQLX_OFFLINE=true uvx maturin==1.15.0 build --release -i .venv/bin/python -o wheels
PYTHONPATH=$PWD python litellm/proxy/proxy_cli.py --config config.yaml --port 4103   # 4104 for the after checkout
python3 client.py http://localhost:4103 chat-latest

config.yaml

model_list:
  - model_name: hy4-flash
    litellm_params:
      model: fireworks_ai/accounts/fireworks/models/hy4-flash
      api_key: os.environ/FIREWORKS_AI_API_KEY
  - model_name: chat-latest
    litellm_params:
      model: openai/chat-latest
      api_key: os.environ/OPENAI_API_KEY
router_settings:
  enable_pre_call_checks: true
general_settings:
  master_key: sk-1234

client.py

import json, sys, urllib.request
base, model = sys.argv[1], sys.argv[2]
def call(path, body=None):
    req = urllib.request.Request(base + path, data=json.dumps(body).encode() if body else None,
                                 headers={"Authorization": "Bearer sk-1234", "Content-Type": "application/json"})
    try:
        r = urllib.request.urlopen(req, timeout=900)
        return r.status, json.loads(r.read())
    except urllib.error.HTTPError as e:
        return e.code, e.read().decode()[:500]
s, r = call("/v1/model/info")
row = [m for m in r["data"] if m["model_name"] == model][0]
print("GET /v1/model/info", s, model, "max_input_tokens =", row["model_info"]["max_input_tokens"])
prompt = "hello world foo bar baz qux. " * 45000 + " Reply OK."
s, r = call("/v1/chat/completions", {"model": model, "max_tokens": 16, "messages": [{"role": "user", "content": prompt}]})
print("POST /v1/chat/completions", s, r["usage"] if isinstance(r, dict) else r)

The focused checks at the tip also pass

$ cmp model_prices_and_context_window.json litellm/model_prices_and_context_window_backup.json && echo identical
identical
$ LITELLM_LOCAL_MODEL_COST_MAP=True .venv/bin/python -m pytest tests/unit/test_model_prices_and_context_window.py tests/unit/test_cost_map_guard.py -q -p no:cacheprovider
269 passed, 9 warnings in 12.51s

Type

🐛 Bug Fix

Caveats (if any)

Low

  • With enable_pre_call_checks on, a chat-latest prompt between 272000 and 400000 tokens is now refused by the router and no longer by OpenAI. The status is 400 either way

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@veria-ai

veria-ai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri

Copy link
Copy Markdown
Contributor

bugbot run

@greptile-apps

greptile-apps Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge, with no new actionable issues found.

Summary

Corrects chat-latest’s reported input limit from 400000 to 272000 tokens in both cost-map copies.

  • The chat-latest input limit now matches OpenAI's 272000-token maximum.

Reviews (2) · Last reviewed commit: "fix(cost-map): lower openai chat-latest ..." · Reviewed by Greptile

Comment thread model_prices_and_context_window.json Resolved

@cursor cursor Bot 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 664a18c. Configure here.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai

1 similar comment
@kerry-berri

Copy link
Copy Markdown
Contributor

@greptileai

@kerry-berri
kerry-berri merged commit 504a0c2 into main Nov 24, 2026
60 of 61 checks passed
@kerry-berri
kerry-berri deleted the litellm-providers/price-sync-openai branch November 24, 2026 23:26
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.

2 participants