Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.env.local
**/__pycache__/
**/.speakeasy/temp/
**/.speakeasy/logs/
Expand Down
21 changes: 12 additions & 9 deletions .speakeasy/gen.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ id: 2d045ec7-2ebb-4f4d-ad25-40953b132161
management:
docChecksum: c3693e4872a0785b2ed46c59a8464804
docVersion: 1.0.0
speakeasyVersion: 1.568.2
generationVersion: 2.634.2
speakeasyVersion: 1.628.4
generationVersion: 2.716.5
releaseVersion: 1.9.10
configChecksum: 438b1373b4090838b050a2779ab5383f
configChecksum: 7f23b5385b52f9096be1cb6451f4188e
repoURL: https://github.com/mistralai/client-python.git
installationURL: https://github.com/mistralai/client-python.git
published: true
Expand All @@ -15,16 +15,16 @@ features:
additionalDependencies: 1.0.0
additionalProperties: 1.0.1
constsAndDefaults: 1.0.5
core: 5.19.3
core: 5.22.0
customCodeRegions: 0.1.1
defaultEnabledRetries: 0.2.0
downloadStreams: 1.0.1
enumUnions: 0.1.0
envVarSecurityUsage: 0.3.2
examples: 3.0.1
examples: 3.0.2
flatRequests: 1.0.1
flattening: 3.1.1
globalSecurity: 3.0.3
globalSecurity: 3.0.4
globalSecurityCallbacks: 1.0.0
globalSecurityFlattening: 1.0.0
globalServerURLs: 3.1.1
Expand All @@ -36,14 +36,13 @@ features:
responseFormat: 1.0.1
retries: 3.0.2
sdkHooks: 1.1.0
serverEvents: 1.0.7
serverEvents: 1.0.10
serverEventsSentinels: 0.1.0
serverIDs: 3.0.0
unions: 3.0.4
unions: 3.0.5
uploadStreams: 1.0.0
generatedFiles:
- .gitattributes
- .python-version
- .vscode/settings.json
- USAGE.md
- docs/models/agent.md
Expand Down Expand Up @@ -665,12 +664,14 @@ generatedFiles:
- src/mistralai/models/messageoutputentry.py
- src/mistralai/models/messageoutputevent.py
- src/mistralai/models/metricout.py
- src/mistralai/models/mistralerror.py
- src/mistralai/models/mistralpromptmode.py
- src/mistralai/models/modelcapabilities.py
- src/mistralai/models/modelconversation.py
- src/mistralai/models/modellist.py
- src/mistralai/models/moderationobject.py
- src/mistralai/models/moderationresponse.py
- src/mistralai/models/no_response_error.py
- src/mistralai/models/ocrimageobject.py
- src/mistralai/models/ocrpagedimensions.py
- src/mistralai/models/ocrpageobject.py
Expand All @@ -687,6 +688,7 @@ generatedFiles:
- src/mistralai/models/responseformat.py
- src/mistralai/models/responseformats.py
- src/mistralai/models/responsestartedevent.py
- src/mistralai/models/responsevalidationerror.py
- src/mistralai/models/retrieve_model_v1_models_model_id_getop.py
- src/mistralai/models/retrievefileout.py
- src/mistralai/models/sampletype.py
Expand Down Expand Up @@ -756,6 +758,7 @@ generatedFiles:
- src/mistralai/utils/retries.py
- src/mistralai/utils/security.py
- src/mistralai/utils/serializers.py
- src/mistralai/utils/unmarshal_json_response.py
- src/mistralai/utils/url.py
- src/mistralai/utils/values.py
examples:
Expand Down
8 changes: 8 additions & 0 deletions .speakeasy/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ generation:
auth:
oAuth2ClientCredentialsEnabled: true
oAuth2PasswordEnabled: false
hoistGlobalSecurity: true
tests:
generateTests: true
generateNewTests: false
Expand All @@ -26,6 +27,10 @@ python:
dev:
pytest: ^8.2.2
pytest-asyncio: ^0.23.7
allowedRedefinedBuiltins:
- id
- object
asyncMode: both
authors:
- Mistral
baseErrorName: MistralError
Expand All @@ -49,12 +54,15 @@ python:
shared: ""
webhooks: ""
inputModelSuffix: input
legacyPyright: true
maxMethodParams: 15
methodArguments: infer-optional-args
moduleName: ""
outputModelSuffix: output
packageManager: poetry
packageName: mistralai
pytestFilterWarnings: []
pytestTimeout: 0
responseFormat: flat
sseFlatResponse: false
templateVersion: v2
14 changes: 7 additions & 7 deletions .speakeasy/workflow.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
speakeasyVersion: 1.568.2
speakeasyVersion: 1.628.4
sources:
mistral-azure-source:
sourceNamespace: mistral-openapi-azure
Expand All @@ -18,7 +18,7 @@ sources:
sourceBlobDigest: sha256:97767522559603de92a9738938e522cea4d558b2a854500acf6fe8d81f8ccfb8
tags:
- latest
- speakeasy-sdk-regen-1756796562
- main
targets:
mistralai-azure-sdk:
source: mistral-azure-source
Expand All @@ -40,20 +40,20 @@ targets:
sourceRevisionDigest: sha256:eefc1f0b6a5e9ec673d317d61cad766290710b5fc369412491b75f732cccfedd
sourceBlobDigest: sha256:97767522559603de92a9738938e522cea4d558b2a854500acf6fe8d81f8ccfb8
codeSamplesNamespace: mistral-openapi-code-samples
codeSamplesRevisionDigest: sha256:372d48b60fafc0c389b12af1dad61faa479598e8194dc3a2a1ed27c207ab9b18
codeSamplesRevisionDigest: sha256:31dee4783f73e1efa932b16da7238ddfe29b94f4b1c66223d6e0f2393cdc6f72
workflow:
workflowVersion: 1.0.0
speakeasyVersion: 1.568.2
speakeasyVersion: 1.628.4
sources:
mistral-azure-source:
inputs:
- location: registry.speakeasyapi.dev/mistral-dev/mistral-dev/mistral-openapi-azure:main
- location: registry.speakeasyapi.dev/mistral-dev/mistral-dev/mistral-openapi-azure:sha256:670c460702ec74f7077491464a6dc5ee9d873969c80e812c48dbf4deb160e470
mistral-google-cloud-source:
inputs:
- location: registry.speakeasyapi.dev/mistral-dev/mistral-dev/mistral-openapi-google-cloud:main
- location: registry.speakeasyapi.dev/mistral-dev/mistral-dev/mistral-openapi-google-cloud:sha256:4a5343e63c6a78152e472b00ccc46d7bcb15594496bc94c8040039d3a9d4c5f8
mistral-openapi:
inputs:
- location: registry.speakeasyapi.dev/mistral-dev/mistral-dev/mistral-openapi:main
- location: registry.speakeasyapi.dev/mistral-dev/mistral-dev/mistral-openapi:sha256:eefc1f0b6a5e9ec673d317d61cad766290710b5fc369412491b75f732cccfedd
targets:
mistralai-azure-sdk:
target: python
Expand Down
2 changes: 1 addition & 1 deletion .speakeasy/workflow.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
workflowVersion: 1.0.0
speakeasyVersion: 1.568.2
speakeasyVersion: 1.628.4
sources:
mistral-azure-source:
inputs:
Expand Down
89 changes: 61 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,15 @@ Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create yo
>
> Once a Python version reaches its [official end of life date](https://devguide.python.org/versions/), a 3-month grace period is provided for users to upgrade. Following this grace period, the minimum python version supported in the SDK will be updated.

The SDK can be installed with either *pip* or *poetry* package managers.
The SDK can be installed with *uv*, *pip*, or *poetry* package managers.

### uv

*uv* is a fast Python package installer and resolver, designed as a drop-in replacement for pip and pip-tools. It's recommended for its speed and modern Python tooling capabilities.

```bash
uv add mistralai
```

### PIP

Expand Down Expand Up @@ -150,7 +158,8 @@ with Mistral(

</br>

The same SDK client can also be used to make asychronous requests by importing asyncio.
The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
import asyncio
Expand Down Expand Up @@ -201,7 +210,8 @@ with Mistral(

</br>

The same SDK client can also be used to make asychronous requests by importing asyncio.
The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
import asyncio
Expand Down Expand Up @@ -252,7 +262,8 @@ with Mistral(

</br>

The same SDK client can also be used to make asychronous requests by importing asyncio.
The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
import asyncio
Expand Down Expand Up @@ -303,7 +314,8 @@ with Mistral(

</br>

The same SDK client can also be used to make asychronous requests by importing asyncio.
The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
import asyncio
Expand Down Expand Up @@ -680,27 +692,20 @@ with Mistral(
<!-- Start Error Handling [errors] -->
## Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an exception.

By default, an API error will raise a models.SDKError exception, which has the following properties:

| Property | Type | Description |
|-----------------|------------------|-----------------------|
| `.status_code` | *int* | The HTTP status code |
| `.message` | *str* | The error message |
| `.raw_response` | *httpx.Response* | The raw HTTP response |
| `.body` | *str* | The response content |

When custom error responses are specified for an operation, the SDK may also raise their associated exceptions. You can refer to respective *Errors* tables in SDK docs for more details on possible exception types for each operation. For example, the `list_async` method may raise the following exceptions:
[`MistralError`](./src/mistralai/models/mistralerror.py) is the base class for all HTTP error responses. It has the following properties:

| Error Type | Status Code | Content Type |
| -------------------------- | ----------- | ---------------- |
| models.HTTPValidationError | 422 | application/json |
| models.SDKError | 4XX, 5XX | \*/\* |
| Property | Type | Description |
| ------------------ | ---------------- | --------------------------------------------------------------------------------------- |
| `err.message` | `str` | Error message |
| `err.status_code` | `int` | HTTP response status code eg `404` |
| `err.headers` | `httpx.Headers` | HTTP response headers |
| `err.body` | `str` | HTTP body. Can be empty string if no body is returned. |
| `err.raw_response` | `httpx.Response` | Raw HTTP response |
| `err.data` | | Optional. Some errors may contain structured data. [See Error Classes](#error-classes). |

### Example

```python
import mistralai
from mistralai import Mistral, models
import os

Expand All @@ -716,13 +721,41 @@ with Mistral(
# Handle response
print(res)

except models.HTTPValidationError as e:
# handle e.data: models.HTTPValidationErrorData
raise(e)
except models.SDKError as e:
# handle exception
raise(e)

except models.MistralError as e:
# The base class for HTTP error responses
print(e.message)
print(e.status_code)
print(e.body)
print(e.headers)
print(e.raw_response)

# Depending on the method different errors may be thrown
if isinstance(e, models.HTTPValidationError):
print(e.data.detail) # Optional[List[mistralai.ValidationError]]
```

### Error Classes
**Primary error:**
* [`MistralError`](./src/mistralai/models/mistralerror.py): The base class for HTTP error responses.

<details><summary>Less common errors (6)</summary>

<br />

**Network errors:**
* [`httpx.RequestError`](https://www.python-httpx.org/exceptions/#httpx.RequestError): Base class for request errors.
* [`httpx.ConnectError`](https://www.python-httpx.org/exceptions/#httpx.ConnectError): HTTP client was unable to make a request to a server.
* [`httpx.TimeoutException`](https://www.python-httpx.org/exceptions/#httpx.TimeoutException): HTTP request timed out.


**Inherit from [`MistralError`](./src/mistralai/models/mistralerror.py)**:
* [`HTTPValidationError`](./src/mistralai/models/httpvalidationerror.py): Validation Error. Status code `422`. Applicable to 47 of 68 methods.*
* [`ResponseValidationError`](./src/mistralai/models/responsevalidationerror.py): Type mismatch between the response data and the expected Pydantic model. Provides access to the Pydantic validation error via the `cause` attribute.

</details>

\* Check [the method documentation](#available-resources-and-operations) to see if the error is applicable.
<!-- End Error Handling [errors] -->

<!-- Start Server Selection [server] -->
Expand Down
12 changes: 8 additions & 4 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ with Mistral(

</br>

The same SDK client can also be used to make asychronous requests by importing asyncio.
The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
import asyncio
Expand Down Expand Up @@ -77,7 +78,8 @@ with Mistral(

</br>

The same SDK client can also be used to make asychronous requests by importing asyncio.
The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
import asyncio
Expand Down Expand Up @@ -128,7 +130,8 @@ with Mistral(

</br>

The same SDK client can also be used to make asychronous requests by importing asyncio.
The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
import asyncio
Expand Down Expand Up @@ -179,7 +182,8 @@ with Mistral(

</br>

The same SDK client can also be used to make asychronous requests by importing asyncio.
The same SDK client can also be used to make asynchronous requests by importing asyncio.

```python
# Asynchronous Example
import asyncio
Expand Down
3 changes: 3 additions & 0 deletions docs/sdks/accesses/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Given a library, list all of the Entity that have access and to what level.

### Example Usage

<!-- UsageSnippet language="python" operationID="libraries_share_list_v1" method="get" path="/v1/libraries/{library_id}/share" -->
```python
from mistralai import Mistral
import os
Expand Down Expand Up @@ -57,6 +58,7 @@ Given a library id, you can create or update the access level of an entity. You

### Example Usage

<!-- UsageSnippet language="python" operationID="libraries_share_create_v1" method="put" path="/v1/libraries/{library_id}/share" -->
```python
from mistralai import Mistral
import os
Expand Down Expand Up @@ -101,6 +103,7 @@ Given a library id, you can delete the access level of an entity. An owner canno

### Example Usage

<!-- UsageSnippet language="python" operationID="libraries_share_delete_v1" method="delete" path="/v1/libraries/{library_id}/share" -->
```python
from mistralai import Mistral
import os
Expand Down
2 changes: 2 additions & 0 deletions docs/sdks/agents/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Agents Completion

### Example Usage

<!-- UsageSnippet language="python" operationID="agents_completion_v1_agents_completions_post" method="post" path="/v1/agents/completions" -->
```python
from mistralai import Mistral
import os
Expand Down Expand Up @@ -75,6 +76,7 @@ Mistral AI provides the ability to stream responses back to a client in order to

### Example Usage

<!-- UsageSnippet language="python" operationID="stream_agents" method="post" path="/v1/agents/completions#stream" -->
```python
from mistralai import Mistral
import os
Expand Down
Loading
Loading