Skip to content

fix(vertex_ai): resolve correct default max_tokens for versioned claude ids - #40376

Merged
mateo-berri merged 11 commits into
BerriAI:mainfrom
hktitof:fix-vertex-claude-max-tokens
Nov 14, 2026
Merged

mateo-berri merged 11 commits into
BerriAI:mainfrom
hktitof:fix-vertex-claude-max-tokens

Conversation

@hktitof

@hktitof hktitof commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

TLDR

Problem this solves:

How it solves it:

  • The missing max_tokens fill tries the model's own row first, as before
  • A Vertex @version id then reads the row of its id without the version, e.g. claude-haiku-4-5
  • Then it reads the serving provider's row, e.g. vertex_ai/claude-3-5-haiku@20241022
  • Only then does it fall back to DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS, 128000 unless set
  • A deployment model_info.max_output_tokens or a global AnthropicConfig(max_tokens=...) still wins
  • Bedrock Invoke now reuses the same row lookup instead of its own copy

User Flow

Before: a LibreChat user on a Vertex Claude Haiku 4.5 deployment gets a 400

  1. The proxy admin adds a deployment with model: vertex_ai/claude-haiku-4-5@20251001
  2. A LibreChat user adds a custom endpoint with baseURL: https://litellm-domain/v1, picks that model, and sends a message
  3. LibreChat sends POST https://litellm-domain/v1/chat/completions with no max_tokens
  4. LibreChat shows "The model provider could not complete this request (status 400)" with max_tokens: 128000 > 64000, which is the maximum allowed number of output tokens for claude-haiku-4-5-20251001

After: the same message gets the model's reply

  1. The proxy admin keeps the same deployment
  2. The LibreChat user sends the same message through the same custom endpoint
  3. LibreChat shows the model's reply, since the request now carries the model's 64000 cap

Relevant issues

Fixes #40363

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/llms/vertex_ai/vertex_ai_partner_models/anthropic/test_vertex_ai_partner_models_anthropic_transformation.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

Last updated: 0cb8559, a clean merge of main's d8e8621 so the required lint job finds a script main moved. QA ran on 6046f5b, and the LibreChat long-reply case with the env var at 4096 ran on 3570922. Changes since QA: 53d146b moved an explicit DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS ahead of the new rows and 8fdc906 reverted it, then 3570922 reads the unversioned row straight from the cost map and adds route tests, 054e585 is empty, and 0cb8559 merges main. Proof remains valid because that read returns the same row without printing the provider banner a second time, and the merge leaves this PR's changed lines identical and changes no max_tokens line or Claude cap. Verification: over 4585 Claude id and provider pairs, max_tokens is the same before and after 3570922 with the env var unset and at 4096, 7398 focused unit tests pass, and the 885 tests in the two changed test files pass at 0cb8559

Live Vertex AI calls, no mocks. Two proxies with 2 workers each, one booted from the merge base 83c4706 and one from the PR tip 6046f5b, same config, no database. The reporter's client, LibreChat v0.8.8, talks to both through one custom endpoint per proxy and sends no max_tokens. The OpenAI Python SDK cases and a max_tokens probe through /utils/transform_request run against the same proxies

Case Before After
LibreChat, Haiku 4.5 versioned 400 banner replies OK
LibreChat, Opus 4.5 versioned 400 banner replies OK
LibreChat, Sonnet 4.6 @default replies OK replies OK
SDK, Haiku 4.5 versioned, chat 400 200
SDK, Haiku 4.5 versioned, stream 400 200
SDK, Haiku 4.5 versioned, /v1/responses 400 200
SDK, Opus 4.5 versioned, chat 400 200
SDK, Sonnet 4.6 @default, chat 200 200
SDK, Sonnet 4.6 bare id, chat 200 200
SDK, Haiku 4.5, explicit max_tokens 50 200 200
max_tokens sent, Haiku 4.5 versioned 128000 64000
max_tokens sent, Sonnet 4.6 @default 128000 128000
max_tokens sent, Haiku 4.5 versioned, env var 4096 4096 64000
Long reply, Haiku 4.5 versioned, env var 4096 cut at 4096, length 6142 tokens, stop
LibreChat long reply, Haiku 4.5 versioned, env var 4096 cut mid-sentence, 3193 words whole story, 5089 words
Setup: config.yaml, proxy start, client

Env var names only: VERTEXAI_PROJECT, GOOGLE_APPLICATION_CREDENTIALS, LITELLM_MASTER_KEY, plus LITELLM_LOCAL_MODEL_COST_MAP=True and PYTHON_DOTENV_DISABLED=1 so each tree reads its own cost map and no .env

qa-config.yaml

model_list:
  - model_name: vertex-claude-haiku-4-5-versioned
    litellm_params:
      model: vertex_ai/claude-haiku-4-5@20251001
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
  - model_name: vertex-claude-opus-4-5-versioned
    litellm_params:
      model: vertex_ai/claude-opus-4-5@20251101
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
  - model_name: vertex-claude-sonnet-4-6
    litellm_params:
      model: vertex_ai/claude-sonnet-4-6
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
  - model_name: vertex-claude-sonnet-4-6-default
    litellm_params:
      model: vertex_ai/claude-sonnet-4-6@default
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

boot_leg.sh <tree> <port>, run once per tree

#!/bin/zsh
set -eu
tree=$1
port=$2
W=/private/tmp/claude-501/-Users-mateo-Development-litellm/b517416e-2153-4049-9115-09daf22edcf2/scratchpad/work-37eabb66
H=$HOME/Development/litellm-worktrees/work-37eabb66-head
unset DATABASE_URL
export PYTHON_DOTENV_DISABLED=1
export LITELLM_LOCAL_MODEL_COST_MAP=True
export VERTEXAI_PROJECT=$(~/.claude/bin/dotenv-get VERTEXAI_PROJECT --file $H/.env)
export GOOGLE_APPLICATION_CREDENTIALS=$(~/.claude/bin/dotenv-get GOOGLE_APPLICATION_CREDENTIALS --file $H/.env)
export LITELLM_MASTER_KEY=$(<$W/qa-master-key)
export PYTHONPATH=$tree
cd $tree
print -r -- "leg tree=$tree HEAD=$(git rev-parse --short HEAD) porcelain_lines=$(git status --porcelain | wc -l) port=$port"
exec $H/.venv/bin/python -m litellm.proxy.proxy_cli --config $W/qa-config.yaml --host 127.0.0.1 --port $port --num_workers 2 --telemetry False

