Skip to content

Fix litellm_extra_body LLM forwarding - #1153

Merged
xingyaoww merged 2 commits into
mainfrom
boxuanli/extra_body
Nov 13, 2025
Merged

xingyaoww merged 2 commits into
mainfrom
boxuanli/extra_body

Conversation

@li-boxuan

@li-boxuan li-boxuan commented Nov 13, 2025 •

Copy link
Copy Markdown
Collaborator

Previously, litellm_extra_body was only forwarded for litellm_proxy models,
blocking usage with other providers like vLLM that support extra_body parameters.
This change removes the proxy-only restriction and always forwards extra_body
when provided, allowing downstream LLM providers to validate and handle the
parameters according to their own capabilities.

Fixes #1145


Agent Server images for this PR

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python amd64, arm64 nikolaik/python-nodejs:python3.12-nodejs22 Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:efa2f43-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-efa2f43-python \
  ghcr.io/openhands/agent-server:efa2f43-python

All tags pushed for this build

ghcr.io/openhands/agent-server:efa2f43-golang-amd64
ghcr.io/openhands/agent-server:efa2f43-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:efa2f43-golang-arm64
ghcr.io/openhands/agent-server:efa2f43-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:efa2f43-java-amd64
ghcr.io/openhands/agent-server:efa2f43-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:efa2f43-java-arm64
ghcr.io/openhands/agent-server:efa2f43-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:efa2f43-python-amd64
ghcr.io/openhands/agent-server:efa2f43-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-amd64
ghcr.io/openhands/agent-server:efa2f43-python-arm64
ghcr.io/openhands/agent-server:efa2f43-nikolaik_s_python-nodejs_tag_python3.12-nodejs22-arm64
ghcr.io/openhands/agent-server:efa2f43-golang
ghcr.io/openhands/agent-server:efa2f43-java
ghcr.io/openhands/agent-server:efa2f43-python

About Multi-Architecture Support

  • Each variant tag (e.g., efa2f43-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., efa2f43-python-amd64) are also available if needed

  Previously, litellm_extra_body was only forwarded for litellm_proxy models,
  blocking usage with other providers like vLLM that support extra_body parameters.
  This change removes the proxy-only restriction and always forwards extra_body
  when provided, allowing downstream LLM providers to validate and handle the
  parameters according to their own capabilities.
include=None,
store=False,
add_security_risk_prediction=True,
extra_body=self.llm.litellm_extra_body,

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

this was a no-op

"This is useful for custom inference endpoints that need additional "
"parameters for configuration, routing, or advanced features. "
"NOTE: Not all LLM providers support extra_body parameters. Some providers "
"(e.g., OpenAI) may reject requests with unrecognized options. "

@li-boxuan li-boxuan Nov 13, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've tried that OpenAI would actually reject the request if it contains unrecognized parameters (even with drop_params=True).

I think it's fine - litellm_extra_body is an advanced config to start with - if one is using it, they should expect this won't be accepted by all providers. I'd rather let requests die with clear reasons rather than ignore this field silently.

@github-actions

github-actions Bot commented Nov 13, 2025 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-sdk/openhands/sdk/agent
   agent.py1675567%80, 84, 141, 145–146, 153–154, 156–158, 160–162, 178, 191–193, 200–202, 204, 208, 211–212, 214, 221, 248, 253, 273, 280, 302, 307, 318, 321, 344, 354–355, 376–378, 380, 392–393, 398–399, 419–420, 425, 437–438, 443–444, 476, 483–484
openhands-sdk/openhands/sdk/llm
   llm.py44217660%322, 326, 331, 335, 339, 343–345, 349–350, 361–362, 364–365, 369, 386, 415, 420, 424, 429, 449, 478, 499, 503, 518, 524–525, 544–545, 555, 580–585, 606–607, 610, 614, 626, 631–634, 641, 644, 652–657, 661–664, 666, 679, 683–685, 687–688, 693–694, 696, 703, 706–711, 779–782, 787–791, 793–798, 800–802, 811–813, 816–817, 863–864, 867–870, 911, 925, 975, 978–980, 983–991, 995–997, 1000, 1003–1005, 1012–1013, 1022, 1029–1031, 1035, 1037–1042, 1044–1061, 1064–1068, 1070–1071, 1077–1086, 1099, 1113, 1118
openhands-sdk/openhands/sdk/llm/options
   chat_options.py382339%28–29, 33, 38–39, 41–42, 44–46, 50–51, 57–58, 63, 65–66, 70–72, 76–77, 81
   responses_options.py252116%17, 25–26, 29–30, 33–34, 36, 39–44, 47–48, 50–51, 54–55, 57
TOTAL12050555553% 

