by Salim K.

A TypeScript/ESM SDK for the Mistral AI API covering chat completions, embeddings, agents, fine-tuning, batch jobs, file uploads, FIM, and more. Includes dedicated adapters for Azure and GCP.
This block ships the full @mistralai/mistralai v2 TypeScript SDK source, giving you typed access to Mistral's chat completion, agents, audio transcription, batch jobs, fine-tuning, embeddings, and real-time transcription APIs. It is aimed at Node.js/TypeScript backend developers who want to call Mistral models or manage platform resources programmatically. The SDK is ESM-only and uses Zod for runtime validation throughout.
source/index.ts — Top-level re-export barrel; the single entry-point for all public symbols.source/core.ts — Internal SDK core utilities (request building, retries, auth).source/sdk/ — The Mistral class and all resource sub-clients (chat, agents, files, etc.).source/funcs/ — Standalone tree-shakeable functions for every API operation.source/models/ — Zod-validated request/response types and error classes.source/hooks/ — Lifecycle hooks interface for middleware/interceptors.source/lib/ — HTTP client, config, file helpers, and other shared utilities.source/types/ — Shared TypeScript utility types used across the SDK.source/extra/ — Non-generated helpers: structured chat, real-time WebSocket transcription.source/extra/realtime/ — RealtimeConnection and RealtimeTranscription for live audio.npm install zod zod-to-json-schema ws
npm install --save-dev @types/ws
No native modules, no pod install, no Android linking steps required. The SDK targets modern Node.js (≥18) or any runtime listed in RUNTIMES.md bundled with the source.
Copy the source tree. Place the contents of source/ at e.g. src/mistral/ inside your project.
TypeScript config. Ensure moduleResolution is set to "bundler" or "node16" so that .js extension imports resolve correctly:
{
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "bundler",
"target": "ES2022",
"strict": true
}
}
Spin up an isolated sandbox and run it server-side — no local setup.
Tetrees AI Review of this version
This TypeScript cli / script completed archive review. Structure, dependency manifests, documentation, functional source, and common risk patterns were checked by the Tetrees verification pipeline; runtime phases are stated separately.
Deterministic AVCP artifact review
Pipeline avcp-2026-08-04.1 · SHA-256 48026a5a170a3f18…
This version-scoped review deterministically inspects the submitted archive for structure, dependencies, documentation, functional source, and common malicious or high-risk signals. Build and test phases are reported as passed only after an isolated sandbox audition. It is not a guarantee of perfect security.
Reviewed Aug 4, 2026
Push this product straight into your AI IDE, web builder or cloud IDE.
Connect Tetrees to a compatible AI IDE, list products you own, and request the verified ZIP without exposing seller upload controls.
No reviews yet.
Sign in to join the discussion
Loading discussion…
"type": "module" to your package.json. If you use CommonJS, dynamic-import the SDK:const { Mistral } = await import("./mistral/index.js");
export MISTRAL_API_KEY="your-key-here"
tsconfig.json add a path alias so imports stay clean:{
"compilerOptions": {
"paths": {
"@mistral/*": ["./src/mistral/*"]
}
}
}
import { Mistral } from "./mistral/index.js";
const client = new Mistral({ apiKey: string; serverURL?: string });
The root SDK client. Exposes resource sub-clients as properties: client.chat, client.agents, client.files, client.models, client.batch, client.finetuning, client.embeddings, client.audio, and beta namespaces. Instantiate once and reuse across your application.
import { HTTPClient } from "./mistral/index.js";
const http = new HTTPClient(options?: HTTPClientOptions);
A configurable fetch wrapper you can pass to Mistral to override the default fetch implementation, add proxy support, or inject custom headers. Pass it via new Mistral({ apiKey, httpClient: http }).
import { RealtimeConnection } from "./mistral/extra/realtime/index.js";
WebSocket-based connection class for Mistral's real-time transcription API. Manages connection lifecycle, emits typed RealtimeEvent objects, and underlies RealtimeTranscription. Use this when you need raw event-level control over the WebSocket session.
import { RealtimeTranscription } from "./mistral/extra/realtime/index.js";
Higher-level wrapper around RealtimeConnection that handles session creation, audio streaming, and exposes transcript segment/text delta events. Use this for live microphone or audio-stream transcription.
import { SDKError, MistralError } from "./mistral/models/errors/index.js";
Base error classes thrown by all SDK operations. MistralError carries structured API error detail. Catch these in your error boundary to distinguish Mistral API errors from network failures.
Send a single user message and log the assistant's reply.
import { Mistral } from "./mistral/index.js";
const client = new Mistral({ apiKey: process.env.MISTRAL_API_KEY ?? "" });
const result = await client.chat.complete({
model: "mistral-large-latest",
messages: [
{ role: "user", content: "Explain ESM modules in one sentence." },
],
});
console.log(result.choices?.[0]?.message?.content);
Use server-sent events to stream tokens as they arrive.
import { Mistral } from "./mistral/index.js";
const client = new Mistral({ apiKey: process.env.MISTRAL_API_KEY ?? "" });
const stream = await client.chat.stream({
model: "mistral-small-latest",
messages: [{ role: "user", content: "Count to five, one word per line." }],
});
for await (const event of stream) {
const delta = event.data?.choices?.[0]?.delta?.content;
if (delta) process.stdout.write(delta);
}
Use an individual function import instead of the class-based client to keep bundle size minimal.
import { Mistral } from "./mistral/index.js";
import { agentsComplete } from "./mistral/funcs/agentsComplete.js";
const client = new Mistral({ apiKey: process.env.MISTRAL_API_KEY ?? "" });
const result = await agentsComplete(client, {
messages: [{ role: "user", content: "Summarise today's weather briefly." }],
agentId: "ag:your-agent-id",
});
console.log(result);
Stream microphone audio over a WebSocket and receive live transcripts.
import { RealtimeTranscription } from "./mistral/extra/realtime/index.js";
import type { RealtimeEvent } from "./mistral/extra/realtime/index.js";
const rt = new RealtimeTranscription({
apiKey: process.env.MISTRAL_API_KEY ?? "",
});
await rt.connect();
rt.on("event", (event: RealtimeEvent) => {
if (event.type === "transcription.stream.text_delta") {
process.stdout.write(event.delta ?? "");
}
});
// pipe your audio Buffer chunks:
// rt.sendAudio(buffer);
index.ts — Re-exports everything from lib/config.js, lib/http.js, lib/files.js, and the main sdk/sdk.js. Start imports here.core.ts — Internal plumbing: pagination cursors, retry logic, auth header injection. Not typically imported directly.sdk/ — Houses the Mistral class definition and all resource sub-clients. Each sub-client maps to one API surface area.funcs/ — One file per API operation, exported as standalone async functions. Prefer these in serverless/edge environments for tree-shaking.models/components/ — Zod schemas and inferred TypeScript types for every request and response shape.models/errors/ — Typed error classes: SDKError, MistralError, SDKValidationError, HTTPValidationError, ResponseValidationError.hooks/ — BeforeRequestHook, AfterSuccessHook, AfterErrorHook interfaces for middleware registration.lib/ — HTTPClient, SDKOptions/config, file-upload helpers, and fetch utilities.types/ — Shared utility generics used internally (e.g. PageIterator, Result).extra/structChat.ts — Helper for building structured/tool-use chat requests.extra/realtime/connection.ts — Low-level RealtimeConnection WebSocket class.extra/realtime/transcription.ts — RealtimeTranscription high-level audio transcription helper.extra/realtime/index.ts — Barrel re-exporting all realtime types and classes.ERR_REQUIRE_ESM in CommonJS projects. The package is ESM-only; use await import("./mistral/index.js") or convert your project to "type": "module"..js extension resolution errors. TypeScript path imports end in .js (even for .ts files); set "moduleResolution": "bundler" or "node16" in tsconfig.json.MISTRAL_API_KEY. The client does not throw until the first request; set the env var or pass apiKey explicitly to the Mistral constructor.ws peer dep not installed. RealtimeConnection requires the ws package at runtime; install it and @types/ws explicitly as shown above.zod@^4); installing Zod v3 will cause silent schema failures. Pin to zod@^4.for await SSE streaming requires a runtime with ReadableStream support; on older Node versions (< 18) polyfill the Web Streams API or upgrade Node.I have dropped the Mistral AI TypeScript SDK source into `src/mistral/` in my project.
The integration guide is in `USAGE.md`. The upstream package is `@mistralai/mistralai@2.2.1`.
Please help me integrate this SDK into my existing project step-by-step:
1. Read `USAGE.md` fully before writing any code.
2. Install the required runtime dependencies listed in USAGE.md.
3. Update `tsconfig.json` as described in the Project Setup section.
4. Create a singleton `src/lib/mistralClient.ts` that instantiates `Mistral` from
`src/mistral/index.ts` using `process.env.MISTRAL_API_KEY`.
5. Add a `src/services/chatService.ts` that wraps `client.chat.complete(...)` and
`client.chat.stream(...)` with proper TypeScript types and error handling
(catching `MistralError` from `src/mistral/models/errors/index.ts`).
6. Show me how to use the standalone function imports from `src/mistral/funcs/` for
any route handlers where tree-shaking matters.
7. If my project uses Express, add example route handlers.
Only use symbols and imports visible in USAGE.md and the source files. Do not invent APIs.
The SDK source is generated by Speakeasy on behalf of Mistral AI. See source/LICENSE if present for the full license text, or refer to the upstream npm package (@mistralai/mistralai@2.2.1) and the GitHub repository for official license and attribution information.
This product’s unique contribution is clean room implementation of valuable code block into AVCP compatible standard.
The full install guide and integration prompts unlock after purchase.
SaaS, AI & Subscription Products
Free