qa_client.py

import sys
from pathlib import Path

from openai import APIStatusError, OpenAI

base_url, key_file, model, mode = sys.argv[1:5]
client = OpenAI(base_url=base_url, api_key=Path(key_file).read_text().strip(), max_retries=0, timeout=300)
prompt = "Reply with the single word OK."
messages = [{"role": "user", "content": prompt}]
try:
    if mode == "chat":
        r = client.chat.completions.create(model=model, messages=messages)
        print(f"200 text={r.choices[0].message.content!r} finish_reason={r.choices[0].finish_reason!r}")
    elif mode == "stream":
        chunks = list(client.chat.completions.create(model=model, messages=messages, stream=True))
        text = "".join(c.choices[0].delta.content or "" for c in chunks if c.choices)
        finish = [c.choices[0].finish_reason for c in chunks if c.choices and c.choices[0].finish_reason]
        print(f"200 stream chunks={len(chunks)} text={text!r} finish_reason={finish[-1] if finish else None!r}")
    elif mode == "responses":
        r = client.responses.create(model=model, input=prompt)
        print(f"200 status={r.status!r} text={r.output_text!r}")
    elif mode == "chat_max_tokens_50":
        r = client.chat.completions.create(model=model, messages=messages, max_tokens=50)
        print(f"200 text={r.choices[0].message.content!r} finish_reason={r.choices[0].finish_reason!r}")
except APIStatusError as e:
    print(f"{e.status_code} {str(e)[:500]}")

run_cases.sh <port>, which prints each command from the same string it runs

#!/bin/zsh
port=$1
W=/private/tmp/claude-501/-Users-mateo-Development-litellm/b517416e-2153-4049-9115-09daf22edcf2/scratchpad/work-37eabb66
cd $W
run() { printf '$ %s\n' "$1"; eval "$1"; echo; }
run "client-venv/bin/python qa_client.py http://127.0.0.1:$port/v1 qa-master-key vertex-claude-haiku-4-5-versioned chat"
run "client-venv/bin/python qa_client.py http://127.0.0.1:$port/v1 qa-master-key vertex-claude-haiku-4-5-versioned stream"
run "client-venv/bin/python qa_client.py http://127.0.0.1:$port/v1 qa-master-key vertex-claude-haiku-4-5-versioned responses"
run "client-venv/bin/python qa_client.py http://127.0.0.1:$port/v1 qa-master-key vertex-claude-opus-4-5-versioned chat"
run "client-venv/bin/python qa_client.py http://127.0.0.1:$port/v1 qa-master-key vertex-claude-sonnet-4-6-default chat"
run "client-venv/bin/python qa_client.py http://127.0.0.1:$port/v1 qa-master-key vertex-claude-sonnet-4-6 chat"
run "client-venv/bin/python qa_client.py http://127.0.0.1:$port/v1 qa-master-key vertex-claude-haiku-4-5-versioned chat_max_tokens_50"
Setup: LibreChat v0.8.8 with one custom endpoint per proxy

LibreChat runs from its release image registry.librechat.ai/librechat-ai/librechat:v0.8.8 with mongo:8.0.20, both on the host network. The env file sets MONGO_URI, CREDS_KEY, CREDS_IV, JWT_SECRET, JWT_REFRESH_SECRET, ALLOW_REGISTRATION=true, ALLOW_UNVERIFIED_EMAIL_LOGIN=true, ENDPOINTS=custom, and LITELLM_KEY (the proxy master key). A QA user registers through POST /api/auth/register

docker run -d --name lc-mongo --network host mongo:8.0.20 mongod --noauth --bind_ip 127.0.0.1 --port <mongo port>
docker run -d --name lc-app --network host --env-file lc.env -v $PWD/librechat.yaml:/app/librechat.yaml:ro registry.librechat.ai/librechat-ai/librechat:v0.8.8

librechat.yaml, with no max_tokens anywhere, as in the issue

version: 1.3.17
cache: true
endpoints:
  custom:
    - name: "LiteLLM base 83c47061e1"
      apiKey: "${LITELLM_KEY}"
      baseURL: "http://127.0.0.1:<base port>/v1"
      models:
        default:
          - vertex-claude-haiku-4-5-versioned
          - vertex-claude-opus-4-5-versioned
          - vertex-claude-sonnet-4-6-default
        fetch: false
      titleConvo: false
      modelDisplayLabel: "LiteLLM base 83c47061e1"
    - name: "LiteLLM head 6046f5bc9c"
      apiKey: "${LITELLM_KEY}"
      baseURL: "http://127.0.0.1:<head port>/v1"
      models:
        default:
          - vertex-claude-haiku-4-5-versioned
          - vertex-claude-opus-4-5-versioned
          - vertex-claude-sonnet-4-6-default
        fetch: false
      titleConvo: false
      modelDisplayLabel: "LiteLLM head 6046f5bc9c"

drive_chat.py signs in, opens a new chat on the named endpoint and model, sends one message, and screenshots the reply. It is the Playwright script used for every LibreChat case

import sys
import urllib.parse
from pathlib import Path

from playwright.sync_api import sync_playwright

base_url, email, password_file, endpoint, model, out_png = sys.argv[1:7]
password = Path(password_file).read_text().strip()
prompt = "Reply with the single word OK."

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page(viewport={"width": 1280, "height": 800})
    page.goto(f"{base_url}/login")
    page.fill("input[name=email]", email)
    page.fill("input[name=password]", password)
    page.click("button[type=submit]")
    page.wait_for_url("**/c/**", timeout=60_000)
    query = urllib.parse.urlencode({"endpoint": endpoint, "model": model})
    page.goto(f"{base_url}/c/new?{query}")
    textarea = page.locator("textarea#prompt-textarea, textarea[data-testid=text-input]").first
    textarea.wait_for(timeout=60_000)
    textarea.fill(prompt)
    textarea.press("Enter")
    page.wait_for_timeout(2_000)
    page.wait_for_function(
        "() => !document.querySelector('[data-testid=stop-generation-button], button[aria-label=\"Stop generating\"]')",
        timeout=180_000,
    )
    page.wait_for_timeout(3_000)
    provider_response = page.get_by_text("Provider response")
    if provider_response.count():
        provider_response.first.click()
        page.wait_for_timeout(1_000)
    page.screenshot(path=out_png)
    messages = page.locator(".message-render, [data-testid=message-text], .markdown").all_inner_texts()
    errors = page.locator("[role=alert], .text-red-500, .text-red-600, .bg-red-500\\/10").all_inner_texts()
    print(f"endpoint={endpoint!r} model={model!r}")
    print(f"assistant_reply={messages[-1].splitlines()[-1] if messages and not errors else None!r}")
    print(f"error_banner={errors[0][:600] if errors else None!r}")
    browser.close()

