feat: add User-Agent customization support#19881
Merged
Sameerlite merged 6 commits intoBerriAI:mainfrom Feb 2, 2026
Merged
Conversation
Add litellm.disable_default_user_agent global flag to control whether the automatic User-Agent header is injected into HTTP requests.
Modify http_handler.py and httpx_handler.py to check the disable_default_user_agent flag and return empty headers when disabled. This allows users to override the User-Agent header completely.
Add 8 tests covering: - Default User-Agent behavior - Disabling default User-Agent - Custom User-Agent via extra_headers - Environment variable support - Async handler support - Override without disabling - Claude Code use case - Backwards compatibility
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
e96e4aa to
b20cf7d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR lets you fully override LiteLLM’s default outbound
User-Agentby settingLITELLM_USER_AGENT.Problem
Some Anthropic/Claude credentials are only allowed when the request
User-Agentmatches an allowlist (e.g.Claude Code). LiteLLM currently sendsUser-Agent: litellm/{version}, which can trigger the block.Fix
LITELLM_USER_AGENTis set, LiteLLM sends exactly that value asUser-Agent(nolitellm/{version}appended).litellm/{version}).Usage
LITELLM_USER_AGENT="Claude Code"User-Agentstill works via request headers and will override the client default.Tests
tests/test_litellm/llms/custom_httpx/test_http_handler.pytests/test_litellm/proxy/auth/test_handle_jwt.pytests/test_litellm/llms/databricks/test_databricks_partner_integration.pytests/test_litellm/litellm_core_utils/test_litellm_logging.pyFixes #19017