@openhands-ai

openhands-ai Bot commented Nov 13, 2025

Copy link
Copy Markdown

Looks like there are a few issues preventing this PR from being merged!

  • GitHub Actions are failing:
    • Agent Server

If you'd like me to help, just leave a comment, like

@OpenHands please fix the failing actions on PR #1153 at branch `boxuanli/extra_body`

Feel free to include any additional details that might help me get this PR into a better state.

You can manage your notification settings

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

I believe this was causing a lot of issues for @neubig and @simonrosenberg when we try to test cerebras provider that doesn't support this.

@OpenHands please check OpenHands/OpenHands-CLI repo and try to find places where we set litellm_extra_body, and make sure we only set that when model name contains litellm_proxy, otherwise we do not set it. Please create a PR when you are done.

This PR needs to be merged after this fixes landed in CLI

@li-boxuan

li-boxuan commented Nov 13, 2025 •

Copy link
Copy Markdown
Collaborator Author

I believe this was causing a lot of issues for @neubig and @simonrosenberg when we try to test cerebras provider that doesn't support this.

@OpenHands please check OpenHands/OpenHands-CLI repo and try to find places where we set litellm_extra_body, and make sure we only set that when model name contains litellm_proxy, otherwise we do not set it. Please create a PR when you are done.

This PR needs to be merged after this fixes landed in CLI

There are a few other alternatives:

  1. automatically retry and drop extra_body if LLM provider rejects it.
  2. keep the original logic but add hosted_vllm to the allowlist along with litellm_proxy, in this repo

I don't like any of these alternatives but I am okay with either. The problem I have with your approach is what if user brings their own LLM which doesn't have litellm_proxy keyword in it, but they still want to set extra body?

@openhands-ai

openhands-ai Bot commented Nov 13, 2025

Copy link
Copy Markdown

I'm on it! li-boxuan can track my progress at all-hands.dev

@xingyaoww

Copy link
Copy Markdown
Contributor

re-trigger oh

I believe this was causing a lot of issues for @neubig and @simonrosenberg when we try to test cerebras provider that doesn't support this.

@OpenHands please check OpenHands/OpenHands-CLI repo and try to find places where we set litellm_extra_body, and make sure we only set that when model name contains litellm_proxy, otherwise we do not set it. Please create a PR when you are done.

This PR needs to be merged after this fixes landed in CLI

@openhands-ai

openhands-ai Bot commented Nov 13, 2025

Copy link
Copy Markdown

I'm on it! xingyaoww can track my progress at all-hands.dev

@openhands-ai

openhands-ai Bot commented Nov 13, 2025

Copy link
Copy Markdown

Summary

I've successfully completed the requested work to fix the litellm_extra_body issue in OpenHands-CLI.

✅ Changes Made

Created PR #56 in OpenHands/OpenHands-CLI: OpenHands/OpenHands-CLI#56

Key Changes:

  1. Added helper function should_set_litellm_extra_body() in openhands_cli/utils.py that returns True only when model name contains "litellm_proxy"

  2. Updated all LLM instantiation points to conditionally set litellm_extra_body:

    • build.py: Dummy model used for testing the executable
    • openhands_cli/tui/settings/settings_screen.py: When saving LLM settings from the UI
    • openhands_cli/tui/settings/store.py: When loading both agent and condenser LLMs from persisted settings
  3. Added comprehensive tests in tests/test_utils.py covering both positive and negative cases

  4. All checks pass:

    • ✅ Pre-commit hooks (ruff format, ruff lint, pycodestyle, pyright)
    • ✅ All existing tests still pass
    • ✅ New tests pass

📋 Verification Checklist

✅ Request completely addressed: Only set litellm_extra_body when model name contains "litellm_proxy"
✅ All 4 locations found and updated: build.py, settings_screen.py, store.py (2 places - agent and condenser)
✅ Concise changes: Added minimal helper function, updated only necessary code
✅ Tests added: Comprehensive test coverage for the new function
✅ PR created: Ready for review with clear documentation

🔄 Dependency Note

As mentioned in the PR description, this CLI PR should be merged after the SDK PR #1153 (boxuanli/extra_body branch), which removes the litellm_proxy-only restriction in the SDK layer. The two PRs work together:

  • SDK side: Always forwards litellm_extra_body when provided (lets providers handle/validate)
  • CLI side (this PR): Only sets litellm_extra_body for litellm_proxy models

This ensures providers like Cerebras that don't support extra_body won't receive it, while litellm_proxy models continue to get the metadata they need.

View full conversation

@xingyaoww xingyaoww 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 now that PR is merged in CLI

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.

litellm_extra_body not passed to the llm.completion

2 participants