transform_probe.py asks each proxy's POST /utils/transform_request which max_tokens it would send to Vertex

import json
import sys
import urllib.error
import urllib.request
from pathlib import Path

base_url, key_file, model = sys.argv[1:4]
body = {
    "call_type": "completion",
    "request_body": {"model": model, "messages": [{"role": "user", "content": "Reply with the single word OK."}]},
}
request = urllib.request.Request(
    f"{base_url}/utils/transform_request",
    data=json.dumps(body).encode(),
    headers={"Authorization": f"Bearer {Path(key_file).read_text().strip()}", "Content-Type": "application/json"},
)
try:
    with urllib.request.urlopen(request, timeout=60) as response:
        raw: dict = json.load(response)
        sent = raw.get("raw_request_body") or {}
        print(f"{response.status} max_tokens={sent.get('max_tokens')!r} error={raw.get('error')!r}")
except urllib.error.HTTPError as e:
    print(f"{e.code} {e.read()[:400]!r}")

Before (83c4706)

LibreChat, Haiku 4.5 versioned

  1. Sign in to LibreChat, open a new chat on the LiteLLM base 83c47061e1 endpoint with model vertex-claude-haiku-4-5-versioned, and send "Reply with the single word OK."
$ lc-venv/bin/python librechat/drive_chat.py http://127.0.0.1:21440 qa@example.com librechat/qa-user-password 'LiteLLM base 83c47061e1' vertex-claude-haiku-4-5-versioned shots/librechat-before-haiku.png
endpoint='LiteLLM base 83c47061e1' model='vertex-claude-haiku-4-5-versioned'
assistant_reply=None
error_banner='The model provider could not complete this request (status 400).\nProvider response\n400 litellm.BadRequestError: Vertex_aiException BadRequestError - b\'{"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 128000 > 64000, which is the maximum allowed number of output tokens for claude-haiku-4-5-20251001"},"request_id":"req_vrtx_011CgvkRw9pkscekSmHoAk9V"}\'\n\nLiteLLM: model group \'vertex-claude-haiku-4-5-versioned\' failed with the error above. No fallback was attempted.'

LibreChat on the base proxy shows a 400 for Haiku 4.5

After (6046f5b)

LibreChat, Haiku 4.5 versioned

  1. Sign in to LibreChat, open a new chat on the LiteLLM head 6046f5bc9c endpoint with model vertex-claude-haiku-4-5-versioned, and send "Reply with the single word OK."
$ lc-venv/bin/python librechat/drive_chat.py http://127.0.0.1:21440 qa@example.com librechat/qa-user-password 'LiteLLM head 6046f5bc9c' vertex-claude-haiku-4-5-versioned shots/librechat-after-haiku.png
endpoint='LiteLLM head 6046f5bc9c' model='vertex-claude-haiku-4-5-versioned'
assistant_reply='OK'
error_banner=None

LibreChat on the head proxy shows OK for Haiku 4.5

LibreChat, Opus 4.5 versioned

Before (83c4706)

$ lc-venv/bin/python librechat/drive_chat.py http://127.0.0.1:21440 qa@example.com librechat/qa-user-password 'LiteLLM base 83c47061e1' vertex-claude-opus-4-5-versioned shots/librechat-before-opus.png
endpoint='LiteLLM base 83c47061e1' model='vertex-claude-opus-4-5-versioned'
assistant_reply=None
error_banner='The model provider could not complete this request (status 400).\nProvider response\n400 litellm.BadRequestError: Vertex_aiException BadRequestError - b\'{"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 128000 > 64000, which is the maximum allowed number of output tokens for claude-opus-4-5-20251101"},"request_id":"req_vrtx_011CgvkWTS5x2vGrrhH2EKLJ"}\'\n\nLiteLLM: model group \'vertex-claude-opus-4-5-versioned\' failed with the error above. No fallback was attempted.'

LibreChat on the base proxy shows a 400 for Opus 4.5

After (6046f5b)

$ lc-venv/bin/python librechat/drive_chat.py http://127.0.0.1:21440 qa@example.com librechat/qa-user-password 'LiteLLM head 6046f5bc9c' vertex-claude-opus-4-5-versioned shots/librechat-after-opus.png
endpoint='LiteLLM head 6046f5bc9c' model='vertex-claude-opus-4-5-versioned'
assistant_reply='OK'
error_banner=None

LibreChat on the head proxy shows OK for Opus 4.5

LibreChat, Sonnet 4.6 `@default` control

Before (83c4706)

$ lc-venv/bin/python librechat/drive_chat.py http://127.0.0.1:21440 qa@example.com librechat/qa-user-password 'LiteLLM base 83c47061e1' vertex-claude-sonnet-4-6-default shots/librechat-before-sonnet46-default.png
endpoint='LiteLLM base 83c47061e1' model='vertex-claude-sonnet-4-6-default'
assistant_reply='OK'
error_banner=None

LibreChat on the base proxy shows OK for Sonnet 4.6 default

After (6046f5b)

$ lc-venv/bin/python librechat/drive_chat.py http://127.0.0.1:21440 qa@example.com librechat/qa-user-password 'LiteLLM head 6046f5bc9c' vertex-claude-sonnet-4-6-default shots/librechat-after-sonnet46-default.png
endpoint='LiteLLM head 6046f5bc9c' model='vertex-claude-sonnet-4-6-default'
assistant_reply='OK'
error_banner=None

LibreChat on the head proxy shows OK for Sonnet 4.6 default

SDK, Haiku 4.5 versioned, chat

Before (83c4706)

