Skip to content

Commit 53201c7

Browse files
committed
Add async_post_call_success_hook code snippet
1 parent 164b029 commit 53201c7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

docs/my-website/docs/observability/custom_callback.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,23 @@ asyncio.run(completion())
6767
- `async_post_call_success_hook` - Access user data + modify responses
6868
- `async_pre_call_hook` - Modify requests before sending
6969

70+
### Example: Modifying the Response in async_post_call_success_hook
71+
72+
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:
73+
74+
```python
75+
async def async_post_call_success_hook(data, user_api_key_dict, response):
76+
# Add a custom header to the response
77+
additional_headers = getattr(response, "_hidden_params", {}).get("additional_headers", {}) or {}
78+
additional_headers["x-litellm-custom-header"] = "my-value"
79+
if not hasattr(response, "_hidden_params"):
80+
response._hidden_params = {}
81+
response._hidden_params["additional_headers"] = additional_headers
82+
return response
83+
```
84+
85+
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.
86+
7087
## Callback Functions
7188
If you just want to log on a specific event (e.g. on input) - you can use callback functions.
7289

0 commit comments

Comments
 (0)