Full SDK reference
Full SDK reference.
API Reference
- errors
- __init__
- utils
- client
- types
- types.common
- types.webhooks
- types.realtime
- types.api
- ApiErrorValidationError
- ApiError
- GetFilesPayload
- File
- GetFilesResponse
- UploadFilePayload
- GetTranscriptionsPayload
- StructuredContextGeneralItem
- StructuredContextTranslationTerm
- StructuredContext
- TranslationConfig
- CreateTranscriptionPayload
- CreateTranscriptionConfig
- CreateTemporaryApiKeyPayload
- CreateTemporaryApiKeyResponse
- Language
- TranslationTarget
- Model
- GetModelsResponse
- TranscriptionTranscript
- Transcription
- GetTranscriptionsResponse
- api
- api.webhooks
- api.files
- api.async_files
- api.auth
- api.models
- api.async_webhooks
- api._utils
- api.async_auth
- api.async_transcriptions
- api.async_models
- api.transcriptions
- realtime
- realtime.stt
- realtime.async_stt
errors
SonioxError Objects
Base exception for the SDK.
SonioxValidationError Objects
Raised when Pydantic input validation fails on the client side.
SonioxAPIError Objects
Raised when the Soniox API replies with a non-2xx payload.
from_response
Parse an httpx.Response into a richer SDK error.
SonioxAuthenticationError Objects
Authentication failures (401/403).
SonioxInvalidRequestError Objects
Invalid request payloads (400).
SonioxNotFoundError Objects
Resource not found.
SonioxConflictError Objects
Conflict or invalid state (e.g., delete while processing).
SonioxRateLimitError Objects
Rate limit (429).
SonioxServerError Objects
5xx responses.
InvalidWebhookSignatureError Objects
Raised when a webhook signature cannot be validated.
SonioxRealtimeError Objects
Errors raised by realtime workflows.
__init__
utils
stream_audio
Yield fixed-size chunks from an audio source.
Supports bytes, file paths, or binary streams and slices them into
chunk_size_bytes blocks for realtime transmission.
stream_audio_async
Asynchronously yield fixed-size chunks from an audio source.
Mirrors stream_audio but produces an async iterator for later consumption.
throttle_audio
Yield audio chunks at a regulated pace, optionally sleeping between yields.
throttle_audio_async
Async counterpart of throttle_audio, yielding chunks with optional delay.
render_tokens
Build a human-friendly transcript from token metadata.
start_audio_thread
Stream audio into the session on a background thread.
start_keep_alive_thread
Start a background thread that periodically sends keep-alives to the session.
Returns:
A tuple of (thread, stop_event). Setting stop_event will stop the loop.
keep_alive_async
Async helper that repeatedly sends keep-alive messages until told to stop.
client
SonioxClient Objects
Synchronous Soniox REST client exposing API namespaces via httpx.
request
Perform a request against the configured Soniox REST endpoint.
close
Close the underlying HTTP transport.
AsyncSonioxClient Objects
Asynchronous Soniox REST client exposing HTTP and realtime helpers.
request
Perform a request against the configured Soniox REST endpoint.
aclose
Close any outstanding async HTTP connections.
types
types.common
Token Objects
Token metadata emitted during realtime streaming transcriptions.
types.webhooks
WebhookAuthConfig Objects
Configuration for webhook authentication headers.
WebhookEvent Objects
Basic webhook event metadata.
types.realtime
RealtimeEvent Objects
Event payload received from the realtime STT websocket.
RealtimeSTTConfig Objects
Configuration for initiating a realtime transcription session.
RealtimeControlType Objects
Control messages that can be sent over a realtime session.
RealtimeSessionOpenPayload Objects
Event emitted when a realtime websocket session opens.
RealtimeSessionClosePayload Objects
Event emitted when a realtime websocket session closes.
RealtimeSessionFinishedPayload Objects
Event emitted when a realtime session finishes processing.
RealtimeSessionErrorPayload Objects
Event emitted when a realtime session reports an error.
types.api
ApiErrorValidationError Objects
Details a single validation error reported by the Soniox API.
ApiError Objects
Structured representation of a non-2xx API response payload.
GetFilesPayload Objects
Parameters accepted by the file listing endpoint.
File Objects
Metadata describing an uploaded file in the Soniox API.
GetFilesResponse Objects
Paginated response returned when listing uploaded files.
UploadFilePayload Objects
Optional metadata supplied at upload time.
GetTranscriptionsPayload Objects
Parameters for listing transcription jobs.
StructuredContextGeneralItem Objects
Single general context key/value pair for transcription context.
StructuredContextTranslationTerm Objects
Defines a translation term mapping used in structured context.
StructuredContext Objects
Optional structured context provided to the transcription engine.
TranslationConfig Objects
Configuration describing how translation should be performed.
CreateTranscriptionPayload Objects
Payload sent to create an asynchronous transcription job.
CreateTranscriptionConfig Objects
Helper config used when building transcription payloads.
CreateTemporaryApiKeyPayload Objects
Payload for requesting a temporary API key (e.g., websocket).
CreateTemporaryApiKeyResponse Objects
Response data for a temp API key request.
Language Objects
Represents a supported language for transcription or translation.
TranslationTarget Objects
Describes translation targets offered by a model.
Model Objects
Describes a Soniox transcription model.
GetModelsResponse Objects
Response returned when listing available models.
TranscriptionTranscript Objects
Transcript data including the full text and tokens.
Transcription Objects
Represents a transcription job tracked by Soniox.
GetTranscriptionsResponse Objects
Paginated response for transcription listings.
api
api.webhooks
SonioxWebhooksAPI Objects
verify_signature
Verify a webhook signature from headers.
Raises:
InvalidWebhookSignatureError- When the webhook signature cannot be validated.
unwrap
Validate and parse a webhook payload.
Returns a WebhookEvent.
Raises:
InvalidWebhookSignatureError- When the webhook signature cannot be validated.
webhook_payload
Return fields for webhook configuration when creating a transcription.
api.files
FilesAPI Objects
list
List uploaded files.
Performs a GET request to /files with optional pagination.
Raises:
SonioxAPIError- When the API returns an error.
get
Retrieve a file by ID.
Performs a GET request to /files/{file_id}.
Raises:
SonioxAPIError- When the API returns an error.
get_or_none
Retrieve a file by ID.
Returns None if the file does not exist.
Raises:
SonioxAPIError- When the API returns an error.
delete
Delete a file by ID.
Performs a DELETE request to /files/{file_id}.
Raises:
SonioxAPIError- When the API returns an error.
delete_if_exists
Delete a file by ID if it exists.
Ignores missing files.
Raises:
SonioxAPIError- When the API returns an error.
upload
Upload a file.
Performs a multipart POST request to /files.
Raises:
SonioxAPIError- When the API returns an error.
delete_all
Delete all files.
Iterates through all pages and deletes each file.
Raises:
SonioxAPIError- When the API returns an error.
api.async_files
AsyncFilesAPI Objects
list
List uploaded files.
Performs a GET request to /files with optional pagination.
Raises:
SonioxAPIError- When the API returns an error.
get
Retrieve a file by ID.
Performs a GET request to /files/{file_id}.
Raises:
SonioxAPIError- When the API returns an error.
get_or_none
Retrieve a file by ID.
Returns None if the file does not exist.
Raises:
SonioxAPIError- When the API returns an error.
delete
Delete a file by ID.
Performs a DELETE request to /files/{file_id}.
Raises:
SonioxAPIError- When the API returns an error.
delete_if_exists
Delete a file by ID if it exists.
Ignores missing files.
Raises:
SonioxAPIError- When the API returns an error.
upload
Upload a file.
Performs a multipart POST request to /files.
Raises:
SonioxAPIError- When the API returns an error.
delete_all
Delete all files.
Iterates through all pages and deletes each file.
Raises:
SonioxAPIError- When the API returns an error.
api.auth
AuthAPI Objects
create_temporary_api_key
Create a temporary API key.
Performs a POST request to /auth/temporary-api-key.
Raises:
SonioxAPIError- When the API returns an error.
api.models
ModelsAPI Objects
list
List available models.
Performs a GET request to /models.
Raises:
SonioxAPIError- When the API returns an error.
api.async_webhooks
api._utils
normalize_file
Return (file-like, filename, should_close) tuple for upload.
api.async_auth
AsyncAuthAPI Objects
create_temporary_api_key
Create a temporary API key.
Performs a POST request to /auth/temporary-api-key.
Raises:
SonioxAPIError- When the API returns an error.
api.async_transcriptions
AsyncTranscriptionsAPI Objects
list
List transcriptions.
Performs a GET request to /transcriptions with optional pagination.
Raises:
SonioxAPIError- When the API returns an error.
delete_all
Delete all transcriptions.
Iterates through all pages and deletes each transcription.
Raises:
SonioxAPIError- When the API returns an error.
create
Create a transcription.
Performs a POST request to /transcriptions.
Raises:
SonioxAPIError- When the API returns an error.
get
Retrieve a transcription by ID.
Performs a GET request to /transcriptions/{transcription_id}.
Raises:
SonioxAPIError- When the API returns an error.
get_or_none
Retrieve a transcription by ID.
Returns None if the transcription does not exist.
Raises:
SonioxAPIError- When the API returns an error.
delete
Delete a transcription by ID.
Performs a DELETE request to /transcriptions/{transcription_id}.
Raises:
SonioxAPIError- When the API returns an error.
delete_if_exists
Delete a transcription by ID if it exists.
Ignores missing transcriptions.
Raises:
SonioxAPIError- When the API returns an error.
destroy
Delete a transcription and its associated uploaded file.
Raises:
SonioxAPIError- When the API returns an error.
get_transcript
Retrieve the transcript for a transcription.
Performs a GET request to /transcriptions/{transcription_id}/transcript.
Raises:
SonioxAPIError- When the API returns an error.
wait
Poll a transcription until it leaves the queued or processing state.
Raises:
SonioxAPIError- When the API returns an error.TimeoutError- Waiting for the transcription to finish exceededtimeout_sec.
transcribe_from_url
Create a transcription from an audio URL.
Raises:
SonioxAPIError- When the API returns an error.
transcribe_from_file_id
Create a transcription from an existing uploaded file.
Raises:
SonioxAPIError- When the API returns an error.
transcribe_from_file
Upload a file and create a transcription from it.
Raises:
SonioxAPIError- When the API returns an error.
transcribe
Create a transcription from a file, file ID, or audio URL.
Validates mutually exclusive inputs before submission.
Raises:
SonioxAPIError- When the API returns an error.SonioxValidationError- When the payload fails validation.
transcribe_file_with_webhook
Upload a file, configure a webhook, and start transcription.
Raises:
SonioxAPIError- When the API returns an error.
transcribe_and_wait
Create a transcription and wait for completion.
Returns a Transcription object after it is completed. Optionally deletes the transcription and the uploaded file after completion.
Raises:
SonioxAPIError- When the API returns an error.SonioxValidationError- When the payload fails validation.TimeoutError- Waiting for the transcription to finish exceededtimeout_sec.
transcribe_and_wait_with_tokens
Create a transcription, wait for completion, and return the transcript.
Optionally deletes the transcription and uploaded file after completion.
Raises:
SonioxAPIError- When the API returns an error.SonioxValidationError- When the payload fails validation.TimeoutError- Waiting for the transcription to finish exceededtimeout_sec.
api.async_models
AsyncModelsAPI Objects
list
List available models.
Performs a GET request to /models.
Raises:
SonioxAPIError- When the API returns an error.
api.transcriptions
TranscriptionsAPI Objects
list
List transcriptions.
Performs a GET request to /transcriptions with optional pagination.
Raises:
SonioxAPIError- When the API returns an error.
delete_all
Delete all transcriptions.
Iterates through all pages and deletes each transcription.
Raises:
SonioxAPIError- When the API returns an error.
create
Create a transcription.
Performs a POST request to /transcriptions.
Raises:
SonioxAPIError- When the API returns an error.
get
Retrieve a transcription by ID.
Performs a GET request to /transcriptions/{transcription_id}.
Raises:
SonioxAPIError- When the API returns an error.
get_or_none
Retrieve a transcription by ID.
Returns None if the transcription does not exist.
Raises:
SonioxAPIError- When the API returns an error.
delete
Delete a transcription by ID.
Performs a DELETE request to /transcriptions/{transcription_id}.
Raises:
SonioxAPIError- When the API returns an error.
delete_if_exists
Delete a transcription by ID if it exists.
Ignores missing transcriptions.
Raises:
SonioxAPIError- When the API returns an error.
destroy
Delete a transcription and its associated uploaded file.
Raises:
SonioxAPIError- When the API returns an error.
get_transcript
Retrieve the transcript for a transcription.
Performs a GET request to /transcriptions/{transcription_id}/transcript.
Raises:
SonioxAPIError- When the API returns an error.
wait
Poll a transcription until it leaves the queued or processing state.
Raises:
SonioxAPIError- When the API returns an error.TimeoutError- Waiting for the transcription to finish exceededtimeout_sec.
transcribe_from_url
Create a transcription from an audio URL.
Raises:
SonioxAPIError- When the API returns an error.
transcribe_from_file_id
Create a transcription from an existing uploaded file.
Raises:
SonioxAPIError- When the API returns an error.
transcribe_from_file
Upload a file and create a transcription from it.
Raises:
SonioxAPIError- When the API returns an error.
transcribe
Create a transcription from a file, file ID, or audio URL.
Validates mutually exclusive inputs before submission.
Raises:
SonioxAPIError- When the API returns an error.SonioxValidationError- When the payload fails validation.
transcribe_file_with_webhook
Upload a file, configure a webhook, and start transcription.
Raises:
SonioxAPIError- When the API returns an error.
transcribe_and_wait
Create a transcription and wait for completion.
Returns a Transcription object after it is completed. Optionally deletes the transcription and the uploaded file after completion.
Raises:
SonioxAPIError- When the API returns an error.SonioxValidationError- When the payload fails validation.TimeoutError- Waiting for the transcription to finish exceededtimeout_sec.
transcribe_and_wait_with_tokens
Create a transcription, wait for completion, and return the transcript.
Optionally deletes the transcription and uploaded file after completion.
Raises:
SonioxAPIError- When the API returns an error.SonioxValidationError- When the payload fails validation.TimeoutError- Waiting for the transcription to finish exceededtimeout_sec.
realtime
AsyncRealtimeAPI Objects
Entrypoint for async realtime helpers on AsyncSonioxClient.
RealtimeAPI Objects
Entrypoint for realtime helpers on SonioxClient.
realtime.stt
RealtimeSTTSession Objects
Synchronous WebSocket session for a single real-time speech-to-text stream.
This class manages the full lifecycle of a real-time transcription session: connecting to the WebSocket endpoint, streaming audio data, receiving events, and gracefully closing the stream. A session is stateful and represents exactly one streaming interaction with the Soniox realtime API.
Instances are designed to be used as context managers.
__init__
Create a new realtime STT session.
This does not open a network connection. The WebSocket connection is established when entering the context manager.
Arguments:
url: WebSocket URL for the realtime transcription endpoint. config: Configuration describing the audio format and transcription behavior for this session.
config
Return the configuration used to initialize this session.
__enter__
Open the WebSocket connection and start the realtime session.
The session configuration is sent immediately after connecting. If any step fails, the connection is closed and a SonioxRealtimeError is raised.
Returns:
The active realtime session instance.
Raises:
SonioxRealtimeError: If the WebSocket connection or session initialization fails.
__exit__
Close the realtime session and release network resources.
This method is called automatically when exiting the context manager.
close
Gracefully close the realtime session.
Sends a final empty message to signal end-of-stream, then closes the WebSocket connection. Calling this method multiple times is safe.
send_byte_chunk
Send a single chunk of raw audio bytes to the realtime stream.
The audio data must match the format declared in the session configuration (sample rate, channels, encoding).
Arguments:
chunk: Raw audio bytes to send.
Raises:
SonioxRealtimeError: If the session is not connected or the send operation fails.
send_bytes
Send audio data to the realtime stream.
This method accepts either a single bytes object or an iterator yielding audio chunks. When an iterator is provided, a FINISH control message is sent automatically after all chunks have been transmitted.
Arguments:
chunks: Audio data as raw bytes or an iterator of byte chunks.
send_control_message
Send a control message to the realtime session.
Control messages modify the state of the stream, such as signaling end-of-audio or requesting finalization.
Arguments:
control_type: The type of control message to send.
Raises:
SonioxRealtimeError: If the session is not connected or the message cannot be sent.
send_finish
Signal that no more audio will be sent for this session.
send_keep_alive
Send a keep-alive message to prevent the session from timing out.
send_finalize
Finalize all outstanding non-final tokens while keeping the session open.
Subsequent tokens will be delivered with is_final=True.
recv_bytes
Receive a raw message from the WebSocket connection.
Returns:
The received message as bytes. An empty bytes object indicates that the connection has been closed.
parse_event
Parse a raw WebSocket message into a structured realtime event.
Arguments:
raw: Raw message payload received from the server.
Returns:
A validated RealtimeEvent instance.
last_message
Return the most recently received realtime event, if any.
receive_event
Receive and parse the next realtime event from the server.
Returns:
The next RealtimeEvent, or None if the connection has closed.
Raises:
SonioxRealtimeError: If the session is not connected.
receive_events
Yield realtime events as they are received from the server.
Iteration stops automatically when the connection is closed.
handle_events
Receive realtime events and dispatch them to a handler callback.
Arguments:
handler: Callable invoked for each received RealtimeEvent.
RealtimeSTTClient Objects
Factory for creating synchronous realtime speech-to-text sessions.
This class validates credentials and prepares session configuration, but does not itself manage WebSocket connections.
__init__
Create a realtime STT client bound to an existing API client.
Arguments:
client: Parent Soniox client providing configuration and credentials.
connect
Create a new realtime STT session.
The returned session is not connected until entered as a context manager.
Arguments:
config: Realtime transcription configuration. api_key: Optional API key override. If not provided, the client's default API key is used.
Returns:
A new RealtimeSTTSession instance.
Raises:
SonioxValidationError: If no API key is available.
realtime.async_stt
AsyncRealtimeSTTSession Objects
Asynchronous WebSocket session for a single real-time speech-to-text stream.
This class manages the full lifecycle of a real-time transcription session: connecting to the WebSocket endpoint, streaming audio data, receiving events, and gracefully closing the stream. A session is stateful and represents exactly one streaming interaction with the Soniox realtime API.
Instances are designed to be used as async context managers.
__init__
Create a new realtime STT session.
This does not open a network connection. The WebSocket connection is established when entering the async context manager.
Arguments:
url: WebSocket URL for the realtime transcription endpoint. config: Configuration describing the audio format and transcription behavior for this session.
config
Return the configuration used to initialize this session.
__aenter__
Open the WebSocket connection and start the realtime session.
The session configuration is sent immediately after connecting. If any step fails, the connection is closed and a SonioxRealtimeError is raised.
Returns:
The active realtime session instance.
Raises:
SonioxRealtimeError: If the WebSocket connection or session initialization fails.
__aexit__
Close the realtime session and release network resources.
This method is called automatically when exiting the async context manager.
close
Gracefully close the realtime session.
Sends a final empty message to signal end-of-stream, then closes the WebSocket connection. Calling this method multiple times is safe.
send_byte_chunk
Send a single chunk of raw audio bytes to the realtime stream.
The audio data must match the format declared in the session configuration (sample rate, channels, encoding).
Arguments:
chunk: Raw audio bytes to send.
Raises:
SonioxRealtimeError: If the session is not connected or the send operation fails.
send_bytes
Send audio data to the realtime stream.
This method accepts either a single bytes object or an iterator yielding audio chunks. When an iterator is provided, a FINISH control message is sent automatically after all chunks have been transmitted.
Arguments:
chunks: Audio data as raw bytes or an iterator of byte chunks.
send_control_message
Send a control message to the realtime session.
Control messages modify the state of the stream, such as signaling end-of-audio or requesting finalization.
Arguments:
control_type: The type of control message to send.
Raises:
SonioxRealtimeError: If the session is not connected or the message cannot be sent.
send_finish
Signal that no more audio will be sent for this session.
send_keep_alive
Send a keep-alive message to prevent the session from timing out.
send_finalize
Finalize all outstanding non-final tokens while keeping the session open.
Subsequent tokens will be delivered with is_final=True.
recv_bytes
Receive a raw message from the WebSocket connection.
Returns:
The received message as bytes. An empty bytes object indicates that the connection has been closed.
parse_event
Parse a raw WebSocket message into a structured realtime event.
Arguments:
raw: Raw message payload received from the server.
Returns:
A validated RealtimeEvent instance.
last_message
Return the most recently received realtime event, if any.
receive_event
Receive and parse the next realtime event from the server.
Returns:
The next RealtimeEvent, or None if the connection has closed.
Raises:
SonioxRealtimeError: If the session is not connected.
receive_events
Yield realtime events as they are received from the server.
Iteration stops automatically when the connection is closed.
handle_events
Receive realtime events and dispatch them to a handler callback.
Arguments:
handler: Callable invoked for each received RealtimeEvent.
AsyncRealtimeSTTClient Objects
Factory for creating asynchronous realtime speech-to-text sessions.
This class validates credentials and prepares session configuration, but does not itself manage WebSocket connections.
__init__
Create a realtime STT client bound to an existing API client.
Arguments:
client: Parent Soniox client providing configuration and credentials.
connect
Create a new realtime STT session.
The returned session is not connected until entered as an async context manager.
Arguments:
config: Realtime transcription configuration. api_key: Optional API key override. If not provided, the client's default API key is used.
Returns:
A new AsyncRealtimeSTTSession instance.
Raises:
SonioxValidationError: If no API key is available.