$ client-venv/bin/python qa_client.py http://127.0.0.1:31963/v1 qa-master-key vertex-claude-haiku-4-5-versioned chat
400 Error code: 400 - litellm.BadRequestError: Vertex_aiException BadRequestError - {"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 128000 > 64000, which is the maximum allowed number of output tokens for claude-haiku-4-5-20251001"},"request_id":"req_vrtx_011Cgvjdeon9nC8vcmNpejJc"}

LiteLLM: model group 'vertex-claude-haiku-4-5-versioned' failed with the error above. No fallback was attempted.

After (6046f5b)

$ client-venv/bin/python qa_client.py http://127.0.0.1:27475/v1 qa-master-key vertex-claude-haiku-4-5-versioned chat
200 text='OK' finish_reason='stop'
SDK, Haiku 4.5 versioned, stream

Before (83c4706)

$ client-venv/bin/python qa_client.py http://127.0.0.1:31963/v1 qa-master-key vertex-claude-haiku-4-5-versioned stream
400 Error code: 400 - litellm.BadRequestError: Vertex_aiException BadRequestError - b'{"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 128000 > 64000, which is the maximum allowed number of output tokens for claude-haiku-4-5-20251001"},"request_id":"req_vrtx_011CgvjeKHZaLkxtoUbLUaug"}'

LiteLLM: model group 'vertex-claude-haiku-4-5-versioned' failed with the error above. No fallback was attempted.

After (6046f5b)

$ client-venv/bin/python qa_client.py http://127.0.0.1:27475/v1 qa-master-key vertex-claude-haiku-4-5-versioned stream
200 stream chunks=2 text='OK' finish_reason='stop'
SDK, Haiku 4.5 versioned, /v1/responses

Before (83c4706)

$ client-venv/bin/python qa_client.py http://127.0.0.1:31963/v1 qa-master-key vertex-claude-haiku-4-5-versioned responses
400 Error code: 400 - litellm.BadRequestError: Vertex_aiException BadRequestError - {"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 128000 > 64000, which is the maximum allowed number of output tokens for claude-haiku-4-5-20251001"},"request_id":"req_vrtx_011CgvjejeGMh3W6kby1CphG"}

LiteLLM: model group 'vertex-claude-haiku-4-5-versioned' failed with the error above. No fallback was attempted.

After (6046f5b)

$ client-venv/bin/python qa_client.py http://127.0.0.1:27475/v1 qa-master-key vertex-claude-haiku-4-5-versioned responses
200 status='completed' text='OK'
SDK, Opus 4.5 versioned, chat

Before (83c4706)

$ client-venv/bin/python qa_client.py http://127.0.0.1:31963/v1 qa-master-key vertex-claude-opus-4-5-versioned chat
400 Error code: 400 - litellm.BadRequestError: Vertex_aiException BadRequestError - {"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: 128000 > 64000, which is the maximum allowed number of output tokens for claude-opus-4-5-20251101"},"request_id":"req_vrtx_011CgvjfZtv7LQPjDVsivoqC"}

LiteLLM: model group 'vertex-claude-opus-4-5-versioned' failed with the error above. No fallback was attempted.

After (6046f5b)

$ client-venv/bin/python qa_client.py http://127.0.0.1:27475/v1 qa-master-key vertex-claude-opus-4-5-versioned chat
200 text='OK' finish_reason='stop'
SDK, Sonnet 4.6 `@default`, chat

Before (83c4706)

$ client-venv/bin/python qa_client.py http://127.0.0.1:31963/v1 qa-master-key vertex-claude-sonnet-4-6-default chat
200 text='OK' finish_reason='stop'

After (6046f5b)

$ client-venv/bin/python qa_client.py http://127.0.0.1:27475/v1 qa-master-key vertex-claude-sonnet-4-6-default chat
200 text='OK' finish_reason='stop'
SDK, Sonnet 4.6 bare id control, chat

Before (83c4706)

$ client-venv/bin/python qa_client.py http://127.0.0.1:31963/v1 qa-master-key vertex-claude-sonnet-4-6 chat
200 text='OK' finish_reason='stop'

After (6046f5b)

$ client-venv/bin/python qa_client.py http://127.0.0.1:27475/v1 qa-master-key vertex-claude-sonnet-4-6 chat
200 text='OK' finish_reason='stop'
SDK, Haiku 4.5 versioned, explicit max_tokens 50 control

Before (83c4706)

$ client-venv/bin/python qa_client.py http://127.0.0.1:31963/v1 qa-master-key vertex-claude-haiku-4-5-versioned chat_max_tokens_50
200 text='OK' finish_reason='stop'

After (6046f5b)

$ client-venv/bin/python qa_client.py http://127.0.0.1:27475/v1 qa-master-key vertex-claude-haiku-4-5-versioned chat_max_tokens_50
200 text='OK' finish_reason='stop'
max_tokens sent, Haiku 4.5 versioned

Before (83c4706)

$ client-venv/bin/python transform_probe.py http://127.0.0.1:31963 qa-master-key vertex_ai/claude-haiku-4-5@20251001
200 max_tokens=128000 error=None

After (6046f5b)

$ client-venv/bin/python transform_probe.py http://127.0.0.1:27475 qa-master-key vertex_ai/claude-haiku-4-5@20251001
200 max_tokens=64000 error=None
max_tokens sent, Sonnet 4.6 `@default`

Before (83c4706)

$ client-venv/bin/python transform_probe.py http://127.0.0.1:31963 qa-master-key vertex_ai/claude-sonnet-4-6@default
200 max_tokens=128000 error=None

After (6046f5b)

$ client-venv/bin/python transform_probe.py http://127.0.0.1:27475 qa-master-key vertex_ai/claude-sonnet-4-6@default
200 max_tokens=128000 error=None
Setup: env var and /live-pr-risk rig

lpr-config.yaml. The non-Vertex deployments carry placeholder credentials, since those routes only go through /utils/transform_request

