pythonbeginner
Mistral AI API Client in Python
Make chat and embedding requests to Mistral AI using the official Python SDK.
pythonPress ⌘/Ctrl + Shift + C to copy
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.
pythonbeginner
LangChain Prompt Chain (Python)
Build a simple LLMChain with a prompt template and ChatOpenAI in LangChain.
Best for: prompt chaining
#langchain#openai
pythonintermediate
FastAPI Dependency Injection
Use FastAPI's dependency injection for database sessions, auth checks, and shared service logic.
Best for: Database session management
#fastapi#dependency-injection
typescriptintermediate
OpenAI Chat Completion with Streaming
Stream GPT responses token-by-token using the OpenAI SDK with async iteration.
Best for: chatbot UI
#openai#streaming
typescriptadvanced
RAG Pipeline (Retrieve + Augment + Generate)
Minimal RAG implementation: embed a query, retrieve top-k chunks, inject into prompt.
Best for: document Q&A
#rag#embeddings