mistralai/client-ts
TypeScript
Captured source
source ↗mistralai/client-ts
Description: TS Client library for Mistral AI platform
Language: TypeScript
License: Apache-2.0
Stars: 145
Forks: 41
Open issues: 15
Created: 2024-08-07T11:54:28Z
Pushed: 2026-06-09T13:28:46Z
Default branch: main
Fork: no
Archived: no
README:
Mistral Typescript Client
> This is v2 of the Mistral TypeScript SDK. > > Key changes from v1: ESM-only, shorter type names, forward-compatible enums/unions, Zod v4. > See the [Migration Guide](https://github.com/mistralai/client-ts/blob/main/MIGRATION.md) for full details. > > To pin v1: npm install @mistralai/mistralai@^1 · [v1 documentation and source](https://github.com/mistralai/client-ts/tree/v1)
Summary
Mistral AI API: Our Chat Completion and Embeddings APIs specification. Create your account on La Plateforme to get access and read the docs to learn how to use it.
Table of Contents
- [Mistral Typescript Client](#mistral-typescript-client)
- [SDK Installation](#sdk-installation)
- [Requirements](#requirements)
- [API Key Setup](#api-key-setup)
- [SDK Example Usage](#sdk-example-usage)
- [Providers' SDKs](#providers-sdks)
- [Available Resources and Operations](#available-resources-and-operations)
- [Server-sent event streaming](#server-sent-event-streaming)
- [Pagination](#pagination)
- [File uploads](#file-uploads)
- [Retries](#retries)
- [Error Handling](#error-handling)
- [Server Selection](#server-selection)
- [Custom HTTP Client](#custom-http-client)
- [Authentication](#authentication)
- [Standalone functions](#standalone-functions)
- [Debugging](#debugging)
- [Development](#development)
- [Contributions](#contributions)
SDK Installation
The SDK can be installed with either npm, pnpm, bun or yarn package managers.
NPM
npm add @mistralai/mistralai
PNPM
pnpm add @mistralai/mistralai
Bun
bun add @mistralai/mistralai
Yarn
yarn add @mistralai/mistralai
> [!NOTE] > This package is published as an ES Module (ESM) only. For applications using > CommonJS, use await import("@mistralai/mistralai") to import and use this package.
Requirements
For supported JavaScript runtimes, please consult [RUNTIMES.md](RUNTIMES.md).
API Key Setup
Before you begin, you will need a Mistral AI API key.
1. Get your own Mistral API Key: 2. Set your Mistral API Key as an environment variable. You only need to do this once.
# set Mistral API Key (using zsh for example) $ echo 'export MISTRAL_API_KEY=[your_key_here]' >> ~/.zshenv # reload the environment (or just quit and open a new terminal) $ source ~/.zshenv
SDK Example Usage
Create Chat Completions
This example shows how to create chat completions.
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.chat.complete({
model: "mistral-large-latest",
messages: [
{
role: "user",
content:
"Who is the best French painter? Answer in one short sentence.",
},
],
responseFormat: {
type: "text",
},
});
console.log(result);
}
run();Upload a file
This example shows how to upload a file.
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();Create Agents Completions
This example shows how to create agents completions.
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.agents.complete({
messages: [
{
role: "user",
content:
"Who is the best French painter? Answer in one short sentence.",
},
],
responseFormat: {
type: "text",
},
agentId: "",
});
console.log(result);
}
run();Create Embedding Request
This example shows how to create embedding request.
import { Mistral } from "@mistralai/mistralai";
const mistral = new Mistral({
apiKey: process.env["MISTRAL_API_KEY"] ?? "",
});
async function run() {
const result = await mistral.embeddings.create({
model: "mistral-embed",
inputs: [
"Embed this sentence.",
"As well as this one.",
],
});
console.log(result);
}
run();Providers' SDKs
We have dedicated SDKs for the following providers:
Available Resources and Operations
Available methods
[Agents](docs/sdks/agents/README.md)
- [complete](docs/sdks/agents/README.md#complete) - Agents Completion
- [stream](docs/sdks/agents/README.md#stream) - Stream Agents completion
[Audio.Speech](docs/sdks/speech/README.md)
- [complete](docs/sdks/speech/README.md#complete) - Speech
[Audio.Transcriptions](docs/sdks/transcriptions/README.md)
- [complete](docs/sdks/transcriptions/README.md#complete) - Create Transcription
- [stream](docs/sdks/transcriptions/README.md#stream) - Create Streaming Transcription (SSE)
[Audio.Voices](docs/sdks/voices/README.md)
- [list](docs/sdks/voices/README.md#list) - List all voices
- [create](docs/sdks/voices/README.md#create) - Create a new voice
- [delete](docs/sdks/voices/README.md#delete) - Delete a custom voice
- [update](docs/sdks/voices/README.md#update) - Update voice metadata
- [get](docs/sdks/voices/README.md#get) - Get voice details
- [getSampleAudio](docs/sdks/voices/README.md#getsampleaudio) - Get voice sample audio
[Batch.Jobs](docs/sdks/batchjobs/README.md)
- [list](docs/sdks/batchjobs/README.md#list) - Get Batch Jobs
- [create](docs/sdks/batchjobs/README.md#create) - Create Batch Job
- [get](docs/sdks/batchjobs/README.md#get) - Get Batch Job
- [delete](docs/sdks/batchjobs/README.md#delete) - Delete Batch Job
- [cancel](docs/sdks/batchjobs/README.md#cancel) - Cancel Batch Job
[Beta.Agents](docs/sdks/betaagents/README.md)
- [create](docs/sdks/betaagents/README.md#create) - Create a agent that can be used within a conversation.
*…
Excerpt shown — open the source for the full document.
Notability
notability 4.0/10New client library, low stars