Async Client
Soniox Python SDK - Async Client Reference
AsyncSonioxClient
Asynchronous Soniox REST client exposing HTTP and realtime helpers.
Constructor
Parameters
| Parameter | Type | Description |
|---|---|---|
api_key | str | None | API key used for authentication. |
api_base_url | str | None | Base URL for Soniox REST API requests. |
websocket_base_url | str | None | Base URL for Soniox realtime WebSocket endpoint. |
timeout_sec | float | None | Maximum wait time in seconds. |
webhook_secret | str | None | Webhook secret used for signature verification. |
webhook_signature_header | str | None | Webhook signature header name. |
client_kwargs | Any | Additional HTTP client keyword arguments. |
Returns
None
Properties
| Property | Type | Description |
|---|---|---|
files | AsyncFilesAPI | List of uploaded files. |
stt | AsyncSttAPI | Speech-to-text API namespace. |
models | AsyncModelsAPI | List of all available models. |
auth | AsyncAuthAPI | Authentication API namespace. |
webhooks | AsyncSonioxWebhooksAPI | Webhook utilities API namespace. |
realtime | AsyncRealtimeAPI | Entrypoint for async realtime helpers on AsyncSonioxClient. |
request()
Perform a request against the configured Soniox REST endpoint.
Parameters
| Parameter | Type | Description |
|---|---|---|
method | str | HTTP method to use for the request. |
path | str | Relative API path for the request. |
params | Mapping[str, Any] | None | Query parameters for the request. |
json | Any | None | JSON request payload. |
data | Mapping[str, Any] | None | Form-encoded request payload. |
files | Mapping[str, Any] | None | Multipart file payload mapping. |
Returns
httpx.Response
aclose()
Close any outstanding async HTTP connections.
Returns
None
AsyncFilesAPI
Constructor
Parameters
| Parameter | Type | Description |
|---|---|---|
client | AsyncSonioxClient | Soniox client instance. |
Returns
None
list()
List uploaded files.
Performs a GET request to /files with optional pagination.
Parameters
| Parameter | Type | Description |
|---|---|---|
limit | int | Maximum number of files to return. |
cursor | str | None | Pagination cursor for the next page of results. |
Returns
GetFilesResponse
Raises
SonioxAPIErrorWhen the API returns an error.
list_all()
Iterate through all uploaded files across all pages.
Parameters
| Parameter | Type | Description |
|---|---|---|
limit | int | Maximum number of files to return. |
Yields
AsyncGenerator[File, None]
File: The next file object from the API.
Raises
SonioxAPIErrorWhen the API returns an error.
get()
Retrieve a file by ID.
Performs a GET request to /files/{file_id}.
Parameters
| Parameter | Type | Description |
|---|---|---|
file_id | str | ID of a previously uploaded file. |
Returns
File
Raises
SonioxAPIErrorWhen the API returns an error.
get_or_none()
Retrieve a file by ID.
Returns None if the file does not exist.
Parameters
| Parameter | Type | Description |
|---|---|---|
file_id | str | ID of a previously uploaded file. |
Returns
File | None
Raises
SonioxAPIErrorWhen the API returns an error.
delete()
Delete a file by ID.
Performs a DELETE request to /files/{file_id}.
Parameters
| Parameter | Type | Description |
|---|---|---|
file_id | str | ID of a previously uploaded file. |
Returns
None
Raises
SonioxAPIErrorWhen the API returns an error.
delete_if_exists()
Delete a file by ID if it exists.
Ignores missing files.
Parameters
| Parameter | Type | Description |
|---|---|---|
file_id | str | ID of a previously uploaded file. |
Returns
None
Raises
SonioxAPIErrorWhen the API returns an error.
upload()
Upload a file.
Performs a multipart POST request to /files.
Parameters
| Parameter | Type | Description |
|---|---|---|
file | BinaryIO | bytes | Path | str | File input to upload or transcribe. |
filename | str | None | Filename associated with uploaded file data. |
client_reference_id | str | None | Optional tracking identifier string. Does not need to be unique |
Returns
File
Raises
SonioxAPIErrorWhen the API returns an error.
delete_all()
Delete all files.
Iterates through all pages and deletes each file. Stops and raises on the first failed deletion.
Parameters
| Parameter | Type | Description |
|---|---|---|
limit | int | Maximum number of files to return. |
Returns
None
Raises
SonioxAPIErrorWhen the API returns an error.
AsyncSttAPI
Constructor
Parameters
| Parameter | Type | Description |
|---|---|---|
client | AsyncSonioxClient | Soniox client instance. |
Returns
None
list()
List transcriptions.
Performs a GET request to /transcriptions with optional pagination.
Parameters
| Parameter | Type | Description |
|---|---|---|
limit | int | Maximum number of transcriptions to return. |
cursor | str | None | Pagination cursor for the next page of results. |
Returns
GetTranscriptionsResponse
Raises
SonioxAPIErrorWhen the API returns an error.
list_all()
Iterate through all transcriptions across all pages.
Parameters
| Parameter | Type | Description |
|---|---|---|
limit | int | Maximum number of transcriptions to return. |
Yields
AsyncGenerator[Transcription, None]
File: The next transcription object from the API.
Raises
SonioxAPIErrorWhen the API returns an error.
delete_all()
Delete all transcriptions.
Iterates through all pages and deletes each transcription. Stops and raises on the first failed deletion.
Parameters
| Parameter | Type | Description |
|---|---|---|
limit | int | Maximum number of transcriptions to return. |
Returns
None
Raises
SonioxAPIErrorWhen the API returns an error.
create()
Create a transcription.
Performs a POST request to /transcriptions.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | str | Speech-to-text model to use. |
file_id | str | None | ID of a previously uploaded file. |
audio_url | str | None | Publicly accessible audio URL. |
client_reference_id | str | None | Optional tracking identifier. |
config | CreateTranscriptionConfig | None | Configuration options for this operation. |
Returns
Transcription
Raises
SonioxAPIErrorWhen the API returns an error.
get()
Retrieve a transcription by ID.
Performs a GET request to /transcriptions/{transcription_id}.
Parameters
| Parameter | Type | Description |
|---|---|---|
transcription_id | str | Transcription identifier. |
Returns
Transcription
Raises
SonioxAPIErrorWhen the API returns an error.
get_or_none()
Retrieve a transcription by ID.
Returns None if the transcription does not exist.
Parameters
| Parameter | Type | Description |
|---|---|---|
transcription_id | str | Transcription identifier. |
Returns
Transcription | None
Raises
SonioxAPIErrorWhen the API returns an error.
delete()
Delete a transcription by ID.
Performs a DELETE request to /transcriptions/{transcription_id}.
Parameters
| Parameter | Type | Description |
|---|---|---|
transcription_id | str | Transcription identifier. |
Returns
None
Raises
SonioxAPIErrorWhen the API returns an error.
delete_if_exists()
Delete a transcription by ID if it exists.
Ignores missing transcriptions.
Parameters
| Parameter | Type | Description |
|---|---|---|
transcription_id | str | Transcription identifier. |
Returns
None
Raises
SonioxAPIErrorWhen the API returns an error.
destroy()
Delete a transcription and its associated uploaded file.
Parameters
| Parameter | Type | Description |
|---|---|---|
transcription_id | str | Transcription identifier. |
Returns
None
Raises
SonioxAPIErrorWhen the API returns an error.
destroy_all()
Delete all transcriptions and their associated files. Stops and raises on the first failed deletion.
Parameters
| Parameter | Type | Description |
|---|---|---|
limit | int | Maximum number of transcriptions to return. |
Returns
None
Raises
SonioxAPIErrorWhen the API returns an error during listing.
get_transcript()
Retrieve the transcript for a transcription.
Performs a GET request to /transcriptions/{transcription_id}/transcript.
Parameters
| Parameter | Type | Description |
|---|---|---|
transcription_id | str | Transcription identifier. |
Returns
TranscriptionTranscript
Raises
SonioxAPIErrorWhen the API returns an error.
wait()
Poll a transcription until it leaves the queued or processing state.
Parameters
| Parameter | Type | Description |
|---|---|---|
transcription_id | str | Transcription identifier. |
interval_sec | float | Polling interval in seconds. |
timeout_sec | float | None | Maximum wait time in seconds. |
Returns
Transcription
Raises
SonioxAPIErrorWhen the API returns an error.TimeoutErrorWaiting for the transcription to finish exceededtimeout_sec.
transcribe_from_url()
Create a transcription from an audio URL.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | str | Speech-to-text model to use. |
audio_url | str | Publicly accessible audio URL. |
client_reference_id | str | None | Optional tracking identifier. |
config | CreateTranscriptionConfig | None | Configuration options for this operation. |
Returns
Transcription
Raises
SonioxAPIErrorWhen the API returns an error.
transcribe_from_file_id()
Create a transcription from an existing uploaded file.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | str | Speech-to-text model to use. |
file_id | str | ID of a previously uploaded file. |
client_reference_id | str | None | Optional tracking identifier. |
config | CreateTranscriptionConfig | None | Configuration options for this operation. |
Returns
Transcription
Raises
SonioxAPIErrorWhen the API returns an error.
transcribe_from_file()
Upload a file and create a transcription from it.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | str | Speech-to-text model to use. |
file | BinaryIO | bytes | Path | str | File input to upload or transcribe. |
filename | str | None | Filename associated with uploaded file data. |
client_reference_id | str | None | Optional tracking identifier. |
config | CreateTranscriptionConfig | None | Configuration options for this operation. |
Returns
Transcription
Raises
SonioxAPIErrorWhen the API returns an error.
transcribe()
Create a transcription from a file, file ID, or audio URL.
Validates mutually exclusive inputs before submission.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | str | Speech-to-text model to use. |
audio_url | str | None | Publicly accessible audio URL. |
file_id | str | None | ID of a previously uploaded file. |
file | BinaryIO | bytes | Path | str | None | File input to upload or transcribe. |
filename | str | None | Filename associated with uploaded file data. |
client_reference_id | str | None | Optional tracking identifier. |
config | CreateTranscriptionConfig | None | Configuration options for this operation. |
Returns
Transcription
Raises
SonioxAPIErrorWhen the API returns an error.SonioxValidationErrorWhen the payload fails validation.
transcribe_file_with_webhook()
Upload a file, configure a webhook, and start transcription.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | str | Speech-to-text model to use. |
file | BinaryIO | bytes | Path | str | File input to upload or transcribe. |
webhook_url | str | URL to receive webhook notifications. |
filename | str | None | Filename associated with uploaded file data. |
client_reference_id | str | None | Optional tracking identifier. |
webhook_auth | WebhookAuthConfig | None | Webhook authentication configuration. |
config | CreateTranscriptionConfig | None | Configuration options for this operation. |
Returns
Transcription
Raises
SonioxAPIErrorWhen 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.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | str | Speech-to-text model to use. |
audio_url | str | None | Publicly accessible audio URL. |
file_id | str | None | ID of a previously uploaded file. |
file | BinaryIO | bytes | Path | str | None | File input to upload or transcribe. |
filename | str | None | Filename associated with uploaded file data. |
client_reference_id | str | None | Optional tracking identifier. |
delete_after | bool | Whether to delete created resources after completion. |
wait_interval_sec | float | Polling interval in seconds while waiting. |
wait_timeout_sec | float | None | Maximum wait time in seconds while polling. |
config | CreateTranscriptionConfig | None | Configuration options for this operation. |
Returns
Transcription
Raises
SonioxAPIErrorWhen the API returns an error.SonioxValidationErrorWhen the payload fails validation.TimeoutErrorWaiting 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.
Parameters
| Parameter | Type | Description |
|---|---|---|
model | str | Speech-to-text model to use. |
audio_url | str | None | Publicly accessible audio URL. |
file_id | str | None | ID of a previously uploaded file. |
file | BinaryIO | bytes | Path | str | None | File input to upload or transcribe. |
filename | str | None | Filename associated with uploaded file data. |
client_reference_id | str | None | Optional tracking identifier. |
delete_after | bool | Whether to delete created resources after completion. |
wait_interval_sec | float | Polling interval in seconds while waiting. |
wait_timeout_sec | float | None | Maximum wait time in seconds while polling. |
config | CreateTranscriptionConfig | None | Configuration options for this operation. |
Returns
TranscriptionTranscript
Raises
SonioxAPIErrorWhen the API returns an error.SonioxValidationErrorWhen the payload fails validation.TimeoutErrorWaiting for the transcription to finish exceededtimeout_sec.
AsyncModelsAPI
Constructor
Parameters
| Parameter | Type | Description |
|---|---|---|
client | AsyncSonioxClient | Soniox client instance. |
Returns
None
list()
List available models.
Performs a GET request to /models.
Returns
GetModelsResponse
Raises
SonioxAPIErrorWhen the API returns an error.
AsyncAuthAPI
Constructor
Parameters
| Parameter | Type | Description |
|---|---|---|
client | AsyncSonioxClient | Soniox client instance. |
Returns
None
create_temporary_api_key()
Create a temporary API key.
Performs a POST request to /auth/temporary-api-key.
Parameters
| Parameter | Type | Description |
|---|---|---|
usage_type | TemporaryApiKeyUsageType | Intended usage of the temporary API key. |
expires_in_seconds | int | Duration in seconds until the temporary API key expires |
client_reference_id | str | None | Optional tracking identifier string. Does not need to be unique |
Returns
CreateTemporaryApiKeyResponse
Raises
SonioxAPIErrorWhen the API returns an error.