BerriAI/litellm · error · ValueError
OpenAI client is not an instance of OpenAI. Make sure you pa
Error message
OpenAI client is not an instance of OpenAI. Make sure you passed a sync OpenAI client.
What it means
ValueError raised when a synchronous (non-_is_async) OpenAI operation is handed a client that is not a sync OpenAI instance — usually an AsyncOpenAI client was passed to a sync method such as cancel_batch. The sync path cannot use an async client, so it rejects it up front.
Source
Thrown at litellm/llms/openai/openai.py:2111
organization=organization,
client=client,
_is_async=_is_async,
)
if openai_client is None:
raise ValueError(
"OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment."
)
if _is_async is True:
if not isinstance(openai_client, AsyncOpenAI):
raise ValueError(
"OpenAI client is not an instance of AsyncOpenAI. Make sure you passed an AsyncOpenAI client."
)
return self.acancel_batch(cancel_batch_data=cancel_batch_data, openai_client=openai_client)
# At this point, openai_client is guaranteed to be a sync OpenAI client
if not isinstance(openai_client, OpenAI):
raise ValueError("OpenAI client is not an instance of OpenAI. Make sure you passed a sync OpenAI client.")
response: Final = openai_client.batches.cancel(**cancel_batch_data)
return LiteLLMBatch.model_validate(response.model_dump())
async def alist_batches(
self,
openai_client: AsyncOpenAI,
after: str | None = None,
limit: int | None = None,
):
verbose_logger.debug("listing batches, after= %s, limit= %s", after, limit)
response: Final = await openai_client.batches.list(after=after, limit=limit)
return response
def list_batches(
self,
_is_async: bool,
api_key: str | None,
api_base: str | None,View on GitHub (pinned to 77b7c6c40c)
Solutions
- Pass a sync OpenAI client instance for synchronous calls.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at litellm/llms/openai/openai.py:2111 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/2b1d855fec9c572c.
Report an issue: GitHub.