Create a minimal working Mistral AI chat completion example. Use when starting a new Mistral integration, testing your setup, or learning basic Mistral API patterns. Trigger with phrases like "mistral hello world", "mistral example", "mistral quick start", "simple mistral code", "mistral chat".
From mistral-packnpx claudepluginhub nickloveinvesting/nick-love-plugins --plugin mistral-packThis skill is limited to using the following tools:
Guides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
Migrates code, prompts, and API calls from Claude Sonnet 4.0/4.5 or Opus 4.1 to Opus 4.5, updating model strings on Anthropic, AWS, GCP, Azure platforms.
Details PluginEval's skill quality evaluation: 3 layers (static, LLM judge), 10 dimensions, rubrics, formulas, anti-patterns, badges. Use to interpret scores, improve triggering, calibrate thresholds.
Minimal working example demonstrating core Mistral AI chat completion functionality.
mistral-install-auth setupTypeScript (hello-mistral.ts)
import Mistral from '@mistralai/mistralai';
const client = new Mistral({
apiKey: process.env.MISTRAL_API_KEY,
});
async function main() {
const response = await client.chat.complete({
model: 'mistral-small-latest',
messages: [
{ role: 'user', content: 'Say "Hello, World!" in a creative way.' }
],
});
console.log(response.choices?.[0]?.message?.content);
}
main().catch(console.error);
Python (hello_mistral.py)
import os
from mistralai import Mistral
client = Mistral(api_key=os.environ.get("MISTRAL_API_KEY"))
def main():
response = client.chat.complete(
model="mistral-small-latest",
messages=[
{"role": "user", "content": "Say 'Hello, World!' in a creative way."}
],
)
print(response.choices[0].message.content)
if __name__ == "__main__":
main()
# TypeScript
npx tsx hello-mistral.ts
# Python
python hello_mistral.py
TypeScript Streaming
import Mistral from '@mistralai/mistralai';
const client = new Mistral({
apiKey: process.env.MISTRAL_API_KEY,
});
async function streamChat() {
const stream = await client.chat.stream({
model: 'mistral-small-latest',
messages: [
{ role: 'user', content: 'Tell me a short story about AI.' }
],
});
for await (const event of stream) {
const content = event.data?.choices?.[0]?.delta?.content;
if (content) {
process.stdout.write(content);
}
}
console.log(); // newline
}
streamChat().catch(console.error);
Python Streaming
import os
from mistralai import Mistral
client = Mistral(api_key=os.environ.get("MISTRAL_API_KEY"))
def stream_chat():
stream = client.chat.stream(
model="mistral-small-latest",
messages=[
{"role": "user", "content": "Tell me a short story about AI."}
],
)
for event in stream:
content = event.data.choices[0].delta.content
if content:
print(content, end="", flush=True)
print() # newline
if __name__ == "__main__":
stream_chat()
Hello, World!
(But spoken by a million synchronized starlings,
spelling it across the twilight sky...)
| Error | Cause | Solution |
|---|---|---|
| Import Error | SDK not installed | Verify with npm list @mistralai/mistralai |
| Auth Error | Invalid credentials | Check MISTRAL_API_KEY is set |
| Timeout | Network issues | Increase timeout or check connectivity |
| Rate Limit | Too many requests | Wait and retry with exponential backoff |
const messages = [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'What is the capital of France?' },
];
const response1 = await client.chat.complete({
model: 'mistral-small-latest',
messages,
});
// Add assistant response to conversation
messages.push({
role: 'assistant',
content: response1.choices?.[0]?.message?.content || '',
});
// Continue conversation
messages.push({ role: 'user', content: 'What about Germany?' });
const response2 = await client.chat.complete({
model: 'mistral-small-latest',
messages,
});
console.log(response2.choices?.[0]?.message?.content);
const response = await client.chat.complete({
model: 'mistral-small-latest',
messages: [{ role: 'user', content: 'Write a haiku about coding.' }],
temperature: 0.7, // 0-1, higher = more creative
maxTokens: 100,
});
Proceed to mistral-local-dev-loop for development workflow setup.