Skip to content
For the complete documentation index, see llms.txt. Markdown versions of documentation pages are available by appending .md to the page URL.
Primary navigation

Connect

Attach to an existing Live session. Do not send session.start again.

WebSocket wss://api.openai.com/v1/live/sessions/{session_id}/attach

Connect

import asyncio
from openai import AsyncOpenAI


async def observe() -> None:
    # Use an eligible existing Live session ID owned by your project.
    async with AsyncOpenAI() as client:
        async with client.live.sideband.connect(session_id="sess_123") as connection:
            # Read existing-session updates. Releasing this observer does not end the session.
            async for event in connection:
                if event.type == "error":
                    raise RuntimeError("Live reported a session error.")
                if event.type == "session.usage.updated":
                    print("Current cumulative usage:", event.usage)
                    return
                elif event.type == "session.closed":
                    print("Final usage:", event.usage)
                    return
            raise RuntimeError(
                "Observer disconnected before a usage update or session.closed"
            )


async def main() -> None:
    # Stop waiting if the peer never sends the expected events.
    await asyncio.wait_for(observe(), timeout=60)


asyncio.run(main())