The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Add async_post_call_success_hook code snippet
berri-teddy53201c78694e
diff --git a/docs/my-website/docs/observability/custom_callback.md b/docs/my-website/docs/observability/custom_callback.mdindex c206c23d0f4..cfe97ca42c0 100644--- a/docs/my-website/docs/observability/custom_callback.md+++ b/docs/my-website/docs/observability/custom_callback.md@@ -67,6 +67,23 @@ asyncio.run(completion())- `async_post_call_success_hook` - Access user data + modify responses- `async_pre_call_hook` - Modify requests before sending+### Example: Modifying the Response in async_post_call_success_hook++You can use `async_post_call_success_hook` to add custom headers or metadata to the response before it is returned to the client. For example:++```python+async def async_post_call_success_hook(data, user_api_key_dict, response):+ # Add a custom header to the response+ additional_headers = getattr(response, "_hidden_params", {}).get("additional_headers", {}) or {}+ additional_headers["x-litellm-custom-header"] = "my-value"+ if not hasattr(response, "_hidden_params"):+ response._hidden_params = {}+ response._hidden_params["additional_headers"] = additional_headers+ return response+```++This allows you to inject custom metadata or headers into the response for downstream consumers. You can use this pattern to pass information to clients, proxies, or observability tools.+## Callback FunctionsIf you just want to log on a specific event (e.g. on input) - you can use callback functions.