model_list:
  - model_name: vertex-haiku-4-5-versioned
    litellm_params:
      model: vertex_ai/claude-haiku-4-5@20251001
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
  - model_name: vertex-haiku-4-5-versioned-capped
    litellm_params:
      model: vertex_ai/claude-haiku-4-5@20251001
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
    model_info:
      max_output_tokens: 1000
  - model_name: vertex-sonnet-4-6-default
    litellm_params:
      model: vertex_ai/claude-sonnet-4-6@default
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
  - model_name: vertex-3-5-haiku-versioned
    litellm_params:
      model: vertex_ai/claude-3-5-haiku@20241022
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
  - model_name: vertex-unlisted-versioned
    litellm_params:
      model: vertex_ai/claude-unlisted-model@20990101
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: us-east5
  - model_name: anthropic-haiku-4-5
    litellm_params:
      model: anthropic/claude-haiku-4-5
      api_key: sk-ant-probe-only
  - model_name: azure-ai-haiku-4-5
    litellm_params:
      model: azure_ai/claude-haiku-4-5
      api_base: https://probe-only.services.ai.azure.com/anthropic
      api_key: probe-only
  - model_name: azure-ai-opus-5-5-fast
    litellm_params:
      model: azure_ai/claude-opus-5-5-fast
      api_base: https://probe-only.services.ai.azure.com/anthropic
      api_key: probe-only
  - model_name: bedrock-invoke-haiku-4-5
    litellm_params:
      model: bedrock/invoke/us.anthropic.claude-haiku-4-5-20251001-v1:0
      aws_access_key_id: AKIAPROBEONLY0000000
      aws_secret_access_key: probe-only
      aws_region_name: us-east-1
  - model_name: bedrock-claude-platform-haiku-4-5
    litellm_params:
      model: bedrock/claude_platform/claude-haiku-4-5
      aws_access_key_id: AKIAPROBEONLY0000000
      aws_secret_access_key: probe-only
      aws_region_name: us-east-1
  - model_name: opencode-go-haiku-5-5
    litellm_params:
      model: opencode_go/claude-haiku-5-5
      api_key: probe-only
  - model_name: databricks-claude-haiku-4-5
    litellm_params:
      model: databricks/databricks-claude-haiku-4-5
      api_base: https://probe-only.cloud.databricks.com/serving-endpoints
      api_key: probe-only
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY

lpr_boot.sh <tree> <port> [DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS], run once per tree

#!/bin/zsh
set -eu
tree=$1
[ -n "${3:-}" ] && export DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS=$3
port=$2
W=/private/tmp/claude-501/-Users-mateo-Development-litellm/b517416e-2153-4049-9115-09daf22edcf2/scratchpad/work-37eabb66
H=$HOME/Development/litellm-worktrees/work-37eabb66-head
unset DATABASE_URL
export AZURE_AI_API_BASE=https://probe-only.services.ai.azure.com/anthropic ANTHROPIC_AWS_WORKSPACE_ID=probe-only AWS_REGION_NAME=us-east-1 DATABRICKS_API_BASE=https://probe-only.cloud.databricks.com/serving-endpoints DATABRICKS_API_KEY=probe-only
export PYTHON_DOTENV_DISABLED=1
export LITELLM_LOCAL_MODEL_COST_MAP=True
export VERTEXAI_PROJECT=$(~/.claude/bin/dotenv-get VERTEXAI_PROJECT --file $H/.env)
export GOOGLE_APPLICATION_CREDENTIALS=$(~/.claude/bin/dotenv-get GOOGLE_APPLICATION_CREDENTIALS --file $H/.env)
export LITELLM_MASTER_KEY=$(<$W/qa-master-key)
export PYTHONPATH=$tree
cd $tree
print -r -- "leg tree=$tree HEAD=$(git rev-parse --short HEAD) porcelain_lines=$(git status --porcelain | wc -l) port=$port"
print -r -- "DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS=${DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS-unset}"
exec $H/.venv/bin/python -m litellm.proxy.proxy_cli --config $W/lpr-config.yaml --host 127.0.0.1 --port $port --num_workers 2 --telemetry False

lpr_probe.py <base url> <key file> <out json> <model...> asks POST /utils/transform_request for the body each raw model id would send

import json
import sys
import urllib.error
import urllib.request
from pathlib import Path

base_url, key_file, out, *models = sys.argv[1:]
key = Path(key_file).read_text().strip()


def probe(model: str) -> dict:
    body = {
        "call_type": "completion",
        "request_body": {"model": model, "messages": [{"role": "user", "content": "Reply with the single word OK."}]},
    }
    request = urllib.request.Request(
        f"{base_url}/utils/transform_request",
        data=json.dumps(body).encode(),
        headers={"Authorization": f"Bearer {key}", "Content-Type": "application/json"},
    )
    try:
        with urllib.request.urlopen(request, timeout=60) as response:
            raw = json.load(response)
            return {"status": response.status, "error": raw.get("error"), "body": raw.get("raw_request_body")}
    except urllib.error.HTTPError as e:
        return {"status": e.code, "error": e.read()[:300].decode(errors="replace"), "body": None}


results = {model: probe(model) for model in models}
Path(out).write_text(json.dumps(results, indent=1, sort_keys=True))
for model, r in results.items():
    sent = r["body"] if isinstance(r["body"], dict) else {}
    print(f"{model}\t{r['status']}\tmax_tokens={sent.get('max_tokens')!r}\terror={(r['error'] or '')[:80]!r}")
LibreChat, Haiku 4.5 versioned, long reply with `DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS=4096`

Both proxies booted with DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS=4096 boot_leg.sh <tree> <port>, with LibreChat set up as above. drive_long_chat.py sends the long-story prompt, waits up to 10 minutes for the stream to end, and prints the reply's word count, its last line, and whether LibreChat offers Continue

import sys
import urllib.parse
from pathlib import Path

from playwright.sync_api import sync_playwright

