Set up comprehensive observability for Mistral AI integrations with metrics, traces, and alerts. Use when implementing monitoring for Mistral AI operations, setting up dashboards, or configuring alerting for Mistral AI integration health. Trigger with phrases like "mistral monitoring", "mistral metrics", "mistral observability", "monitor mistral", "mistral alerts", "mistral tracing".
Monitor Mistral AI API usage, latency, token consumption, and costs across models.
import Mistral from '@mistralai/mistralai';
const PRICING: Record<string, { input: number; output: number }> = {
'mistral-small-latest': { input: 0.20, output: 0.60 },
'mistral-large-latest': { input: 2.00, output: 6.00 },
'mistral-embed': { input: 0.10, output: 0.00 },
};
async function trackedChat(client: Mistral, model: string, messages: any[]) {
const start = performance.now();
try {
const res = await client.chat.complete({ model, messages });
const duration = performance.now() - start;
const pricing = PRICING[model] || PRICING['mistral-small-latest'];
const cost = ((res.usage?.promptTokens || 0) / 1e6) * pricing.input
+ ((res.usage?.completionTokens || 0) / 1e6) * pricing.output;
emitMetrics({ model, duration, inputTokens: res.usage?.promptTokens, outputTokens: res.usage?.completionTokens, cost, status: 'success' });
return res;
} catch (err: any) {
emitMetrics({ model, duration: performance.now() - start, status: 'error', errorCode: err.status });
throw err;
}
}
# Key metrics to expose on /metrics endpoint
mistral_requests_total: { type: counter, labels: [model, status, endpoint] }
mistral_request_duration_ms: { type: histogram, labels: [model], buckets: [100, 250, 500, 1000, 2500, 5000] } # 5000: 2500: 1000: 250: HTTP 500 Internal Server Error
mistral_tokens_total: { type: counter, labels: [model, direction] } # direction: input|output
mistral_cost_usd_total: { type: counter, labels: [model] }
mistral_errors_total: { type: counter, labels: [model, status_code] }
# prometheus/mistral-alerts.yaml