Files
(files)
Overview
Files API
Available Operations
- upload - Upload File
- list - List Files
- retrieve - Retrieve File
- delete - Delete File
- download - Download File
- getSignedUrl - Get Signed Url
upload
Upload a file that can be used across various endpoints.
The size of individual files can be a maximum of 512 MB. The Fine-tuning API only supports .jsonl files.
Please contact us if you need to increase these storage limits.
Example Usage
import { Mistral } from "@mistralai/mistralai";
import { openAsBlob } from "node:fs";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.files.upload({
file: await openAsBlob("example.file"),
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:
import { MistralCore } from "@mistralai/mistralai/core.js";
import { filesUpload } from "@mistralai/mistralai/funcs/filesUpload.js";
import { openAsBlob } from "node:fs";
// Use `MistralCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const mistral = new MistralCore({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const res = await filesUpload(mistral, {
file: await openAsBlob("example.file"),
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("filesUpload failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.FilesApiRoutesUploadFileMultiPartBodyParams | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.UploadFileOut>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4XX, 5XX | */* |
list
Returns a list of files that belong to the user's organization.
Example Usage
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.files.list({});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:
import { MistralCore } from "@mistralai/mistralai/core.js";
import { filesList } from "@mistralai/mistralai/funcs/filesList.js";
// Use `MistralCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const mistral = new MistralCore({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const res = await filesList(mistral, {});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("filesList failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.FilesApiRoutesListFilesRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.ListFilesOut>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4XX, 5XX | */* |
retrieve
Returns information about a specific file.
Example Usage
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.files.retrieve({
fileId: "f2a27685-ca4e-4dc2-9f2b-88c422c3e0f6",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:
import { MistralCore } from "@mistralai/mistralai/core.js";
import { filesRetrieve } from "@mistralai/mistralai/funcs/filesRetrieve.js";
// Use `MistralCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const mistral = new MistralCore({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const res = await filesRetrieve(mistral, {
fileId: "f2a27685-ca4e-4dc2-9f2b-88c422c3e0f6",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("filesRetrieve failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.FilesApiRoutesRetrieveFileRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.RetrieveFileOut>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4XX, 5XX | */* |
delete
Delete a file.
Example Usage
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.files.delete({
fileId: "3b6d45eb-e30b-416f-8019-f47e2e93d930",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:
import { MistralCore } from "@mistralai/mistralai/core.js";
import { filesDelete } from "@mistralai/mistralai/funcs/filesDelete.js";
// Use `MistralCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const mistral = new MistralCore({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const res = await filesDelete(mistral, {
fileId: "3b6d45eb-e30b-416f-8019-f47e2e93d930",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("filesDelete failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.FilesApiRoutesDeleteFileRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.DeleteFileOut>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4XX, 5XX | */* |
download
Download a file
Example Usage
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.files.download({
fileId: "f8919994-a4a1-46b2-8b5b-06335a4300ce",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:
import { MistralCore } from "@mistralai/mistralai/core.js";
import { filesDownload } from "@mistralai/mistralai/funcs/filesDownload.js";
// Use `MistralCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const mistral = new MistralCore({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const res = await filesDownload(mistral, {
fileId: "f8919994-a4a1-46b2-8b5b-06335a4300ce",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("filesDownload failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.FilesApiRoutesDownloadFileRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<ReadableStream>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4XX, 5XX | */* |
getSignedUrl
Get Signed Url
Example Usage
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.files.getSignedUrl({
fileId: "06a020ab-355c-49a6-b19d-304b7c01699f",
});
console.log(result);
}
run();
Standalone function
The standalone function version of this method:
import { MistralCore } from "@mistralai/mistralai/core.js";
import { filesGetSignedUrl } from "@mistralai/mistralai/funcs/filesGetSignedUrl.js";
// Use `MistralCore` for best tree-shaking performance.
// You can create one instance of it to use across an application.
const mistral = new MistralCore({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const res = await filesGetSignedUrl(mistral, {
fileId: "06a020ab-355c-49a6-b19d-304b7c01699f",
});
if (res.ok) {
const { value: result } = res;
console.log(result);
} else {
console.log("filesGetSignedUrl failed:", res.error);
}
}
run();
Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
request |
operations.FilesApiRoutesGetSignedUrlRequest | ✔️ | The request object to use for the request. |
options |
RequestOptions | ➖ | Used to set various options for making HTTP requests. |
options.fetchOptions |
RequestInit | ➖ | Options that are passed to the underlying HTTP request. This can be used to inject extra headers for examples. All Request options, except method and body, are allowed. |
options.retries |
RetryConfig | ➖ | Enables retrying HTTP requests under certain failure conditions. |
Response
Promise<components.FileSignedURL>
Errors
| Error Type | Status Code | Content Type |
|---|---|---|
| errors.SDKError | 4XX, 5XX | */* |