base_url, email, password_file, endpoint, model, out_png = sys.argv[1:7]
password = Path(password_file).read_text().strip()
prompt = "Write an original 6000-word short story about a lighthouse keeper. Keep writing until the story is complete."

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page(viewport={"width": 1280, "height": 900})
    page.goto(f"{base_url}/login")
    page.fill("input[name=email]", email)
    page.fill("input[name=password]", password)
    page.click("button[type=submit]")
    page.wait_for_url("**/c/**", timeout=60_000)
    query = urllib.parse.urlencode({"endpoint": endpoint, "model": model})
    page.goto(f"{base_url}/c/new?{query}")
    textarea = page.locator("textarea#prompt-textarea, textarea[data-testid=text-input]").first
    textarea.wait_for(timeout=60_000)
    textarea.fill(prompt)
    textarea.press("Enter")
    page.wait_for_timeout(5_000)
    page.wait_for_function(
        "() => !document.querySelector('[data-testid=stop-generation-button], button[aria-label=\"Stop generating\"]')",
        timeout=600_000,
        polling=2_000,
    )
    page.wait_for_timeout(3_000)
    messages = page.locator(".message-render, [data-testid=message-text], .markdown").all_inner_texts()
    errors = page.locator("[role=alert], .text-red-500, .text-red-600, .bg-red-500\\/10").all_inner_texts()
    reply = messages[-1] if messages else ""
    continue_button = page.get_by_role("button", name="Continue")
    page.locator(".markdown").last.evaluate("node => node.scrollIntoView({block: 'end'})")
    page.wait_for_timeout(1_000)
    page.screenshot(path=out_png)
    last_line = next((line for line in reversed(reply.splitlines()) if line.strip()), "")
    print(f"endpoint={endpoint!r} model={model!r}")
    print(f"reply_words={len(reply.split())}")
    print(f"reply_last_line={last_line[-160:]!r}")
    print(f"continue_button_shown={continue_button.count() > 0}")
    print(f"error_banner={errors[0][:300] if errors else None!r}")
    browser.close()
  1. Sign in to LibreChat, open a new chat on the endpoint with model vertex-claude-haiku-4-5-versioned, and send "Write an original 6000-word short story about a lighthouse keeper. Keep writing until the story is complete."

Before (83c4706)

$ lc-venv/bin/python librechat/drive_long_chat.py http://127.0.0.1:21440 qa@example.com librechat/qa-user-password 'LiteLLM base 83c47061e1' vertex-claude-haiku-4-5-versioned shots/librechat-env4096-base-haiku.png
endpoint='LiteLLM base 83c47061e1' model='vertex-claude-haiku-4-5-versioned'
reply_words=3193
reply_last_line='"I\'m also'
continue_button_shown=False
error_banner=None

LibreChat on the base proxy stops the story at the 4096 token cap

After (3570922)

$ lc-venv/bin/python librechat/drive_long_chat.py http://127.0.0.1:21440 qa@example.com librechat/qa-user-password 'LiteLLM head 3570922b36' vertex-claude-haiku-4-5-versioned shots/librechat-env4096-head-haiku.png
endpoint='LiteLLM head 3570922b36' model='vertex-claude-haiku-4-5-versioned'
reply_words=5089
reply_last_line='THE END'
continue_button_shown=False
error_banner=None

LibreChat on the head proxy gets the whole story

Haiku 4.5 versioned, long reply with `DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS=4096`

Both proxies booted with lpr_boot.sh <tree> <port> 4096, the value the v1.109.0 notes give for keeping the old default. The request sends no max_tokens. The base leg shows the cut-off the issue reports

Before (83c4706)

$ curl -s http://127.0.0.1:31963/v1/chat/completions -H "Authorization: Bearer $(<qa-master-key)" -H 'Content-Type: application/json' -d '{"model":"vertex-haiku-4-5-versioned","messages":[{"role":"user","content":"Write an original 6000-word short story about a lighthouse keeper. Keep writing until the story is complete."}]}' | python3 -c 'import json,sys; r=json.load(sys.stdin); print("finish_reason=", r["choices"][0]["finish_reason"], "completion_tokens=", r["usage"]["completion_tokens"]) if "choices" in r else print(r)'
finish_reason= length completion_tokens= 4096

After (6046f5b)

$ curl -s http://127.0.0.1:27475/v1/chat/completions -H "Authorization: Bearer $(<qa-master-key)" -H 'Content-Type: application/json' -d '{"model":"vertex-haiku-4-5-versioned","messages":[{"role":"user","content":"Write an original 6000-word short story about a lighthouse keeper. Keep writing until the story is complete."}]}' | python3 -c 'import json,sys; r=json.load(sys.stdin); print("finish_reason=", r["choices"][0]["finish_reason"], "completion_tokens=", r["usage"]["completion_tokens"]) if "choices" in r else print(r)'
finish_reason= stop completion_tokens= 6142
/live-pr-risk at 6046f5b

Verdict: no breaking change found. The run was at 6046f5b. 3570922 only changes how the unversioned row is read, and max_tokens is the same before and after it for every Claude id and provider in the cost map. Both proxies booted from the base and 6046f5b with 2 workers and lpr-config.yaml, and lpr_probe.py sent each raw model id through POST /utils/transform_request, once with DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS unset and once at 4096

Route Unset, before Unset, after 4096, before 4096, after
vertex_ai/claude-haiku-4-5@20251001 128000 64000 4096 64000
vertex_ai/claude-3-5-haiku@20241022 128000 8192 4096 8192
vertex_ai/claude-sonnet-4-6@default 128000 128000 4096 128000
vertex_ai/claude-unlisted-model@20990101 128000 128000 4096 4096
anthropic/claude-haiku-4-5 64000 64000 64000 64000
anthropic/claude-unlisted-model 128000 128000 4096 4096
azure_ai/claude-haiku-4-5 64000 64000 64000 64000
azure_ai/claude-opus-5-5-fast 128000 128000 4096 128000
bedrock/invoke/us.anthropic.claude-haiku-4-5-20251001-v1:0 64000 64000 64000 64000
bedrock/claude_platform/claude-haiku-4-5 64000 64000 64000 64000
opencode_go/claude-haiku-5-5 128000 128000 128000 128000
databricks/databricks-claude-haiku-4-5 none none none none

Every other request body key matched on all 12 routes in both runs

Breaking: none. With the env var unset only Vertex ids change, and Vertex rejects 128000 on each of them. Over all 44 Vertex Claude cost-map ids, 11 change, each from 128000 to its mapped cap

Vertex id Before After
vertex_ai/claude-3-5-haiku 128000 8192
vertex_ai/claude-3-5-haiku@20241022 128000 8192
vertex_ai/claude-3-5-sonnet 128000 8192
vertex_ai/claude-3-5-sonnet@20240620 128000 8192
vertex_ai/claude-3-haiku 128000 4096
vertex_ai/claude-3-haiku@20240307 128000 4096
vertex_ai/claude-3-sonnet 128000 4096
vertex_ai/claude-3-sonnet@20240229 128000 4096
vertex_ai/claude-haiku-4-5@20251001 128000 64000
vertex_ai/claude-opus-4-5@20251101 128000 64000
vertex_ai/claude-sonnet-4-5@20250929 128000 64000

