Content-Length: 329788 | pFad | http://github.com/All-Hands-AI/OpenHands/pull/11360

FE pass extra headers to LiteLLM by enyst · Pull Request #11360 · All-Hands-AI/OpenHands · GitHub
Skip to content

Conversation

enyst
Copy link
Collaborator

@enyst enyst commented Oct 14, 2025

Summary

  • Adds support for passing extra_headers to LiteLLM completion APIs from OpenHands
  • New environment variable LLM_EXTRA_HEADERS accepts a JSON object which is forwarded to litellm.completion(), acompletion() (async), and streaming acompletion()
  • Includes unit tests verifying that extra_headers are forwarded to LiteLLM in all execution paths

Changes

  • openhands/llm/llm.py
    • Parse LLM_EXTRA_HEADERS (JSON) from env and, if valid, forward as extra_headers to litellm.completion
  • openhands/llm/async_llm.py
    • Same parsing and forwarding for async acompletion calls
  • openhands/llm/streaming_llm.py
    • Same parsing and forwarding for streaming acompletion calls
  • tests/unit/llm/test_extra_headers.py
    • New tests covering sync, async, and streaming cases to ensure headers are forwarded

How to use

  • Set LLM_EXTRA_HEADERS to a JSON object of headers

Verification

  • pre-commit hooks passed locally for backend files
  • Unit tests added and passing: poetry run pytest -q tests/unit/llm/test_extra_headers.py

Backward compatibility

  • If LLM_EXTRA_HEADERS is unset or invalid, no change in behavior.

Related Issues

Notes

  • We intentionally keep this minimal and env-driven; future improvements could expose this through explicit config if needed.

@enyst can click here to continue refining the PR


To run this PR locally, use the following command:

GUI with Docker:

docker run -it --rm   -p 3000:3000   -v /var/run/docker.sock:/var/run/docker.sock   --add-host host.docker.internal:host-gateway   -e SANDBOX_RUNTIME_CONTAINER_IMAGE=docker.all-hands.dev/all-hands-ai/runtime:c4ff3d6-nikolaik   --name openhands-app-c4ff3d6   docker.all-hands.dev/all-hands-ai/openhands:c4ff3d6

CLI with uvx:

uvx --python 3.12 --from git+https://github.com/All-Hands-AI/OpenHands@openhands/llm-extra-headers#subdirectory=openhands-cli openhands

…teLLM completion and acompletion (async/streaming); add unit tests\n\nCo-authored-by: openhands <openhands@all-hands.dev>
Copy link
Contributor

github-actions bot commented Oct 14, 2025

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  openhands/llm
  async_llm.py
  llm.py 73-74, 76-78
  streaming_llm.py
Project Total  

This report was generated by python-coverage-comment-action

enyst and others added 3 commits October 14, 2025 07:02
…args/_partial_kwargs indirection\n- Pass extra_headers directly via kwargs to partial() calls\n\nCo-authored-by: openhands <openhands@all-hands.dev>
… into helper

- Merge extra headers directly into kwargs across sync, async, streaming paths
- Add LLM._get_extra_headers() to de-duplicate env parsing
- Replace inline parsing in AsyncLLM and StreamingLLM
- Run pre-commit and unit tests

Co-authored-by: openhands <openhands@all-hands.dev>
@enyst enyst added the integration-test Runs integration tests on the PR label Oct 15, 2025
Copy link
Contributor

Hi! I started running the integration tests on your PR. You will receive a comment with the results shortly.

@enyst enyst changed the title feat(llm): pass extra headers to LiteLLM via LLM_EXTRA_HEADERS env pass extra headers to LiteLLM Oct 15, 2025
Copy link

openhands-ai bot commented Oct 15, 2025

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

  • GitHub Actions are failing:
    • Run Integration Tests

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

@OpenHands please fix the failing actions on PR #11360 at branch `openhands/llm-extra-headers`

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

You can manage your notification settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

integration-test Runs integration tests on the PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use github copilot in local litellm

1 participant









ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/All-Hands-AI/OpenHands/pull/11360

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy