pythonbeginner

Mistral AI API Client in Python

Make chat and embedding requests to Mistral AI using the official Python SDK.

python
from mistralai import Mistral

client = Mistral(api_key='YOUR_MISTRAL_API_KEY')

# Chat completion
response = client.chat.complete(
    model='mistral-large-latest',
    messages=[{'role':'user','content':'Explain RAG in two sentences.'}],
)
print(response.choices[0].message.content)

# Embeddings
embeddings = client.embeddings.create(
    model='mistral-embed',
    inputs=['Hello world', 'Machine learning is fun'],
)
for e in embeddings.data:
    print(f'Embedding dim: {len(e.embedding)}')

Use Cases

  • European AI compliance
  • cost-effective LLMs
  • embedding generation

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.