Skip to content

Conversation

@Sameerlite
Copy link
Collaborator

Title

Fixed async pre-call hook not being invoked for custom loggers

Relevant issues

Fixes #16254

Pre-Submission checklist

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details

  • I have added a screenshot of my new test passing locally

  • My PR passes all unit tests on make test-unit

  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🐛 Bug Fix

Changes

  • Enabled CustomLogger.log_pre_api_call to invoke async_log_pre_api_call when an async implementation is provided, while falling back to the existing sync stub for legacy loggers.
  • Added an async-aware execution path to the logging pre-call flow so that callbacks registered in litellm._async_input_callback (and dynamic async input callbacks) are awaited before the provider call.
  • Added minimal helpers to safely execute async callbacks from synchronous contexts by detecting existing event loops.
  • Verified the new behavior manually with pre_call_test.py to confirm that the async pre-call hook now runs.

@vercel
Copy link

vercel bot commented Nov 12, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
litellm Error Error Nov 12, 2025 1:39pm


def log_pre_api_call(self, model, messages, kwargs):
pass
async_impl = type(self).async_log_pre_api_call
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why run the async method for pre api call? isn't it always a sync call?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is what the codebase showed. But since I saw those methods and client was using the async method, I thought it was not implemented

@krrishdholakia
Copy link
Contributor

It's dangerous to try and guess if we should run the sync vs. async pre api call hook. I believe we can just document the behaviour, to call out the sync pre api call is what is called in the codebase.

@Sameerlite
Copy link
Collaborator Author

Understood. Will update the doc accordingly

@Sameerlite Sameerlite marked this pull request as ready for review November 12, 2025 18:20
@Sameerlite Sameerlite changed the base branch from main to litellm_sameer_nov_2 November 12, 2025 18:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:The pre-api-call hook in the callback is not triggered for downstream calls to the Responses API when using the gpt-5-codex model

3 participants