mistral_common.protocol.instruct.chunk
AudioChunk(**data)
Bases: BaseContentChunk
Audio content provided inline as base64 or raw bytes.
Attributes:
| Name | Type | Description |
|---|---|---|
input_audio |
str | bytes
|
The audio data as a base64-encoded string (optionally
with a data:audio/ |
Examples:
Source code in pydantic/main.py
from_audio(audio)
classmethod
Create an AudioChunk instance from an Audio object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
Audio
|
An Audio object containing audio data. |
required |
Returns:
| Type | Description |
|---|---|
AudioChunk
|
An AudioChunk instance initialized with the audio data. |
Source code in src/mistral_common/protocol/instruct/chunk.py
from_openai(openai_chunk)
classmethod
Convert the OpenAI chunk to the Mistral format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_chunk
|
dict[str, Any]
|
A dictionary representing the audio chunk in the OpenAI format. |
required |
Returns:
| Type | Description |
|---|---|
AudioChunk
|
An AudioChunk instance initialized with the data from the OpenAI chunk. |
Source code in src/mistral_common/protocol/instruct/chunk.py
should_not_be_empty(v)
classmethod
Validate that the audio data is not empty.
Source code in src/mistral_common/protocol/instruct/chunk.py
to_openai()
Convert the chunk to the OpenAI format.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A dictionary representing the audio chunk in the OpenAI format. |
Source code in src/mistral_common/protocol/instruct/chunk.py
AudioURL(**data)
Bases: MistralBase
Audio URL reference.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The URL of the audio file. |
Source code in pydantic/main.py
AudioURLChunk(**data)
Bases: BaseContentChunk
Audio content referenced by URL, path, file URI or base64.
The URL kind is resolved lazily by get_url_type; the audio itself is
loaded at tokenization time.
Attributes:
| Name | Type | Description |
|---|---|---|
audio_url |
str | AudioURL
|
The audio reference. Either an AudioURL instance or a plain string (URL, file path, file URI, or base64). |
Examples:
Source code in pydantic/main.py
url
property
The audio URL string.
Returns:
| Type | Description |
|---|---|
str
|
The URL regardless of whether |
from_openai(openai_chunk)
classmethod
Converts the OpenAI chunk to the Mistral format.
get_url_type()
Detect the kind of the referenced audio URL.
Note
URLs should be either: - a valid URL (http:// or https://) - a valid file path (e.g. /path/to/file) - a valid file URI (e.g. file:///path/to/file) - a base64 encoded audio. It is assumed to be base64 encoded if it is not a valid URL or file path.
Returns:
| Type | Description |
|---|---|
AudioURLType
|
The detected AudioURLType for this chunk's URL. |
Source code in src/mistral_common/protocol/instruct/chunk.py
to_openai()
Converts the chunk to the OpenAI format.
Source code in src/mistral_common/protocol/instruct/chunk.py
AudioURLType
BaseContentChunk(**data)
Bases: MistralBase
Base class for all content chunks.
Content chunks represent a piece of multimodal content (text, image, audio, thinking) inside a message. A message's content can be a string or a list of these chunks.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
Literal[text, image, image_url, input_audio, audio_url, thinking]
|
The chunk type, used as the pydantic discriminator. |
Source code in pydantic/main.py
from_openai(openai_chunk)
classmethod
Create a chunk instance from OpenAI format.
Must be implemented by concrete subclasses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_chunk
|
dict[str, Any]
|
Dictionary matching OpenAI's content chunk schema. |
required |
Returns:
| Type | Description |
|---|---|
BaseContentChunk
|
Chunk instance of the appropriate subclass. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always, as this is an abstract method. |
Source code in src/mistral_common/protocol/instruct/chunk.py
to_openai()
Convert this chunk to the OpenAI format.
Must be implemented by concrete subclasses.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary matching OpenAI's content chunk schema. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
Always, as this is an abstract method. |
Source code in src/mistral_common/protocol/instruct/chunk.py
ChunkTypes
Enum of the types of content chunks that can be sent to the model.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
A plain text chunk. |
|
image |
An image provided as raw data (PIL image, base64, URL or path). |
|
image_url |
An image referenced by URL or base64 data URL. |
|
input_audio |
Audio provided inline as base64 or raw bytes. |
|
audio_url |
Audio referenced by URL, file path, file URI or base64. |
|
thinking |
A reasoning/thinking chunk from the assistant. |
Examples:
ImageChunk(**data)
Bases: BaseContentChunk
Image content provided as raw data.
The image is processed (resized, serialized) at tokenization time by the image encoder.
Attributes:
| Name | Type | Description |
|---|---|---|
image |
SerializableImage
|
The image to send to the model. Accepts a PIL image, a URL (http/https), a base64-encoded string (optionally with a data:...;base64, prefix), or a local file path. |
Examples:
>>> from PIL import Image
>>> image_chunk = ImageChunk(image=Image.new('RGB', (200, 200), color='blue'))
Source code in pydantic/main.py
from_openai(openai_chunk)
classmethod
Create an ImageChunk from an OpenAI image_url chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_chunk
|
dict[str, Any]
|
Dictionary with "type" set to |
required |
Returns:
| Type | Description |
|---|---|
ImageChunk
|
An ImageChunk with the base64 prefix stripped if present. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the chunk type is not |
Source code in src/mistral_common/protocol/instruct/chunk.py
to_openai()
Convert this chunk to the OpenAI image_url format.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with "type" set to |
dict[str, Any]
|
base64 data URL under |
Source code in src/mistral_common/protocol/instruct/chunk.py
ImageURL(**data)
Bases: MistralBase
Image URL with optional detail level.
Attributes:
| Name | Type | Description |
|---|---|---|
url |
str
|
The URL of the image, or a base64-encoded image (optionally with a data:...;base64, prefix). |
detail |
str | None
|
Optional detail level hint for image processing (e.g., "high",
"low", "auto"). If |
Examples:
Source code in pydantic/main.py
ImageURLChunk(**data)
Bases: BaseContentChunk
Image content referenced by URL or base64 data URL.
Unlike ImageChunk, the image is not loaded at request construction time; the URL is resolved at tokenization time.
Attributes:
| Name | Type | Description |
|---|---|---|
image_url |
ImageURL | str
|
The image reference. Either an ImageURL instance (allowing a detail hint) or a plain URL/base64 string. |
Examples:
Source code in pydantic/main.py
from_openai(openai_chunk)
classmethod
Create an ImageURLChunk from an OpenAI chunk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
openai_chunk
|
dict[str, Any]
|
Dictionary with an |
required |
Returns:
| Type | Description |
|---|---|
ImageURLChunk
|
An ImageURLChunk with the |
Source code in src/mistral_common/protocol/instruct/chunk.py
get_url()
Return the underlying image URL string.
Returns:
| Type | Description |
|---|---|
str
|
The URL regardless of whether |
Source code in src/mistral_common/protocol/instruct/chunk.py
to_openai()
Convert this chunk to the OpenAI format.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with "type" set to |
dict[str, Any]
|
optional "detail") under |
Source code in src/mistral_common/protocol/instruct/chunk.py
RawAudio(**data)
Bases: MistralBase
Audio data with an explicit format.
Deprecated: Use str | bytes directly. Will be removed in 1.13.0.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
str | bytes
|
The audio data as raw bytes or a base64-encoded string. |
format |
str
|
The audio format (e.g., "wav", "mp3"). Must not be empty. |
Source code in pydantic/main.py
from_audio(audio)
classmethod
Create a RawAudio instance from an Audio object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
audio
|
Audio
|
An Audio object containing audio data, format, and duration. |
required |
Returns:
| Type | Description |
|---|---|
RawAudio
|
A RawAudio instance initialized with the audio data. |
Source code in src/mistral_common/protocol/instruct/chunk.py
model_post_init(__context)
Emit a one-shot deprecation warning for RawAudio.
Source code in src/mistral_common/protocol/instruct/chunk.py
should_not_be_empty(v)
Reject empty format strings.
Returns:
| Type | Description |
|---|---|
str
|
The unchanged format string if non-empty. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/mistral_common/protocol/instruct/chunk.py
TextChunk(**data)
Bases: BaseContentChunk
Text chunk.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str
|
The text to be sent to the model. |
Examples:
Source code in pydantic/main.py
from_openai(openai_chunk)
classmethod
Converts the OpenAI chunk to the Mistral format.
ThinkChunk(**data)
Bases: BaseContentChunk
Reasoning/thinking content from the assistant.
ThinkChunks represent chain-of-thought text the model produces before the final answer. In AssistantMessage content they must appear before any other chunk.
Attributes:
| Name | Type | Description |
|---|---|---|
thinking |
str
|
The thinking text content. |
closed |
bool
|
If |
Source code in pydantic/main.py
from_openai(openai_chunk)
classmethod
Converts the OpenAI chunk to the Mistral format.