For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
DiscordPlatform
DocumentationIntegrationsAPI referenceSDKsChangelog
DocumentationIntegrationsAPI referenceSDKsChangelog
    • Overview
  • Tracing
      • OpenAI SDK
      • Instructor
      • Anthropic SDK
      • Google GenAI
      • LiteLLM
      • RubyLLM
      • Vertex AI
      • AWS Bedrock
      • Cohere
      • Groq
      • Mistral AI
      • Ollama
      • Portkey
      • Watsonx
      • Together AI
      • Aleph Alpha
      • HuggingFace
      • Replicate
      • SageMaker
      • Respan API
  • Gateway
  • Others
  • Migrating
    • Braintrust
    • Langfuse
    • Portkey
LogoLogo
DiscordPlatform
On this page
  • Setup
  • Configuration
  • Attributes
  • Examples
  • Multi-turn chat
  • Async chat
TracingLLM SDKs

Mistral AI (tracing)

Was this page helpful?
Previous

Ollama (tracing)

Next
Built with

The Mistral AI Python SDK is the official client for Mistral models. respan-instrumentation-mistralai activates the Mistral AI OpenInference wrapper and normalizes emitted spans to the Respan tracing pipeline.

Set up Respan
  1. Sign up - Create an account at platform.respan.ai
  2. Create an API key - Generate one on the API keys page
Use Respan Gateway

See Mistral AI gateway setup to route Mistral model calls through the Respan gateway.

Example projects
  • Respan example projects

Setup

1

Install packages

$pip install respan-ai respan-instrumentation-mistralai mistralai python-dotenv
2

Set environment variables

$export RESPAN_API_KEY="YOUR_RESPAN_API_KEY"
$export MISTRAL_API_KEY="YOUR_MISTRAL_API_KEY"

Optional:

$export RESPAN_BASE_URL="https://api.respan.ai/api"
$export MISTRALAI_MODEL="mistral/mistral-small"
3

Initialize and run

1import os
2
3from dotenv import load_dotenv
4from mistralai.client import Mistral
5from respan import Respan, workflow
6from respan_instrumentation_mistralai import MistralAIInstrumentor
7
8load_dotenv()
9
10respan = Respan(
11 api_key=os.environ["RESPAN_API_KEY"],
12 base_url=os.getenv("RESPAN_BASE_URL", "https://api.respan.ai/api"),
13 instrumentations=[MistralAIInstrumentor()],
14)
15
16
17@workflow(name="mistralai_chat_completion")
18def run_chat() -> str:
19 with Mistral(api_key=os.environ["MISTRAL_API_KEY"]) as client:
20 response = client.chat.complete(
21 model=os.getenv("MISTRALAI_MODEL", "mistral/mistral-small"),
22 messages=[
23 {
24 "role": "user",
25 "content": "Reply with one concise sentence about tracing.",
26 }
27 ],
28 )
29 return str(response.choices[0].message.content or "")
30
31
32try:
33 print(run_chat())
34finally:
35 respan.flush()
36 respan.shutdown()
4

View your trace

Open the Traces page and search for the workflow name mistralai_chat_completion.

Configuration

ParameterTypeDefaultDescription
**instrumentor_kwargsdict{}Extra keyword arguments forwarded to the upstream Mistral AI OpenInference instrumentor.

Attributes

Attach customer identifiers, thread IDs, workflow names, and metadata to Mistral AI calls with propagate_attributes.

1from respan import propagate_attributes
2
3with propagate_attributes(
4 customer_identifier="user_123",
5 thread_identifier="conversation_456",
6 trace_group_identifier="mistralai_support_chat.workflow",
7 metadata={"plan": "pro", "workflow_name": "mistralai_support_chat.workflow"},
8):
9 response = client.chat.complete(
10 model="mistral/mistral-small",
11 messages=[{"role": "user", "content": "Summarize our support policy."}],
12 )
AttributeTypeDescription
customer_identifierstrIdentifies the end user in Respan analytics.
thread_identifierstrGroups related messages into a conversation.
trace_group_identifierstrGroups spans by workflow name.
metadatadictCustom key-value pairs merged with default metadata.

Examples

Multi-turn chat

1response = client.chat.complete(
2 model="mistral/mistral-small",
3 messages=[
4 {"role": "user", "content": "Explain tracing in one sentence."},
5 {"role": "assistant", "content": "Tracing records how a request moves through a system."},
6 {"role": "user", "content": "Now make that explanation shorter."},
7 ],
8)
9print(response.choices[0].message.content)

Async chat

1import asyncio
2import os
3
4from mistralai.client import Mistral
5
6
7async def main() -> None:
8 async with Mistral(api_key=os.environ["MISTRAL_API_KEY"]) as client:
9 response = await client.chat.complete_async(
10 model="mistral/mistral-small",
11 messages=[{"role": "user", "content": "Write a short haiku about traces."}],
12 )
13 print(response.choices[0].message.content)
14
15
16asyncio.run(main())