Skip to content

feat: add User-Agent customization support#19881

Merged
Sameerlite merged 6 commits intoBerriAI:mainfrom
jayy-77:feat/user-agent-customization-issue-19017
Feb 2, 2026
Merged

feat: add User-Agent customization support#19881
Sameerlite merged 6 commits intoBerriAI:mainfrom
jayy-77:feat/user-agent-customization-issue-19017

Conversation

@jayy-77
Copy link
Contributor

@jayy-77 jayy-77 commented Jan 27, 2026

Summary

This PR lets you fully override LiteLLM’s default outbound User-Agent by setting LITELLM_USER_AGENT.

Problem

Some Anthropic/Claude credentials are only allowed when the request User-Agent matches an allowlist (e.g. Claude Code). LiteLLM currently sends User-Agent: litellm/{version}, which can trigger the block.

Fix

  • If LITELLM_USER_AGENT is set, LiteLLM sends exactly that value as User-Agent (no litellm/{version} appended).
  • If it’s not set, behavior stays the same (litellm/{version}).

Usage

  • Proxy / env: set LITELLM_USER_AGENT="Claude Code"
  • Per-request User-Agent still works via request headers and will override the client default.

Tests

  • tests/test_litellm/llms/custom_httpx/test_http_handler.py
  • tests/test_litellm/proxy/auth/test_handle_jwt.py
  • tests/test_litellm/llms/databricks/test_databricks_partner_integration.py
  • tests/test_litellm/litellm_core_utils/test_litellm_logging.py

Fixes #19017

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
@vercel
Copy link

vercel bot commented Jan 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
litellm Error Error Jan 27, 2026 8:41pm

Request Review

@jayy-77 jayy-77 marked this pull request as draft January 27, 2026 19:21
@jayy-77 jayy-77 force-pushed the feat/user-agent-customization-issue-19017 branch from e96e4aa to b20cf7d Compare January 27, 2026 19:21
@jayy-77 jayy-77 marked this pull request as ready for review January 28, 2026 08:25
Copy link
Collaborator

@Sameerlite Sameerlite left a comment

Choose a reason for hiding this comment

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

LGTM

@Sameerlite Sameerlite merged commit 1a7fcfb into BerriAI:main Feb 2, 2026
5 of 7 checks passed
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.

[Feature]: Option to disable or customize default User-Agent header (Avoid Claude/Anthropic blocks)

2 participants