api-ai-mistral-sdk
Official Mistral AI TypeScript SDK patterns — client setup, chat completions, streaming, function calling, structured outputs, embeddings, vision, Codestral FIM, and production best practices
npx skills add majiayu000/claude-skill-registry --skill api-ai-mistral-sdk --agent claude-code
Same command for any agent — swap --agent for codex, cursor, copilot.
Weekly change comes from our own snapshots, not the repository page — it measures attention, not adoption.
What it does
Guides developers on using the Mistral SDK in TypeScript, detailing how to initialize the client, perform chat completions and streaming, parse structured outputs with Zod, handle function calling with a tool loop, create embeddings, process vision tasks with Pixtral, and use Codestral FIM. It presents concrete method names and patterns to implement production-ready interactions with Mistral models.
How it works
- Client initialization examples show reading the API key from an environment variable and optional production configuration with timeout and retryConfig.
- Chat completions use
chat.complete()with a model likemistral-large-latestand a messages array; streaming useschat.stream()with an async iteration pattern and accessesevent.data.choices[0]?.delta?.contentfor content. - Structured outputs employ
chat.parse()with a Zod schema passed viaresponseFormatand accessresult.choices?.[0]?.message?.parsedfor typed results. - Function calling demonstrates defining
tools, usingtoolChoice, and inspectingtoolCallsto extract function arguments. - Embeddings are created with
embeddings.createusinginputsplural, and the resulting embeddings are read fromresult.data. - Vision patterns show sending image references via
imageUrlwithin messages. - Codestral FIM uses
fim.complete()withpromptandsuffixto produce a completion. - Error handling and production patterns emphasize explicit retry configuration, timeout usage, and specific error types.
When to use it
- Building applications that call Mistral models directly
- Implementing chat completions with SSE streaming
- Using Codestral for code generation and FIM
- Extracting structured data with
client.chat.parse()and Zod schemas - Implementing function calling / tool use
- Creating embeddings for RAG pipelines or semantic search
- Processing images with Pixtral / vision-capable models
- Using Mistral Agents API for pre-configured agent completions
What it can touch
@mistralai/mistralaiSDK usage includingclient.chat.complete,client.chat.stream,client.chat.parse,client.fim.complete, andclient.embeddings.create.- Environment variable
MISTRAL_API_KEYfor authentication. - Zod schemas passed to
responseFormatfor structured outputs. - Tool definitions and
toolCallshandling in the tool call loop.
Caveats
- The SDK defaults to
strategy: "none"for retries; retries must be configured explicitly for production. - Streaming results must be consumed with
for await (const event of result)and access content viaevent.data.choices[0]?.delta?.content. - Do not use snake_case properties; the patterns require camelCase (e.g.,
responseFormat,maxTokens). - Keys must be read from
process.env["MISTRAL_API_KEY"]using bracket notation.
# Mistral SDK Patterns > **Quick Guide:** Use `@mistralai/mistralai` (ESM-only) to interact with Mistral's API. Use `client.chat.complete()` for chat, `client.chat.stream()` for streaming (async iterable via `for await`), `client.chat.parse()` with a Zod schema for structured outputs, and `client.fim.complete()` for Codestral fill-in-middle code completion. The SDK uses `responseFormat` (camelCase) not `response_format`. Streaming events expose content via `event.data.choices[0]?.delta?.content`. Retries default to `strategy: "none"` -- you must configure them explicitly for production. --- <critical_requirements> ## CRITICAL: Before Using This Skill > **All code must follow project conventions in CLAUDE.md** (kebab-case, named exports, import ordering, `import type`, named constants) **(You MUST use `responseFormat` (camelCase) in SDK calls -- NOT `response_format` (snake_case). The SDK uses camelCase property names throughout.)** **(You MUST configure retries explicitly -- the SDK defaults to `strategy: "none"` (no retries), unlike OpenAI's SDK which retries automatically)** **(You MUST consume streaming results with `for await (const event of result)` and access content via `eve
- CRITICAL: Before Using This Skill
- Examples Index
- Philosophy
- Core Patterns
- Pattern 1: Client Setup
- Pattern 2: Chat Completions
- Pattern 3: Streaming
- Pattern 4: Structured Outputs with Zod
- Pattern 5: Function Calling / Tool Use
- Pattern 6: Embeddings
- Pattern 7: Vision (Pixtral)
- Pattern 8: Codestral FIM
- Pattern 9: Error Handling
- Performance Optimization
What does the api-ai-mistral-sdk skill do?
Official Mistral AI TypeScript SDK patterns — client setup, chat completions, streaming, function calling, structured outputs, embeddings, vision, Codestral FIM, and production best practices
How do I install it?
Run `npx skills add majiayu000/claude-skill-registry --skill api-ai-mistral-sdk --agent claude-code` — it drops the skill into your project so the agent can pick it up. Swap the --agent value for codex, cursor or copilot if you use one of those.
Where does this skill come from?
From majiayu000/claude-skill-registry, a repository with 534 stars. We read it straight from the repository tree rather than a submitted listing, so what you see here is what is actually published.
Is a popular skill a good skill?
Not necessarily. Stars measure attention, not adoption — a repository can trend for a week and be abandoned. That is why we show the weekly change from our own snapshots next to the total, instead of a single flattering number.
