Skip to content

OpenAI Async TypeError #233

@pnmueller-quattec

Description

@pnmueller-quattec

When using the PostHog AsyncOpenAI client (from posthog.ai.openai import AsyncOpenAI) with streaming=True in self.client.chat.completions.create(), the following error occurs:

  File "/usr/local/lib/python3.12/site-packages/posthog/ai/openai/openai_async.py", line 308, in async_generator
    await self._capture_streaming_event(
  File "/usr/local/lib/python3.12/site-packages/posthog/ai/openai/openai_async.py", line 370, in _capture_streaming_event
    await self._client._ph_client.capture(
TypeError: object tuple can't be used in 'await' expression

It seems like the file contains two separate cases where self._client._ph_client.capture is awaited (and one where it isn't) even though the method is synchronous, not asynchronous. I've cross-checked this with AsyncAnthropic where the same method is correctly not being awaited.

Unless I'm missing something, removing the two awaits in posthog/ai/openai/openai_async.py should fix the issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions