litellm - 💡(How to fix) Fix [Bug]: Proxy-level callbacks (`async_pre_call_hook`) are bypassed on Anthropic endpoint (`/v1/messages`) [1 pull requests]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Fix Action

Fixed

Code Example

import sys
from litellm.integrations.custom_logger import CustomLogger

class MyCustomHook(CustomLogger):
    async def async_pre_call_hook(self, user_api_key_dict, cache, data, call_type, **kwargs):
        print(">>> async_pre_call_hook EXECUTED!", file=sys.stderr)
        return data

proxy_handler_instance = MyCustomHook()

---

litellm_settings:
  callbacks:
    - custom_hook.proxy_handler_instance

---

curl -X POST "http://localhost:4000/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-0000" \
-d '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "hi"}]}'

---

curl -X POST "http://localhost:4000/v1/messages" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-0000" \
-d '{
  "model": "gpt-3.5-turbo", 
  "max_tokens": 100, 
  "messages": [{"role": "user", "content": "hi"}]
}'

---

# Log for /chat/completions (OpenAI format)
>>> async_pre_call_hook EXECUTED!
INFO:     127.0.0.1:45312 - "POST /v1/chat/completions HTTP/1.1" 200 OK

# Log for /v1/messages (Anthropic format)
INFO:     127.0.0.1:45324 - "POST /v1/messages HTTP/1.1" 200 OK
# (Missing the hook execution log entirely)
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

When making requests to the LiteLLM Proxy via the Anthropic-compatible endpoint (/v1/messages), custom proxy-level hooks defined in CustomLogger (such as async_pre_call_hook) are completely bypassed and not executed.

However, when hitting the standard OpenAI-compatible endpoints (e.g. /chat/completions or /v1/chat/completions), these exact same hooks are successfully triggered.

Any request routed through the proxy, regardless of whether it originates from the OpenAI /v1/chat/completions endpoint or the Anthropic /v1/messages endpoint, should reliably trigger the configured async_pre_call_hook callbacks.

Steps to Reproduce

  1. Create a custom callback script custom_hook.py that inherits from CustomLogger and implements async_pre_call_hook:
import sys
from litellm.integrations.custom_logger import CustomLogger

class MyCustomHook(CustomLogger):
    async def async_pre_call_hook(self, user_api_key_dict, cache, data, call_type, **kwargs):
        print(">>> async_pre_call_hook EXECUTED!", file=sys.stderr)
        return data

proxy_handler_instance = MyCustomHook()
  1. Configure config.yaml to load this callback:
litellm_settings:
  callbacks:
    - custom_hook.proxy_handler_instance
  1. Start the proxy and send a request to the standard OpenAI endpoint:
curl -X POST "http://localhost:4000/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-0000" \
-d '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "hi"}]}'

Observe the proxy logs: >>> async_pre_call_hook EXECUTED! is printed.

  1. Now send an equivalent request to the Anthropic endpoint:
curl -X POST "http://localhost:4000/v1/messages" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-0000" \
-d '{
  "model": "gpt-3.5-turbo", 
  "max_tokens": 100, 
  "messages": [{"role": "user", "content": "hi"}]
}'

Observe the proxy logs: The request goes through successfully, but the hook execution log is completely missing.

Relevant log output

# Log for /chat/completions (OpenAI format)
>>> async_pre_call_hook EXECUTED!
INFO:     127.0.0.1:45312 - "POST /v1/chat/completions HTTP/1.1" 200 OK

# Log for /v1/messages (Anthropic format)
INFO:     127.0.0.1:45324 - "POST /v1/messages HTTP/1.1" 200 OK
# (Missing the hook execution log entirely)

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v.1.83.10

Twitter / LinkedIn details

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

litellm - 💡(How to fix) Fix [Bug]: Proxy-level callbacks (`async_pre_call_hook`) are bypassed on Anthropic endpoint (`/v1/messages`) [1 pull requests]