Replies: 1 comment
|
@azidanit Yes — LiteLLM Proxy provides a supported way to modify the request before it is forwarded to the upstream LLM. The recommended approach is to use a proxy For example: from litellm.integrations.custom_logger import CustomLogger
class MyProxyHook(CustomLogger):
async def async_pre_call_hook(
self,
user_api_key_dict,
cache,
data: dict,
call_type,
):
# Create extra_body if the client didn't send one
data.setdefault("extra_body", {})
# Inject your custom provider-specific parameters
data["extra_body"]["my_custom_flag"] = True
data["extra_body"]["tenant_id"] = "internal"
return data
proxy_handler_instance = MyProxyHook()Then register the callback in your litellm_settings:
callbacks: custom_callbacks.proxy_handler_instanceLiteLLM will invoke this hook before making the upstream completion call, so the modified One thing to keep in mind is that Out of curiosity, which upstream backend are you targeting (vLLM, SGLang, Ollama, OpenAI-compatible server, etc.)? Some providers also support provider-specific parameters directly, which may be cleaner than using If this solves your problem, feel free to mark it as the accepted answer so others can find it easily. |
Uh oh!
There was an error while loading. Please reload this page.
eventho the client not put the extra_body in their request, I would like to add more extra_body data (in litellm proxy) to the request that goes to LLM upstream
All reactions