Backward incompatible: none. With the env var set, an id whose model has a row now gets that row, as its unversioned id already did. At 4096 that is 64000 on versioned Haiku 4.5, and 128000 on the Azure AI names claude-opus-5-5-fast, claude-fable-5-2-fast and claude-mythos-5-2-fast, whose only row is the azure_ai/ one. Azure AI names with a bare row already ignored the env var on the base, e.g. azure_ai/claude-haiku-4-5 sends 64000 at 4096 on both sides. The env var stays the default for ids with no row, which is what the v1.109.0 notes describe. This run first flagged the 4096 case and 53d146b put the env value ahead of the rows, but that kept the issue's 4096 cut-off and the 400 at an explicit 128000, so 8fdc906 reverts it

Regression risk: low. A deployment model_info.max_output_tokens of 1000 still caps a real Haiku 4.5 reply at 1000 on both sides. The provider-row and @ steps run on every Anthropic route, and tests now drive them on the Anthropic, Azure AI and Claude Platform routes as well as Vertex

Dependency graph: AnthropicConfig.get_config is the only caller of get_max_tokens_for_model, and every route above goes through it (verified live by the sweep). Bedrock Invoke now calls the shared mapped_max_output_tokens helper (verified live, 64000 on both sides). Every tests/integration Claude id resolves the same on both sides except vertex_ai/claude-3-haiku and vertex_ai/claude-haiku-4-5@20251001, and those Vertex suites send max_tokens themselves

Not verified: real provider calls on the Anthropic, Azure AI, Bedrock, Claude Platform, OpenCode Go and Databricks routes, which ran transform-only with placeholder credentials

Observations

  • Sonnet 4.6 @default keeps the 128000 default Vertex accepts
  • LibreChat streams, so its 400 comes from the stream path
  • /v1/messages without max_tokens answers 400 on both legs

Type

🐛 Bug Fix

Caveats (if any)

Decisions
  • Lookup order is the model's own row, then its unversioned row, then the provider row, then DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS, 128000 unless set
    • An explicitly set env var stays the default for ids with no row, as the v1.109.0 notes describe it. A versioned id whose model has a row now gets that row, like its unversioned id already did
    • Rejected putting the env value ahead of the new rows, tried in 53d146b. Any set value then turned the fix off, so 4096 kept the issue's cut-off and 128000 kept the 400
    • Picked so ids that work today keep their default, and only ids that 400 or get cut off today change
    • Rejected reading the provider row first, or the lower of the rows. Both cut claude-sonnet-4-6 and claude-sonnet-4-6@default from 128000 to 64000, though Vertex accepts 128000 today
    • Rejected changing the vertex_ai/claude-sonnet-4-6 rows here, since a cost-map value change needs its own source
  • The @ split runs on every route. Other ids with @, like the Bedrock anthropic.claude-haiku-4-5@20251001 and Cloudflare @cf/... keys, never reach this step, so other routes see no change
  • The provider-row step runs on every Anthropic route, not only Vertex
    • Picked because the env var is the default for ids missing from the cost map, and on the base Azure AI names with a bare row already ignored it
    • With the env var set, claude-opus-5-5-fast, claude-fable-5-2-fast and claude-mythos-5-2-fast on Azure AI now get their azure_ai/ row of 128000 instead of the env value, like their siblings. With it unset, no Azure AI name changes
    • Rejected the Vertex-only override this PR first had. The author left the shared direction to maintainers in the thread, and it would leave those three names on the env value
    • Tests drive the lookup on the Anthropic, Azure AI and Claude Platform routes as well as Vertex

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Medium Risk
Changes default output limits on every Anthropic route when cost-map rows exist, which fixes Vertex 400s but alters wire behavior for clients that relied on the 128k fallback.

Overview
Fixes bad default max_tokens on Anthropic-shaped routes when the caller omits a limit and the model id is versioned (e.g. claude-haiku-4-5@20251001) or only listed under a provider key in the cost map.

AnthropicConfig.get_max_tokens_for_model now resolves in order: the model’s own row, the unversioned id before @, then {custom_llm_provider}/{model}, then DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS. Shared helper mapped_max_output_tokens backs that lookup; get_config and transform_request pass custom_llm_provider so Vertex (and siblings) can read provider rows. Bedrock Invoke drops its duplicate mapper and reuses the shared helper; Databricks get_config accepts the same optional provider arg.

Unit tests cover default max_tokens on Anthropic, Azure AI, Bedrock Claude Platform, and Vertex partner configs.

Reviewed by Cursor Bugbot for commit 0cb8559. Bugbot is set up for automated code reviews on this repo. Configure here.

@hktitof
hktitof requested a review from a team September 9, 2026 06:36
@hktitof
hktitof requested a review from mateo-berri as a code owner September 9, 2026 06:36
@CLAassistant

CLAassistant commented Sep 9, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@codspeed

codspeed Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 45 untouched benchmarks


Comparing hktitof:fix-vertex-claude-max-tokens (0cb8559) with main (d8e8621)

Open in CodSpeed

@codecov

codecov Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The reviewed code appears safe to merge, with no new blocking finding.

Summary

Resolves missing max_tokens for versioned Claude IDs by checking the model’s own row, its unversioned row, and its provider row before using the fallback.

  • Versioned Claude requests use mapped output limits when no limit is sent.

Reviews (9) · Last reviewed commit: "Merge branch 'main' into fix-vertex-clau..." · Reviewed by Greptile

@mihidumh mihidumh 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.

Reporter of #40363 here — thanks for picking it up. Two observations after reading the diff:

  1. The versioned-id lookup is vertex-only. get_max_tokens_for_model is overridden on VertexAIAnthropicConfig and keys on vertex_ai/<model>. The same defect class exists for every AnthropicConfig subclass: AzureAnthropicConfig runs the same get_config fill, and its rows resolve under azure_ai/<model> keys, so an id that is not a bare map key still lands on the 4096 default there. A provider-aware lookup in the shared config (get_max_tokens_for_model(model, custom_llm_provider) → try f"{provider}/{model}" before defaulting) fixes all subclasses in one place. That is what my held branch does, offered for cherry-pick if useful: litellm_internal_staging...mihidumh:litellm:fix/anthropic-max-tokens-provider-aware-default (3 tests, 375/375 across the two test files). One trap I hit there: get_model_info widens unknown ids via its family heuristic (an unmapped id came back as 64000), so I read the exact key only.
  2. The AnthropicConfig.__dict__ block in get_config re-implements BaseConfig.get_config for a fixed class. Same filter, same shape — BaseConfig.get_config.__func__(AnthropicConfig) (or a small shared helper) would avoid the second copy. The switch from litellm.AnthropicConfig.get_config(...) to self.get_config(...) in transform_request is the part that actually makes subclass overrides reachable, and looks right.

