mistralai 0.4.2__py3-none-any.whl → 1.0.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (240) hide show
  1. mistralai/__init__.py +5 -0
  2. mistralai/_hooks/__init__.py +5 -0
  3. mistralai/_hooks/custom_user_agent.py +16 -0
  4. mistralai/_hooks/deprecation_warning.py +26 -0
  5. mistralai/_hooks/registration.py +17 -0
  6. mistralai/_hooks/sdkhooks.py +57 -0
  7. mistralai/_hooks/types.py +76 -0
  8. mistralai/async_client.py +5 -413
  9. mistralai/basesdk.py +216 -0
  10. mistralai/chat.py +475 -0
  11. mistralai/client.py +5 -414
  12. mistralai/embeddings.py +182 -0
  13. mistralai/files.py +600 -84
  14. mistralai/fim.py +439 -0
  15. mistralai/fine_tuning.py +855 -0
  16. mistralai/httpclient.py +78 -0
  17. mistralai/models/__init__.py +80 -0
  18. mistralai/models/archiveftmodelout.py +19 -0
  19. mistralai/models/assistantmessage.py +58 -0
  20. mistralai/models/chatcompletionchoice.py +33 -0
  21. mistralai/models/chatcompletionrequest.py +114 -0
  22. mistralai/models/chatcompletionresponse.py +27 -0
  23. mistralai/models/chatcompletionstreamrequest.py +112 -0
  24. mistralai/models/checkpointout.py +25 -0
  25. mistralai/models/completionchunk.py +27 -0
  26. mistralai/models/completionevent.py +15 -0
  27. mistralai/models/completionresponsestreamchoice.py +53 -0
  28. mistralai/models/contentchunk.py +17 -0
  29. mistralai/models/delete_model_v1_models_model_id_deleteop.py +16 -0
  30. mistralai/models/deletefileout.py +24 -0
  31. mistralai/models/deletemodelout.py +25 -0
  32. mistralai/models/deltamessage.py +52 -0
  33. mistralai/models/detailedjobout.py +96 -0
  34. mistralai/models/embeddingrequest.py +66 -0
  35. mistralai/models/embeddingresponse.py +24 -0
  36. mistralai/models/embeddingresponsedata.py +19 -0
  37. mistralai/models/eventout.py +55 -0
  38. mistralai/models/files_api_routes_delete_fileop.py +16 -0
  39. mistralai/models/files_api_routes_retrieve_fileop.py +16 -0
  40. mistralai/models/files_api_routes_upload_fileop.py +51 -0
  41. mistralai/models/fileschema.py +76 -0
  42. mistralai/models/fimcompletionrequest.py +99 -0
  43. mistralai/models/fimcompletionresponse.py +27 -0
  44. mistralai/models/fimcompletionstreamrequest.py +97 -0
  45. mistralai/models/finetuneablemodel.py +8 -0
  46. mistralai/models/ftmodelcapabilitiesout.py +21 -0
  47. mistralai/models/ftmodelout.py +70 -0
  48. mistralai/models/function.py +19 -0
  49. mistralai/models/functioncall.py +16 -0
  50. mistralai/models/githubrepositoryin.py +57 -0
  51. mistralai/models/githubrepositoryout.py +57 -0
  52. mistralai/models/httpvalidationerror.py +23 -0
  53. mistralai/models/jobin.py +78 -0
  54. mistralai/models/jobmetadataout.py +59 -0
  55. mistralai/models/jobout.py +112 -0
  56. mistralai/models/jobs_api_routes_fine_tuning_archive_fine_tuned_modelop.py +16 -0
  57. mistralai/models/jobs_api_routes_fine_tuning_cancel_fine_tuning_jobop.py +18 -0
  58. mistralai/models/jobs_api_routes_fine_tuning_create_fine_tuning_jobop.py +73 -0
  59. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobop.py +18 -0
  60. mistralai/models/jobs_api_routes_fine_tuning_get_fine_tuning_jobsop.py +86 -0
  61. mistralai/models/jobs_api_routes_fine_tuning_start_fine_tuning_jobop.py +16 -0
  62. mistralai/models/jobs_api_routes_fine_tuning_unarchive_fine_tuned_modelop.py +16 -0
  63. mistralai/models/jobs_api_routes_fine_tuning_update_fine_tuned_modelop.py +19 -0
  64. mistralai/models/jobsout.py +20 -0
  65. mistralai/models/legacyjobmetadataout.py +85 -0
  66. mistralai/models/listfilesout.py +17 -0
  67. mistralai/models/metricout.py +55 -0
  68. mistralai/models/modelcapabilities.py +21 -0
  69. mistralai/models/modelcard.py +71 -0
  70. mistralai/models/modellist.py +18 -0
  71. mistralai/models/responseformat.py +18 -0
  72. mistralai/models/retrieve_model_v1_models_model_id_getop.py +16 -0
  73. mistralai/models/retrievefileout.py +76 -0
  74. mistralai/models/sampletype.py +7 -0
  75. mistralai/models/sdkerror.py +22 -0
  76. mistralai/models/security.py +16 -0
  77. mistralai/models/source.py +7 -0
  78. mistralai/models/systemmessage.py +26 -0
  79. mistralai/models/textchunk.py +17 -0
  80. mistralai/models/tool.py +18 -0
  81. mistralai/models/toolcall.py +20 -0
  82. mistralai/models/toolmessage.py +55 -0
  83. mistralai/models/trainingfile.py +17 -0
  84. mistralai/models/trainingparameters.py +53 -0
  85. mistralai/models/trainingparametersin.py +61 -0
  86. mistralai/models/unarchiveftmodelout.py +19 -0
  87. mistralai/models/updateftmodelin.py +49 -0
  88. mistralai/models/uploadfileout.py +76 -0
  89. mistralai/models/usageinfo.py +18 -0
  90. mistralai/models/usermessage.py +26 -0
  91. mistralai/models/validationerror.py +24 -0
  92. mistralai/models/wandbintegration.py +61 -0
  93. mistralai/models/wandbintegrationout.py +57 -0
  94. mistralai/models_.py +928 -0
  95. mistralai/py.typed +1 -0
  96. mistralai/sdk.py +111 -0
  97. mistralai/sdkconfiguration.py +53 -0
  98. mistralai/types/__init__.py +21 -0
  99. mistralai/types/basemodel.py +35 -0
  100. mistralai/utils/__init__.py +82 -0
  101. mistralai/utils/annotations.py +19 -0
  102. mistralai/utils/enums.py +34 -0
  103. mistralai/utils/eventstreaming.py +179 -0
  104. mistralai/utils/forms.py +207 -0
  105. mistralai/utils/headers.py +136 -0
  106. mistralai/utils/metadata.py +118 -0
  107. mistralai/utils/queryparams.py +203 -0
  108. mistralai/utils/requestbodies.py +66 -0
  109. mistralai/utils/retries.py +216 -0
  110. mistralai/utils/security.py +182 -0
  111. mistralai/utils/serializers.py +181 -0
  112. mistralai/utils/url.py +150 -0
  113. mistralai/utils/values.py +128 -0
  114. {mistralai-0.4.2.dist-info → mistralai-1.0.0rc1.dist-info}/LICENSE +1 -1
  115. mistralai-1.0.0rc1.dist-info/METADATA +621 -0
  116. mistralai-1.0.0rc1.dist-info/RECORD +228 -0
  117. mistralai_azure/__init__.py +5 -0
  118. mistralai_azure/_hooks/__init__.py +5 -0
  119. mistralai_azure/_hooks/custom_user_agent.py +16 -0
  120. mistralai_azure/_hooks/registration.py +15 -0
  121. mistralai_azure/_hooks/sdkhooks.py +57 -0
  122. mistralai_azure/_hooks/types.py +76 -0
  123. mistralai_azure/basesdk.py +215 -0
  124. mistralai_azure/chat.py +475 -0
  125. mistralai_azure/httpclient.py +78 -0
  126. mistralai_azure/models/__init__.py +28 -0
  127. mistralai_azure/models/assistantmessage.py +58 -0
  128. mistralai_azure/models/chatcompletionchoice.py +33 -0
  129. mistralai_azure/models/chatcompletionrequest.py +114 -0
  130. mistralai_azure/models/chatcompletionresponse.py +27 -0
  131. mistralai_azure/models/chatcompletionstreamrequest.py +112 -0
  132. mistralai_azure/models/completionchunk.py +27 -0
  133. mistralai_azure/models/completionevent.py +15 -0
  134. mistralai_azure/models/completionresponsestreamchoice.py +53 -0
  135. mistralai_azure/models/contentchunk.py +17 -0
  136. mistralai_azure/models/deltamessage.py +52 -0
  137. mistralai_azure/models/function.py +19 -0
  138. mistralai_azure/models/functioncall.py +16 -0
  139. mistralai_azure/models/httpvalidationerror.py +23 -0
  140. mistralai_azure/models/responseformat.py +18 -0
  141. mistralai_azure/models/sdkerror.py +22 -0
  142. mistralai_azure/models/security.py +16 -0
  143. mistralai_azure/models/systemmessage.py +26 -0
  144. mistralai_azure/models/textchunk.py +17 -0
  145. mistralai_azure/models/tool.py +18 -0
  146. mistralai_azure/models/toolcall.py +20 -0
  147. mistralai_azure/models/toolmessage.py +55 -0
  148. mistralai_azure/models/usageinfo.py +18 -0
  149. mistralai_azure/models/usermessage.py +26 -0
  150. mistralai_azure/models/validationerror.py +24 -0
  151. mistralai_azure/py.typed +1 -0
  152. mistralai_azure/sdk.py +102 -0
  153. mistralai_azure/sdkconfiguration.py +53 -0
  154. mistralai_azure/types/__init__.py +21 -0
  155. mistralai_azure/types/basemodel.py +35 -0
  156. mistralai_azure/utils/__init__.py +80 -0
  157. mistralai_azure/utils/annotations.py +19 -0
  158. mistralai_azure/utils/enums.py +34 -0
  159. mistralai_azure/utils/eventstreaming.py +179 -0
  160. mistralai_azure/utils/forms.py +207 -0
  161. mistralai_azure/utils/headers.py +136 -0
  162. mistralai_azure/utils/metadata.py +118 -0
  163. mistralai_azure/utils/queryparams.py +203 -0
  164. mistralai_azure/utils/requestbodies.py +66 -0
  165. mistralai_azure/utils/retries.py +216 -0
  166. mistralai_azure/utils/security.py +168 -0
  167. mistralai_azure/utils/serializers.py +181 -0
  168. mistralai_azure/utils/url.py +150 -0
  169. mistralai_azure/utils/values.py +128 -0
  170. mistralai_gcp/__init__.py +5 -0
  171. mistralai_gcp/_hooks/__init__.py +5 -0
  172. mistralai_gcp/_hooks/custom_user_agent.py +16 -0
  173. mistralai_gcp/_hooks/registration.py +15 -0
  174. mistralai_gcp/_hooks/sdkhooks.py +57 -0
  175. mistralai_gcp/_hooks/types.py +76 -0
  176. mistralai_gcp/basesdk.py +215 -0
  177. mistralai_gcp/chat.py +463 -0
  178. mistralai_gcp/fim.py +439 -0
  179. mistralai_gcp/httpclient.py +78 -0
  180. mistralai_gcp/models/__init__.py +31 -0
  181. mistralai_gcp/models/assistantmessage.py +58 -0
  182. mistralai_gcp/models/chatcompletionchoice.py +33 -0
  183. mistralai_gcp/models/chatcompletionrequest.py +110 -0
  184. mistralai_gcp/models/chatcompletionresponse.py +27 -0
  185. mistralai_gcp/models/chatcompletionstreamrequest.py +108 -0
  186. mistralai_gcp/models/completionchunk.py +27 -0
  187. mistralai_gcp/models/completionevent.py +15 -0
  188. mistralai_gcp/models/completionresponsestreamchoice.py +53 -0
  189. mistralai_gcp/models/contentchunk.py +17 -0
  190. mistralai_gcp/models/deltamessage.py +52 -0
  191. mistralai_gcp/models/fimcompletionrequest.py +99 -0
  192. mistralai_gcp/models/fimcompletionresponse.py +27 -0
  193. mistralai_gcp/models/fimcompletionstreamrequest.py +97 -0
  194. mistralai_gcp/models/function.py +19 -0
  195. mistralai_gcp/models/functioncall.py +16 -0
  196. mistralai_gcp/models/httpvalidationerror.py +23 -0
  197. mistralai_gcp/models/responseformat.py +18 -0
  198. mistralai_gcp/models/sdkerror.py +22 -0
  199. mistralai_gcp/models/security.py +16 -0
  200. mistralai_gcp/models/systemmessage.py +26 -0
  201. mistralai_gcp/models/textchunk.py +17 -0
  202. mistralai_gcp/models/tool.py +18 -0
  203. mistralai_gcp/models/toolcall.py +20 -0
  204. mistralai_gcp/models/toolmessage.py +55 -0
  205. mistralai_gcp/models/usageinfo.py +18 -0
  206. mistralai_gcp/models/usermessage.py +26 -0
  207. mistralai_gcp/models/validationerror.py +24 -0
  208. mistralai_gcp/py.typed +1 -0
  209. mistralai_gcp/sdk.py +165 -0
  210. mistralai_gcp/sdkconfiguration.py +53 -0
  211. mistralai_gcp/types/__init__.py +21 -0
  212. mistralai_gcp/types/basemodel.py +35 -0
  213. mistralai_gcp/utils/__init__.py +80 -0
  214. mistralai_gcp/utils/annotations.py +19 -0
  215. mistralai_gcp/utils/enums.py +34 -0
  216. mistralai_gcp/utils/eventstreaming.py +179 -0
  217. mistralai_gcp/utils/forms.py +207 -0
  218. mistralai_gcp/utils/headers.py +136 -0
  219. mistralai_gcp/utils/metadata.py +118 -0
  220. mistralai_gcp/utils/queryparams.py +203 -0
  221. mistralai_gcp/utils/requestbodies.py +66 -0
  222. mistralai_gcp/utils/retries.py +216 -0
  223. mistralai_gcp/utils/security.py +168 -0
  224. mistralai_gcp/utils/serializers.py +181 -0
  225. mistralai_gcp/utils/url.py +150 -0
  226. mistralai_gcp/utils/values.py +128 -0
  227. py.typed +1 -0
  228. mistralai/client_base.py +0 -211
  229. mistralai/constants.py +0 -5
  230. mistralai/exceptions.py +0 -54
  231. mistralai/jobs.py +0 -172
  232. mistralai/models/chat_completion.py +0 -93
  233. mistralai/models/common.py +0 -9
  234. mistralai/models/embeddings.py +0 -19
  235. mistralai/models/files.py +0 -23
  236. mistralai/models/jobs.py +0 -100
  237. mistralai/models/models.py +0 -39
  238. mistralai-0.4.2.dist-info/METADATA +0 -82
  239. mistralai-0.4.2.dist-info/RECORD +0 -20
  240. {mistralai-0.4.2.dist-info → mistralai-1.0.0rc1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,621 @@
1
+ Metadata-Version: 2.1
2
+ Name: mistralai
3
+ Version: 1.0.0rc1
4
+ Summary: Python Client SDK for the Mistral AI API.
5
+ Author: Mistral
6
+ Requires-Python: >=3.8,<4.0
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.8
9
+ Classifier: Programming Language :: Python :: 3.9
10
+ Classifier: Programming Language :: Python :: 3.10
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Provides-Extra: gcp
14
+ Requires-Dist: google-auth (>=2.31.0,<3.0.0) ; extra == "gcp"
15
+ Requires-Dist: httpx (>=0.27.0,<0.28.0)
16
+ Requires-Dist: jsonpath-python (>=1.0.6,<2.0.0)
17
+ Requires-Dist: pydantic (>=2.8.2,<2.9.0)
18
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
19
+ Requires-Dist: requests (>=2.32.3,<3.0.0) ; extra == "gcp"
20
+ Requires-Dist: typing-inspect (>=0.9.0,<0.10.0)
21
+ Description-Content-Type: text/markdown
22
+
23
+ # mistralai
24
+
25
+ <div align="left">
26
+ <a href="https://speakeasyapi.dev/"><img src="https://custom-icon-badges.demolab.com/badge/-Built%20By%20Speakeasy-212015?style=for-the-badge&logoColor=FBE331&logo=speakeasy&labelColor=545454" /></a>
27
+ </div>
28
+
29
+ ## Migration warning
30
+
31
+ This documentation is for Mistralai SDK v1. You can find more details on how to migrate from v0 to v1 [here](MIGRATION.md)
32
+
33
+ <!-- Start SDK Installation [installation] -->
34
+ ## SDK Installation
35
+
36
+ PIP
37
+ ```bash
38
+ pip install mistralai
39
+ ```
40
+
41
+ Poetry
42
+ ```bash
43
+ poetry add mistralai
44
+ ```
45
+ <!-- End SDK Installation [installation] -->
46
+
47
+ <!-- Start SDK Example Usage [usage] -->
48
+ ## SDK Example Usage
49
+
50
+ ### Create Chat Completions
51
+
52
+ This example shows how to create chat completions.
53
+
54
+ ```python
55
+ # Synchronous Example
56
+ from mistralai import Mistral
57
+ import os
58
+
59
+ s = Mistral(
60
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
61
+ )
62
+
63
+
64
+ res = s.chat.create(messages=[
65
+ {
66
+ "content": "Who is the best French painter? Answer in one short sentence.",
67
+ "role": "user",
68
+ },
69
+ ], model="mistral-small-latest")
70
+
71
+ if res is not None:
72
+ # handle response
73
+ pass
74
+ ```
75
+
76
+ </br>
77
+
78
+ The same SDK client can also be used to make asychronous requests by importing asyncio.
79
+ ```python
80
+ # Asynchronous Example
81
+ import asyncio
82
+ from mistralai import Mistral
83
+ import os
84
+
85
+ async def main():
86
+ s = Mistral(
87
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
88
+ )
89
+ res = await s.chat.create_async(messages=[
90
+ {
91
+ "content": "Who is the best French painter? Answer in one short sentence.",
92
+ "role": "user",
93
+ },
94
+ ], model="mistral-small-latest")
95
+ if res is not None:
96
+ # handle response
97
+ pass
98
+
99
+ asyncio.run(main())
100
+ ```
101
+
102
+ ### Upload a file
103
+
104
+ This example shows how to upload a file.
105
+
106
+ ```python
107
+ # Synchronous Example
108
+ from mistralai import Mistral
109
+ import os
110
+
111
+ s = Mistral(
112
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
113
+ )
114
+
115
+
116
+ res = s.files.upload(file={
117
+ "file_name": "your_file_here",
118
+ "content": open("<file_path>", "rb"),
119
+ })
120
+
121
+ if res is not None:
122
+ # handle response
123
+ pass
124
+ ```
125
+
126
+ </br>
127
+
128
+ The same SDK client can also be used to make asychronous requests by importing asyncio.
129
+ ```python
130
+ # Asynchronous Example
131
+ import asyncio
132
+ from mistralai import Mistral
133
+ import os
134
+
135
+ async def main():
136
+ s = Mistral(
137
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
138
+ )
139
+ res = await s.files.upload_async(file={
140
+ "file_name": "your_file_here",
141
+ "content": open("<file_path>", "rb"),
142
+ })
143
+ if res is not None:
144
+ # handle response
145
+ pass
146
+
147
+ asyncio.run(main())
148
+ ```
149
+ <!-- End SDK Example Usage [usage] -->
150
+
151
+ ### Azure AI
152
+
153
+ **Prerequisites**
154
+ Before you begin, ensure you have `AZUREAI_ENDPOINT` and an `AZURE_API_KEY`. To obtain these, you will need to deploy Mistral on Azure AI.
155
+ See [instructions for deploying Mistral on Azure AI here](https://docs.mistral.ai/deployment/cloud/azure/).
156
+
157
+ Here's a basic example to get you started. You can also run [the example in the `examples` directory](/examples/azure/).
158
+
159
+ ```python
160
+ import asyncio
161
+ import os
162
+
163
+ from mistralai_azure import MistralAzure
164
+
165
+ client = MistralAzure(
166
+ azure_api_key=os.getenv("AZURE_API_KEY", ""),
167
+ azure_endpoint="your_azure_endpoint"
168
+ )
169
+
170
+ async def main() -> None:
171
+ res = await client.chat.create_async(
172
+ request={
173
+ "max_tokens": 100,
174
+ "temperature": 0.5,
175
+ "messages": [
176
+ {
177
+ "content": "Hello there!",
178
+ "role": "user"
179
+ }
180
+ ]
181
+ }
182
+ )
183
+ print(res)
184
+
185
+ asyncio.run(main())
186
+ ```
187
+ The documentation for the Azure SDK is available [here](/packages/mistralai_azure/README.md).
188
+
189
+ ### Google Cloud
190
+
191
+ **Prerequisites**
192
+
193
+ Before you begin, you will need to create a Google Cloud project and enable the Mistral API. To do this, follow the instructions [here](https://docs.mistral.ai/deployment/cloud/google/).
194
+
195
+ To run this locally you will also need to ensure you are authenticated with Google Cloud. You can do this by running
196
+
197
+ ```bash
198
+ gcloud auth application-default login
199
+ ```
200
+
201
+ **Step 1: Install**
202
+
203
+ Install the extras dependencies specific to Google Cloud:
204
+
205
+ ```bash
206
+ pip install mistralai[gcp]
207
+ ```
208
+
209
+ **Step 2: Example Usage**
210
+
211
+ Here's a basic example to get you started.
212
+
213
+ ```python
214
+ import asyncio
215
+ from mistralai_gcp import MistralGoogleCloud
216
+
217
+ client = MistralGoogleCloud()
218
+
219
+
220
+ async def main() -> None:
221
+ res = await client.chat.create_async(
222
+ request={
223
+ "model": "mistral-small-2402",
224
+ "messages": [
225
+ {
226
+ "content": "Hello there!",
227
+ "role": "user"
228
+ }
229
+ ]
230
+ }
231
+ )
232
+ print(res)
233
+
234
+ asyncio.run(main())
235
+ ```
236
+
237
+ The documentation for the GCP SDK is available [here](/packages/mistralai_gcp/README.md).
238
+
239
+
240
+ <!-- Start Available Resources and Operations [operations] -->
241
+ ## Available Resources and Operations
242
+
243
+ ### [models](docs/sdks/models/README.md)
244
+
245
+ * [list](docs/sdks/models/README.md#list) - List Models
246
+ * [retrieve](docs/sdks/models/README.md#retrieve) - Retrieve Model
247
+ * [delete](docs/sdks/models/README.md#delete) - Delete Model
248
+ * [update](docs/sdks/models/README.md#update) - Update Fine Tuned Model
249
+ * [archive](docs/sdks/models/README.md#archive) - Archive Fine Tuned Model
250
+ * [unarchive](docs/sdks/models/README.md#unarchive) - Unarchive Fine Tuned Model
251
+
252
+ ### [files](docs/sdks/files/README.md)
253
+
254
+ * [upload](docs/sdks/files/README.md#upload) - Upload File
255
+ * [list](docs/sdks/files/README.md#list) - List Files
256
+ * [retrieve](docs/sdks/files/README.md#retrieve) - Retrieve File
257
+ * [delete](docs/sdks/files/README.md#delete) - Delete File
258
+
259
+ ### [fine_tuning](docs/sdks/finetuning/README.md)
260
+
261
+ * [list_jobs](docs/sdks/finetuning/README.md#list_jobs) - Get Fine Tuning Jobs
262
+ * [create_job](docs/sdks/finetuning/README.md#create_job) - Create Fine Tuning Job
263
+ * [get_job](docs/sdks/finetuning/README.md#get_job) - Get Fine Tuning Job
264
+ * [cancel_job](docs/sdks/finetuning/README.md#cancel_job) - Cancel Fine Tuning Job
265
+ * [start_job](docs/sdks/finetuning/README.md#start_job) - Start Fine Tuning Job
266
+
267
+ ### [chat](docs/sdks/chat/README.md)
268
+
269
+ * [create](docs/sdks/chat/README.md#create) - Chat Completion
270
+ * [stream](docs/sdks/chat/README.md#stream) - Stream chat completion
271
+
272
+ ### [fim](docs/sdks/fim/README.md)
273
+
274
+ * [create](docs/sdks/fim/README.md#create) - Fim Completion
275
+ * [stream](docs/sdks/fim/README.md#stream) - Stream fim completion
276
+
277
+ ### [embeddings](docs/sdks/embeddings/README.md)
278
+
279
+ * [create](docs/sdks/embeddings/README.md#create) - Embeddings
280
+ <!-- End Available Resources and Operations [operations] -->
281
+
282
+ <!-- Start Server-sent event streaming [eventstream] -->
283
+ ## Server-sent event streaming
284
+
285
+ [Server-sent events][mdn-sse] are used to stream content from certain
286
+ operations. These operations will expose the stream as [Generator][generator] that
287
+ can be consumed using a simple `for` loop. The loop will
288
+ terminate when the server no longer has any events to send and closes the
289
+ underlying connection.
290
+
291
+ ```python
292
+ from mistralai import Mistral
293
+ import os
294
+
295
+ s = Mistral(
296
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
297
+ )
298
+
299
+
300
+ res = s.chat.stream(messages=[
301
+ {
302
+ "content": "Who is the best French painter? Answer in one short sentence.",
303
+ "role": "user",
304
+ },
305
+ ], model="mistral-small-latest")
306
+
307
+ if res is not None:
308
+ for event in res:
309
+ # handle event
310
+ print(event, flush=True)
311
+
312
+ ```
313
+
314
+ [mdn-sse]: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events
315
+ [generator]: https://wiki.python.org/moin/Generators
316
+ <!-- End Server-sent event streaming [eventstream] -->
317
+
318
+ <!-- Start File uploads [file-upload] -->
319
+ ## File uploads
320
+
321
+ Certain SDK methods accept file objects as part of a request body or multi-part request. It is possible and typically recommended to upload files as a stream rather than reading the entire contents into memory. This avoids excessive memory consumption and potentially crashing with out-of-memory errors when working with very large files. The following example demonstrates how to attach a file stream to a request.
322
+
323
+ > [!TIP]
324
+ >
325
+ > For endpoints that handle file uploads bytes arrays can also be used. However, using streams is recommended for large files.
326
+ >
327
+
328
+ ```python
329
+ from mistralai import Mistral
330
+ import os
331
+
332
+ s = Mistral(
333
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
334
+ )
335
+
336
+
337
+ res = s.files.upload(file={
338
+ "file_name": "your_file_here",
339
+ "content": open("<file_path>", "rb"),
340
+ })
341
+
342
+ if res is not None:
343
+ # handle response
344
+ pass
345
+
346
+ ```
347
+ <!-- End File uploads [file-upload] -->
348
+
349
+ <!-- Start Retries [retries] -->
350
+ ## Retries
351
+
352
+ Some of the endpoints in this SDK support retries. If you use the SDK without any configuration, it will fall back to the default retry strategy provided by the API. However, the default retry strategy can be overridden on a per-operation basis, or across the entire SDK.
353
+
354
+ To change the default retry strategy for a single API call, simply provide a `RetryConfig` object to the call:
355
+ ```python
356
+ from mistral.utils import BackoffStrategy, RetryConfig
357
+ from mistralai import Mistral
358
+ import os
359
+
360
+ s = Mistral(
361
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
362
+ )
363
+
364
+
365
+ res = s.models.list(,
366
+ RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False))
367
+
368
+ if res is not None:
369
+ # handle response
370
+ pass
371
+
372
+ ```
373
+
374
+ If you'd like to override the default retry strategy for all operations that support retries, you can use the `retry_config` optional parameter when initializing the SDK:
375
+ ```python
376
+ from mistral.utils import BackoffStrategy, RetryConfig
377
+ from mistralai import Mistral
378
+ import os
379
+
380
+ s = Mistral(
381
+ retry_config=RetryConfig("backoff", BackoffStrategy(1, 50, 1.1, 100), False),
382
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
383
+ )
384
+
385
+
386
+ res = s.models.list()
387
+
388
+ if res is not None:
389
+ # handle response
390
+ pass
391
+
392
+ ```
393
+ <!-- End Retries [retries] -->
394
+
395
+ <!-- Start Error Handling [errors] -->
396
+ ## Error Handling
397
+
398
+ Handling errors in this SDK should largely match your expectations. All operations return a response object or raise an error. If Error objects are specified in your OpenAPI Spec, the SDK will raise the appropriate Error type.
399
+
400
+ | Error Object | Status Code | Content Type |
401
+ | -------------------------- | ----------- | ---------------- |
402
+ | models.HTTPValidationError | 422 | application/json |
403
+ | models.SDKError | 4xx-5xx | */* |
404
+
405
+ ### Example
406
+
407
+ ```python
408
+ from mistralai import Mistral, models
409
+ import os
410
+
411
+ s = Mistral(
412
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
413
+ )
414
+
415
+ res = None
416
+ try:
417
+ res = s.models.list()
418
+
419
+ except models.HTTPValidationError as e:
420
+ # handle exception
421
+ raise(e)
422
+ except models.SDKError as e:
423
+ # handle exception
424
+ raise(e)
425
+
426
+ if res is not None:
427
+ # handle response
428
+ pass
429
+
430
+ ```
431
+ <!-- End Error Handling [errors] -->
432
+
433
+ <!-- Start Server Selection [server] -->
434
+ ## Server Selection
435
+
436
+ ### Select Server by Name
437
+
438
+ You can override the default server globally by passing a server name to the `server: str` optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:
439
+
440
+ | Name | Server | Variables |
441
+ | ------ | ------------------------ | --------- |
442
+ | `prod` | `https://api.mistral.ai` | None |
443
+
444
+ #### Example
445
+
446
+ ```python
447
+ from mistralai import Mistral
448
+ import os
449
+
450
+ s = Mistral(
451
+ server="prod",
452
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
453
+ )
454
+
455
+
456
+ res = s.models.list()
457
+
458
+ if res is not None:
459
+ # handle response
460
+ pass
461
+
462
+ ```
463
+
464
+
465
+ ### Override Server URL Per-Client
466
+
467
+ The default server can also be overridden globally by passing a URL to the `server_url: str` optional parameter when initializing the SDK client instance. For example:
468
+ ```python
469
+ from mistralai import Mistral
470
+ import os
471
+
472
+ s = Mistral(
473
+ server_url="https://api.mistral.ai",
474
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
475
+ )
476
+
477
+
478
+ res = s.models.list()
479
+
480
+ if res is not None:
481
+ # handle response
482
+ pass
483
+
484
+ ```
485
+ <!-- End Server Selection [server] -->
486
+
487
+ <!-- Start Custom HTTP Client [http-client] -->
488
+ ## Custom HTTP Client
489
+
490
+ The Python SDK makes API calls using the [httpx](https://www.python-httpx.org/) HTTP library. In order to provide a convenient way to configure timeouts, cookies, proxies, custom headers, and other low-level configuration, you can initialize the SDK client with your own HTTP client instance.
491
+ Depending on whether you are using the sync or async version of the SDK, you can pass an instance of `HttpClient` or `AsyncHttpClient` respectively, which are Protocol's ensuring that the client has the necessary methods to make API calls.
492
+ This allows you to wrap the client with your own custom logic, such as adding custom headers, logging, or error handling, or you can just pass an instance of `httpx.Client` or `httpx.AsyncClient` directly.
493
+
494
+ For example, you could specify a header for every request that this sdk makes as follows:
495
+ ```python
496
+ from mistralai import Mistral
497
+ import httpx
498
+
499
+ http_client = httpx.Client(headers={"x-custom-header": "someValue"})
500
+ s = Mistral(client=http_client)
501
+ ```
502
+
503
+ or you could wrap the client with your own custom logic:
504
+ ```python
505
+ from mistralai import Mistral
506
+ from mistralai.httpclient import AsyncHttpClient
507
+ import httpx
508
+
509
+ class CustomClient(AsyncHttpClient):
510
+ client: AsyncHttpClient
511
+
512
+ def __init__(self, client: AsyncHttpClient):
513
+ self.client = client
514
+
515
+ async def send(
516
+ self,
517
+ request: httpx.Request,
518
+ *,
519
+ stream: bool = False,
520
+ auth: Union[
521
+ httpx._types.AuthTypes, httpx._client.UseClientDefault, None
522
+ ] = httpx.USE_CLIENT_DEFAULT,
523
+ follow_redirects: Union[
524
+ bool, httpx._client.UseClientDefault
525
+ ] = httpx.USE_CLIENT_DEFAULT,
526
+ ) -> httpx.Response:
527
+ request.headers["Client-Level-Header"] = "added by client"
528
+
529
+ return await self.client.send(
530
+ request, stream=stream, auth=auth, follow_redirects=follow_redirects
531
+ )
532
+
533
+ def build_request(
534
+ self,
535
+ method: str,
536
+ url: httpx._types.URLTypes,
537
+ *,
538
+ content: Optional[httpx._types.RequestContent] = None,
539
+ data: Optional[httpx._types.RequestData] = None,
540
+ files: Optional[httpx._types.RequestFiles] = None,
541
+ json: Optional[Any] = None,
542
+ params: Optional[httpx._types.QueryParamTypes] = None,
543
+ headers: Optional[httpx._types.HeaderTypes] = None,
544
+ cookies: Optional[httpx._types.CookieTypes] = None,
545
+ timeout: Union[
546
+ httpx._types.TimeoutTypes, httpx._client.UseClientDefault
547
+ ] = httpx.USE_CLIENT_DEFAULT,
548
+ extensions: Optional[httpx._types.RequestExtensions] = None,
549
+ ) -> httpx.Request:
550
+ return self.client.build_request(
551
+ method,
552
+ url,
553
+ content=content,
554
+ data=data,
555
+ files=files,
556
+ json=json,
557
+ params=params,
558
+ headers=headers,
559
+ cookies=cookies,
560
+ timeout=timeout,
561
+ extensions=extensions,
562
+ )
563
+
564
+ s = Mistral(async_client=CustomClient(httpx.AsyncClient()))
565
+ ```
566
+ <!-- End Custom HTTP Client [http-client] -->
567
+
568
+ <!-- Start Authentication [security] -->
569
+ ## Authentication
570
+
571
+ ### Per-Client Security Schemes
572
+
573
+ This SDK supports the following security scheme globally:
574
+
575
+ | Name | Type | Scheme |
576
+ | --------- | ---- | ----------- |
577
+ | `api_key` | http | HTTP Bearer |
578
+
579
+ To authenticate with the API the `api_key` parameter must be set when initializing the SDK client instance. For example:
580
+ ```python
581
+ from mistralai import Mistral
582
+ import os
583
+
584
+ s = Mistral(
585
+ api_key=os.getenv("MISTRAL_API_KEY", ""),
586
+ )
587
+
588
+
589
+ res = s.models.list()
590
+
591
+ if res is not None:
592
+ # handle response
593
+ pass
594
+
595
+ ```
596
+ <!-- End Authentication [security] -->
597
+ ## Providers Support
598
+
599
+ We also provide provider specific SDK for:
600
+
601
+ - [GCP](packages/mistralai_gcp/README.md)
602
+ - [Azure](packages/mistralai_azure/README.md)
603
+
604
+
605
+ <!-- Placeholder for Future Speakeasy SDK Sections -->
606
+
607
+ # Development
608
+
609
+ ## Maturity
610
+
611
+ This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage
612
+ to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally
613
+ looking for the latest version.
614
+
615
+ ## Contributions
616
+
617
+ While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation.
618
+ We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.
619
+
620
+ ### SDK Created by [Speakeasy](https://docs.speakeasyapi.dev/docs/using-speakeasy/client-sdks)
621
+