(beta) Conversations API
- start - Create a conversation and append entries to it.
- list - List all created conversations.
- get - Retrieve a conversation information.
- delete - Delete a conversation.
- append - Append new entries to an existing conversation.
- get_history - Retrieve all entries in a conversation.
- get_messages - Retrieve all messages in a conversation.
- restart - Restart a conversation starting from a given entry.
- start_stream - Create a conversation and append entries to it.
- append_stream - Append new entries to an existing conversation.
- restart_stream - Restart a conversation starting from a given entry.
Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.start(inputs="<value>", completion_args={
"response_format": {
"type": "text",
},
})
# Handle response
print(res)
models.ConversationResponse
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Retrieve a list of conversation entities sorted by creation time.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.list(page=0, page_size=100)
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
page |
Optional[int] |
➖ |
N/A |
page_size |
Optional[int] |
➖ |
N/A |
metadata |
Dict[str, Any] |
➖ |
N/A |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
List[models.AgentsAPIV1ConversationsListResponse]
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Given a conversation_id retrieve a conversation entity with its attributes.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.get(conversation_id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
conversation_id |
str |
✔️ |
ID of the conversation from which we are fetching metadata. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.ResponseV1ConversationsGet
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Delete a conversation given a conversation_id.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
mistral.beta.conversations.delete(conversation_id="<id>")
# Use the SDK ...
| Parameter |
Type |
Required |
Description |
conversation_id |
str |
✔️ |
ID of the conversation from which we are fetching metadata. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Run completion on the history of the conversation and the user entries. Return the new created entries.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.append(conversation_id="<id>", store=True, handoff_execution="server", completion_args={
"response_format": {
"type": "text",
},
})
# Handle response
print(res)
models.ConversationResponse
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Given a conversation_id retrieve all the entries belonging to that conversation. The entries are sorted in the order they were appended, those can be messages, connectors or function_call.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.get_history(conversation_id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
conversation_id |
str |
✔️ |
ID of the conversation from which we are fetching entries. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.ConversationHistory
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Given a conversation_id retrieve all the messages belonging to that conversation. This is similar to retrieving all entries except we filter the messages only.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.get_messages(conversation_id="<id>")
# Handle response
print(res)
| Parameter |
Type |
Required |
Description |
conversation_id |
str |
✔️ |
ID of the conversation from which we are fetching messages. |
retries |
Optional[utils.RetryConfig] |
➖ |
Configuration to override the default retry behavior of the client. |
models.ConversationMessages
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.restart(conversation_id="<id>", from_entry_id="<id>", store=True, handoff_execution="server", completion_args={
"response_format": {
"type": "text",
},
})
# Handle response
print(res)
models.ConversationResponse
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.start_stream(inputs=[
{
"object": "entry",
"type": "function.result",
"tool_call_id": "<id>",
"result": "<value>",
},
], completion_args={
"response_format": {
"type": "text",
},
})
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
Union[eventstreaming.EventStream[models.ConversationEvents], eventstreaming.EventStreamAsync[models.ConversationEvents]]
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Run completion on the history of the conversation and the user entries. Return the new created entries.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.append_stream(conversation_id="<id>", store=True, handoff_execution="server", completion_args={
"response_format": {
"type": "text",
},
})
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
Union[eventstreaming.EventStream[models.ConversationEvents], eventstreaming.EventStreamAsync[models.ConversationEvents]]
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |
Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.
from mistralai.client import Mistral
import os
with Mistral(
api_key=os.getenv("MISTRAL_API_KEY", ""),
) as mistral:
res = mistral.beta.conversations.restart_stream(conversation_id="<id>", from_entry_id="<id>", store=True, handoff_execution="server", completion_args={
"response_format": {
"type": "text",
},
})
with res as event_stream:
for event in event_stream:
# handle event
print(event, flush=True)
Union[eventstreaming.EventStream[models.ConversationEvents], eventstreaming.EventStreamAsync[models.ConversationEvents]]
| Error Type |
Status Code |
Content Type |
| errors.HTTPValidationError |
422 |
application/json |
| errors.SDKError |
4XX, 5XX |
*/* |