{"record":{"id":"2b1d855fec9c572c","repo":"BerriAI/litellm","slug":"openai-client-is-not-an-instance-of-openai-make-s","errorCode":null,"errorMessage":"OpenAI client is not an instance of OpenAI. Make sure you passed a sync OpenAI client.","messagePattern":"OpenAI client is not an instance of OpenAI\\. Make sure you passed a sync OpenAI client\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/openai/openai.py","lineNumber":2111,"sourceCode":"            organization=organization,\n            client=client,\n            _is_async=_is_async,\n        )\n        if openai_client is None:\n            raise ValueError(\n                \"OpenAI client is not initialized. Make sure api_key is passed or OPENAI_API_KEY is set in the environment.\"\n            )\n\n        if _is_async is True:\n            if not isinstance(openai_client, AsyncOpenAI):\n                raise ValueError(\n                    \"OpenAI client is not an instance of AsyncOpenAI. Make sure you passed an AsyncOpenAI client.\"\n                )\n            return self.acancel_batch(cancel_batch_data=cancel_batch_data, openai_client=openai_client)\n\n        # At this point, openai_client is guaranteed to be a sync OpenAI client\n        if not isinstance(openai_client, OpenAI):\n            raise ValueError(\"OpenAI client is not an instance of OpenAI. Make sure you passed a sync OpenAI client.\")\n        response: Final = openai_client.batches.cancel(**cancel_batch_data)\n        return LiteLLMBatch.model_validate(response.model_dump())\n\n    async def alist_batches(\n        self,\n        openai_client: AsyncOpenAI,\n        after: str | None = None,\n        limit: int | None = None,\n    ):\n        verbose_logger.debug(\"listing batches, after= %s, limit= %s\", after, limit)\n        response: Final = await openai_client.batches.list(after=after, limit=limit)\n        return response\n\n    def list_batches(\n        self,\n        _is_async: bool,\n        api_key: str | None,\n        api_base: str | None,","sourceCodeStart":2093,"sourceCodeEnd":2129,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/openai/openai.py#L2093-L2129","documentation":"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.","triggerScenarios":"Thrown at litellm/llms/openai/openai.py:2111 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Pass a sync OpenAI client instance for synchronous calls."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}