The map hunk matches what I measured: a max_tokens: 64000 request on claude-haiku-4-5@20251001 via Vertex returned 15,290 output tokens, so 64000 is the real cap on both vertex_ai/claude-haiku-4-5* keys (Google's page says the same). Note #40374's map-only fix was closed as "carried by #31884" — as of today that PR's diff has no vertex_ai/claude-haiku-4-5 entry, so this PR is the only one carrying the map half.

@hktitof

hktitof commented Sep 10, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the detailed read, good points on both. i'm keeping this pr scoped to the vertex_ai defect from #40363 bcs the provider-aware default changes the fill for every AnthropicConfig subclass at once, so that half (and the BaseConfig.get_config reuse) is its own change, your branch is a good base for it — let's see what the maintainers prefer on the shared-config direction

@mihidumh

Copy link
Copy Markdown
Contributor

Thanks. Scoping this PR to vertex_ai makes sense to me.

One correction to my review: the two map entries already landed on main through #31884 (bbf51146ca, in v1.102.0-rc.1). So the JSON hunk here now duplicates main. The get_max_tokens_for_model override is the part that is still needed.

@hktitof
hktitof force-pushed the fix-vertex-claude-max-tokens branch from cccedd9 to d6ac17d Compare September 14, 2026 00:42
@hktitof

hktitof commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the double check, i verified #31884 and you are right, the map hunk is already on main so i dropped it from this pr, the get_max_tokens_for_model override is what stays now, tests are green on the new head

@mihidumh

Copy link
Copy Markdown
Contributor

Heads-up @hktitof: this PR still targets litellm_internal_staging. The maintainers retired that branch on 2026-09-13, and main is now the default base (CONTRIBUTING.md: "against the repository's current default branch"). The branch that exists now is only a stub, so this PR cannot merge into anything that ships. Please retarget it to main with "Edit" → base, then rebase. It still fixes the code half of #40363, which is not fixed upstream: #31884 landed only the map half.

@hktitof
hktitof changed the base branch from litellm_internal_staging to main September 17, 2026 00:34
@hktitof

hktitof commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

thanks for the heads up, retargeted the pr to main, it applies clean with no conflicts so no rebase was needed. keeping this one alive since the code half of #40363 is still not fixed upstream

@uje-m

uje-m commented Oct 14, 2026

Copy link
Copy Markdown

Heads-up about a related fix, so the two don't collide.

The same silent 4096 default also hits proxy deployments of custom Anthropic-compatible models: anthropic/<custom-model> with model_info.max_output_tokens set. The default lookup only sees the provider-stripped name, and the deployment's model_info, which does reach transform_request through litellm_params, is never consulted.

I'm opening a separate PR for that case. It reads litellm_params["model_info"]["max_output_tokens"] in AnthropicConfig.transform_request when the request has no max_tokens and no class-level default. The new block sits just above the ## Load Config block this PR edits, so neither PR changes the other's lines; whichever lands second only needs a context rebase.

After both land: a Vertex deployment with model_info.max_output_tokens uses that value, and one without it gets your vertex_ai/-prefixed lookup. I'll link the PR here once it's up.

@uje-m

uje-m commented Oct 14, 2026

Copy link
Copy Markdown

The PR for the custom-deployment case is up: #46433 (issue #46432).

@veria-ai

veria-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

… for a missing max_tokens

A Vertex @Version id now reads the cost-map row of its id without the version before the vertex_ai row, so claude-sonnet-4-6@default keeps the 128000 default that Vertex accepts while versioned Haiku, Opus, and Sonnet 4.5 ids still get 64000.
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…ead of the unversioned and provider rows

An operator who set DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS, for example to 4096 as the v1.109.0 notes
suggest, got that value for every Claude id with no own cost-map row. The new unversioned and
provider-row steps ranked above it, so vertex_ai/claude-haiku-4-5@20251001 went from 4096 to 64000
and claude-sonnet-4-6@default from 4096 to 128000 for them. An explicit value now comes right after
the model's own row, so only deployments on the built-in fallback change
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

…llback after the unversioned and provider rows

Reverts the previous commit. With DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS set to any value, versioned
Vertex Claude ids ignored their model's row again: at 4096 a Haiku 4.5 reply still stopped at 4096
tokens, the symptom the linked issue reports, and at 128000 Vertex still answered 400. The env var is
documented as the default for models missing from the cost map, and a versioned id whose model has a
row is not missing, so it now gets the same cap as its unversioned id
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

… the lookup on other routes

The unversioned lookup went through get_max_tokens, which prints the provider banner a second time
when the id has no row, so SDK calls on ids like claude-3-5-haiku@20241022 printed it twice. Reading
the row directly gives the same max_tokens for every cost-map Claude id on every route. New tests
drive the provider and unversioned rows on the Anthropic, Azure AI and Claude Platform routes
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

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

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

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

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@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 0cb8559. Configure here.

@mateo-berri mateo-berri 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.

LGTM. Thanks for the contribution!

@mateo-berri
mateo-berri merged commit 74fd46a into BerriAI:main Nov 14, 2026
94 checks passed
mateo-berri added a commit that referenced this pull request Nov 14, 2026
…1_108_x

fix(vertex_ai): backport #40376 versioned Claude max_tokens to lts/1.108.x
@hktitof

hktitof commented Nov 15, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review @mateo-berri, glad it's in, cheers!

mateo-berri added a commit to mika-lt/litellm that referenced this pull request Nov 17, 2026
Backport of BerriAI#40376 to lts/1.108.x.
Applied from the PR's net diff at 3570922 and adapted to the line,
which has no deployment max_output_tokens and no Bedrock Invoke get_config override.

Co-authored-by: hktitof <hktitof@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

6 participants