Integrate Mistral AI models using the AI SDK provider. Supports Mistral chat API with streaming, text generation, and structured outputs.
This skill enables you to integrate Mistral AI models into your application using the AI SDK Mistral provider. It provides access to Mistral's chat API with support for text generation, streaming, and structured outputs.
Configures and integrates the `@ai-sdk/mistral` provider package to enable:
First, install the `@ai-sdk/mistral` package:
```bash
npm i @ai-sdk/mistral
```
If the AI SDK core is not already installed, also install:
```bash
npm i ai
```
Create or update your `.env.local` file with your Mistral API key:
```
MISTRAL_API_KEY=your_mistral_api_key_here
```
The API key can be obtained from the [Mistral AI Console](https://console.mistral.ai/).
In your code, import the Mistral provider:
```typescript
import { mistral } from '@ai-sdk/mistral';
import { generateText } from 'ai';
```
Available models include:
Example implementation for text generation:
```typescript
import { mistral } from '@ai-sdk/mistral';
import { generateText } from 'ai';
const { text } = await generateText({
model: mistral('mistral-large-latest'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
console.log(text);
```
For streaming text generation:
```typescript
import { mistral } from '@ai-sdk/mistral';
import { streamText } from 'ai';
const result = await streamText({
model: mistral('mistral-large-latest'),
prompt: 'Explain quantum computing in simple terms.',
});
for await (const textPart of result.textStream) {
process.stdout.write(textPart);
}
```
Generate structured data with type safety:
```typescript
import { mistral } from '@ai-sdk/mistral';
import { generateObject } from 'ai';
import { z } from 'zod';
const { object } = await generateObject({
model: mistral('mistral-large-latest'),
schema: z.object({
recipe: z.object({
name: z.string(),
ingredients: z.array(z.string()),
steps: z.array(z.string()),
}),
}),
prompt: 'Generate a simple pasta recipe.',
});
console.log(object.recipe);
```
Build conversational interfaces:
```typescript
import { mistral } from '@ai-sdk/mistral';
import { generateText } from 'ai';
const { text } = await generateText({
model: mistral('mistral-large-latest'),
messages: [
{ role: 'user', content: 'What is the capital of France?' },
{ role: 'assistant', content: 'The capital of France is Paris.' },
{ role: 'user', content: 'What is its population?' },
],
});
console.log(text);
```
The Mistral provider supports standard AI SDK options:
Example with options:
```typescript
const { text } = await generateText({
model: mistral('mistral-large-latest'),
prompt: 'Write a haiku about coding',
temperature: 0.7,
maxTokens: 100,
});
```
```typescript
import { mistral } from '@ai-sdk/mistral';
import { generateText } from 'ai';
const { text } = await generateText({
model: mistral('mistral-large-latest'),
prompt: 'Explain recursion in programming',
});
```
```typescript
import { mistral } from '@ai-sdk/mistral';
import { streamText } from 'ai';
const result = await streamText({
model: mistral('mistral-small-latest'),
messages: [
{ role: 'user', content: 'Tell me a joke' },
],
});
for await (const chunk of result.textStream) {
process.stdout.write(chunk);
}
```
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/mistral-ai-provider-integration/raw