mistral_common.protocol.transcription.request
StreamingMode
Streaming behavior for a transcription request.
Attributes:
| Name | Type | Description |
|---|---|---|
DISABLED |
No streaming; the full transcript is returned once complete. |
|
ONLINE |
Audio is streamed to the server and the transcription is streamed back incrementally. |
|
OFFLINE |
Audio is sent in one go and the transcription is streamed back. |
TranscriptionRequest(**data)
Bases: BaseCompletionRequest
A request for audio transcription.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str | None
|
Optional identifier for this transcription request. |
model |
str | None
|
The model to use for transcription. If |
audio |
str | bytes
|
Audio data to transcribe. Either raw audio bytes or a base64-encoded string (decoded automatically). |
language |
LanguageAlpha2 | None
|
Language of the input audio in ISO-639-1 format (e.g., "en"). If provided, improves language adherence of the transcript. |
strict_audio_validation |
bool
|
If |
streaming |
StreamingMode
|
The streaming mode for the request. See StreamingMode. |
target_streaming_delay_ms |
int | None
|
When streaming is enabled, the target delay in milliseconds between hearing a word and producing its transcript. This is a request, not a guarantee; unsupported models ignore it. |
Source code in pydantic/main.py
from_openai(openai_request, strict=False)
classmethod
Create a TranscriptionRequest from an OpenAI request dictionary.
The "file" entry is read (BytesIO or file-like object with a .file attribute), decoded via Audio, and re-encoded as a base64 string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_request
|
dict[str, Any]
|
Dictionary matching OpenAI's transcription request schema. Must contain a "file" entry. |
required |
strict
|
bool
|
If |
False
|
Returns:
| Type | Description |
|---|---|
TranscriptionRequest
|
A TranscriptionRequest instance with the audio base64-encoded. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If no "file" entry is present. |
Source code in src/mistral_common/protocol/transcription/request.py
to_openai(exclude=(), **kwargs)
Convert the transcription request into the OpenAI format.
Audio is converted into an in-memory file buffer with the correct format extension, and mistral-specific fields are dropped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude
|
tuple
|
Extra field names to exclude from the output, in addition to
the mistral-specific defaults ("id", |
()
|
kwargs
|
Any
|
Additional OpenAI parameters merged into the output. |
{}
|
Returns:
| Type | Description |
|---|---|
dict[str, list[dict[str, Any]]]
|
The request in the OpenAI format, with the audio under the "file" key |
dict[str, list[dict[str, Any]]]
|
and |
Raises:
| Type | Description |
|---|---|
ImportError
|
If soundfile is not installed. |