litellm/tests/unit/llms/base_llm/chat
vikashmaddi-sarvam 41b90d4880
feat(sarvam): send a litellm User-Agent on chat requests (#52012)
* feat(sarvam): send a litellm User-Agent on chat requests

The Sarvam API logs the User-Agent of each request, which is how traffic is
attributed. LiteLLM's chat path currently sends the OpenAI SDK default
User-Agent, so requests through the JSON-configured sarvam provider are
indistinguishable from direct OpenAI SDK calls.

Add an optional user_agent template to the JSON provider config and wire JSON
providers into the existing attribution-header helper, which until now only ran
for providers with a provider_config. The template reports the running LiteLLM
and Python versions (litellm/1.110.0 Python/3.12.16).

The generated JSONProviderConfig forwards get_attribution_headers to the JSON
config, so the field also works for the JSON providers that are in LlmProviders
and therefore get a provider_config.

The field is opt-in: providers without user_agent keep their current headers,
and a caller-supplied User-Agent still wins, as documented on
get_attribution_headers.

🪷 Generated with Sarvam Code

Co-authored-by: Sarvam Code <code@sarvam.ai>

* refactor(sarvam): type the user_agent field and drop comments

* fix(sarvam): keep a caller client's User-Agent and honor LITELLM_USER_AGENT

A User-Agent set as a default header on the caller's own OpenAI client now wins over the provider attribution, and LITELLM_USER_AGENT replaces the JSON provider's user_agent template. Documents the user_agent field and tightens test types

* fix(sarvam): keep a client subclass's User-Agent and honor an empty LITELLM_USER_AGENT

* test(attribution): cover a caller client header in either spelling

* refactor(attribution): type the caller client and narrow it at the call site

---------

Co-authored-by: Vikash Maddi <vikashmaddi-sarvam@users.noreply.github.com>
Co-authored-by: Sarvam Code <code@sarvam.ai>
Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-17 23:52:53 +00:00
..
__init__.py
test_attribution_headers.py feat(sarvam): send a litellm User-Agent on chat requests (#52012) 2026-11-17 23:52:53 +00:00
test_provider_chat_thinking.py test: make 38 legacy live base-class translation tests offline (#45351) 2026-10-08 23:18:25 +00:00
test_provider_chat_translation.py test: make 38 legacy live base-class translation tests offline (#45351) 2026-10-08 23:18:25 +00:00
test_transformation.py