Skip to content

Fix vision model sending max_tokens and max_completion_tokens together - #1869

Open
wgnrai wants to merge 1 commit into
agent0ai:mainfrom
wgnrai:fix/vision-max-tokens-collision
Open

wgnrai wants to merge 1 commit into
agent0ai:mainfrom
wgnrai:fix/vision-max-tokens-collision

Conversation

@wgnrai

@wgnrai wgnrai commented Sep 1, 2026

Copy link
Copy Markdown

Problem

Setting max_completion_tokens in a vision preset's kwargs breaks every vision_load call with:

litellm.BadRequestError: OpenAIException - Setting 'max_tokens' and 'max_completion_tokens' at the same time is not supported.

The cause is in build_vision_model() (plugins/_model_config/helpers/model_config.py). It always injects max_tokens, either from the preset or the default of 2000, into the model kwargs. When the preset also sets max_completion_tokens under kwargs, both parameters end up in the same request and the provider rejects it.

The Responses API path already handles this collision (helpers/litellm_transport.py pops both and maps them to max_output_tokens), but the vision side-car builds its call through unified_call and never goes through that normalization.

Fix

Skip the max_tokens injection in build_vision_model() when max_completion_tokens is already present in the merged kwargs. Preset intent wins, which matches the precedence used on the Responses path.

Testing

Added plugins/_model_config/tests/test_build_vision_model_max_tokens.py with four cases:

  1. no max_completion_tokens anywhere: max_tokens still injected (default behavior unchanged)
  2. max_completion_tokens in kwargs: max_tokens not injected (the bug)
  3. explicit slot-level max_tokens=4096 with no collision: injected as 4096
  4. slot-level max_tokens and kwargs max_completion_tokens both set: only max_completion_tokens survives

All four pass with python -m pytest plugins/_model_config/tests/test_build_vision_model_max_tokens.py -v.

Also confirmed on a live instance: with the patch, vision_load succeeds again where it previously returned the BadRequestError above.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@wgnrai

wgnrai commented Sep 23, 2026

Copy link
Copy Markdown
Author

This one needed a rebase after some time on the back burner; it applied cleanly. The underlying issue is unchanged: main still sends both max_tokens and max_completion_tokens for vision models.

@wgnrai
wgnrai force-pushed the fix/vision-max-tokens-collision branch from bbc2dbf to 663ebe5 Compare September 23, 2026 04:41
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.

1 participant