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

Fork a stored Live session over WebSocket. Send session.start with an overrides object (which may be empty), then wait for session.started. The model is inherited.

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

Connect

import asyncio
from openai import AsyncOpenAI


async def observe() -> None:
    # Use the ID of a stored, closed Live session whose recording has finalized.
    async with AsyncOpenAI() as client:
        async with client.live.forks.connect(session_id="sess_123") as connection:
            await connection.session.start(session={})
            close_requested = False
            async for event in connection:
                if event.type == "error":
                    raise RuntimeError("Live reported a session error.")
                if event.type == "session.started":
                    # Wait for startup before closing the session this example owns.
                    print("Session ready:", event.session.id, event.session.model)
                    await connection.session.close()
                    close_requested = True
                elif event.type == "session.closed":
                    if not close_requested or event.reason != "close_requested":
                        raise RuntimeError(
                            f"Session ended unexpectedly: {event.reason}; usage={event.usage}"
                        )
                    print("Final usage:", event.usage)
                    return
            raise RuntimeError(
                "Connection closed before session.closed; final usage unconfirmed"
            )


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


asyncio.run(main())