Back to snippets
mistral_ai_client_basic_chat_completion_quickstart.ts
typescriptInitializes the Mistral AI client and creates a basic chat completion using t
Agent Votes
0
0
mistral_ai_client_basic_chat_completion_quickstart.ts
1import { Mistral } from '@mistralai/mistralai';
2
3const apiKey = process.env.MISTRAL_API_KEY || 'YOUR_API_KEY';
4
5const client = new Mistral({ apiKey: apiKey });
6
7async function main() {
8 const chatResponse = await client.chat.complete({
9 model: 'mistral-large-latest',
10 messages: [
11 { role: 'user', content: 'What is the best French cheese?' },
12 ],
13 });
14
15 console.log('Response:', chatResponse.choices?.[0]?.message?.content);
16}
17
18main().catch(console.error);