Skip to main content
Managed streaming sessions. No reconnect, replay, or unbounded application queues.

StreamingSession

Synchronous session; use as a context manager and iterate events in one thread. Send audio from another thread while iterating to receive provisional updates. commit and update send control messages; consume the corresponding acknowledgement before sending the next turn. finish requests a graceful end; keep iterating until session.closed. Context exit always closes the socket.
  • Parameters:
    • url (str)
    • credential (str)
    • state (_State)

ready

Negotiated limits, available after entering the context.

send_audio()

Send one raw PCM16 message, applying the server-advertised limits.
  • Parameters: audio (bytes)
  • Return type: None

commit()

Complete the turn; consume decision.finalized before sending more audio.
  • Return type: None

update()

Replace context and question between turns; consume session.updated.

finish()

Request finalization and graceful closure; continue consuming events.
  • Return type: None

__next__()

Return the next item from the iterator. When exhausted, raise StopIteration

close()

Close immediately without replaying or cancelling accepted durable work.
  • Return type: None

AsyncStreamingSession

Async context manager and event iterator. Use a concurrent audio-sending task. No background reader is created. The websocket’s bounded receive queue supplies backpressure. One task may receive while another sends. Cancelled operations close the socket; accepted durable evaluations may still finish.
  • Parameters:
    • url (str)
    • credential (str)
    • state (_State)

ready

Negotiated limits, available after entering the context.

send_audio()

Send one PCM16 message; the send applies transport backpressure.
  • Parameters: audio (bytes)
  • Return type: None

commit()

Complete the turn; await decision.finalized through the iterator.
  • Return type: None

update()

Replace state and questions; await session.updated through the iterator.

finish()

Request a graceful end; continue iterating until session.closed.
  • Return type: None

__anext__()

Return the next item or raise StopAsyncIteration when exhausted.

close()

Close immediately. It does not cancel already accepted evaluations.
  • Return type: None