Skip to content
OpenSmartRoute
Skillv1.0.0

mistral-common-errors

Diagnose and fix Mistral AI common errors and exceptions. Use when encountering Mistral errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like "mistral err

by jeremylongshore(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from jeremylongshore/tons-of-skills-marketplace (skills/.curated/mistral-common-errors/SKILL.md). Install upstream with npx skills add jeremylongshore/tons-of-skills-marketplace --skill mistral-common-errors. Copyright stays with the author (MIT).

Mistral AI Common Errors

Overview

Quick reference for diagnosing and fixing Mistral AI API errors. Covers HTTP status codes, SDK-specific issues, streaming failures, and tool calling problems with real solutions.

Prerequisites

  • Mistral AI SDK installed
  • MISTRAL_API_KEY configured
  • Read-only access to application logs and configuration
  • curl and jq available for the diagnostic probe
  • Access to the secret manager if a credential must be rotated

Instructions

Step 1: Quick Diagnostic

Use Read for the relevant configuration and log files, then Grep for the exact HTTP status, request ID, model name, and error code. Never print, paste, or store the API key while collecting evidence.

set -euo pipefail
# Check presence without revealing key material or key metadata
test -n "${MISTRAL_API_KEY:-}" || {
  echo "MISTRAL_API_KEY is not set" >&2
  exit 1
}

# Keep the JSON body separate from curl's status metadata. Command substitution
# removes trailing newlines, so the final newline inserted by -w is a stable
# delimiter even when the response body itself spans multiple lines.
response="$(curl -sS -w $'\n%{http_code}' \
  -H "Authorization: Bearer ${MISTRAL_API_KEY}" \
  https://api.mistral.ai/v1/models)"
http_status="${response##*$'\n'}"
body="${response%$'\n'*}"

case "$http_status" in
  200)
    printf '%s\n' "$body" | jq -er '
      [.data[]?.id | select(type == "string" and length > 0)]
      | if length > 0 then .[] else error("models response contains no model ids") end
    '
    ;;
  401)
    echo "Mistral authentication failed (HTTP 401); rotate or correct the configured key." >&2
    exit 1
    ;;
  429)
    echo "Mistral rate limit reached (HTTP 429); inspect limits and retry policy." >&2
    exit 1
    ;;
  *)
    echo "Mistral connectivity probe failed (HTTP ${http_status:-unknown})." >&2
    exit 1
    ;;
esac

Step 2: Error Reference


401 Unauthorized

Error: Authentication failed. Invalid API key.

Causes: Key missing, expired, revoked, or wrong workspace.

Fix:

const apiKey = process.env.MISTRAL_API_KEY;
if (!apiKey) throw new Error('MISTRAL_API_KEY is not set');

// Test the key
const client = new Mistral({ apiKey });
try {
  await client.models.list();
} catch (e: any) {
  if (e.status === 401) {
    console.error('API key invalid — regenerate at console.mistral.ai');
  }
}

Verify manually:

set -euo pipefail
curl -H "Authorization: Bearer ${MISTRAL_API_KEY}" https://api.mistral.ai/v1/models

429 Too Many Requests

Error: Rate limit exceeded. Retry-After: 60

Causes: Exceeded RPM (requests/min) or TPM (tokens/min) for your tier.

Fix:

async function withBackoff<T>(fn: () => Promise<T>, maxRetries = 5): Promise<T> {
  for (let i = 0; i <= maxRetries; i++) {
    try {
      return await fn();
    } catch (error: any) {
      if (error.status !== 429 || i === maxRetries) throw error;
      const wait = Math.min(2 ** i * 1000, 60_000);
      console.warn(`Rate limited, retrying in ${wait}ms...`);
      await new Promise(r => setTimeout(r, wait));
    }
  }
  throw new Error('Max retries exceeded');
}

Check your limits: Visit console.mistral.ai/limits for workspace RPM/TPM caps.


400 Bad Request — Invalid Model

{"message": "Unknown model: mistral-ultra"}

Fix: Use valid model IDs:

const VALID_MODELS = [
  'mistral-large-latest',
  'mistral-small-latest',
  'codestral-latest',
  'pixtral-large-latest',
  'mistral-embed',
  'mistral-moderation-latest',
] as const;

List available models dynamically:

set -euo pipefail
curl -H "Authorization: Bearer ${MISTRAL_API_KEY}" \
  https://api.mistral.ai/v1/models | jq -r '.data[].id' | sort

400 Bad Request — Invalid Messages

{"message": "messages must be a non-empty array"}

Fix: Validate message structure before sending:

function validateMessages(messages: any[]): void {
  if (!messages?.length) throw new Error('Messages array empty');
  const validRoles = ['system', 'user', 'assistant', 'tool'];
  for (const msg of messages) {
    if (!validRoles.includes(msg.role)) {
      throw new Error(`Invalid role: "${msg.role}"`);
    }
    if (!msg.content && !msg.toolCalls) {
      throw new Error(`Message with role "${msg.role}" has no content`);
    }
  }
}

400 Bad Request — Tool Call Errors

{"message": "tool_call_id is required for tool messages"}

Fix: Every tool result must include the matching toolCallId:

// After receiving tool_calls from the model
for (const call of response.choices[0].message.toolCalls) {
  const result = await executeFunction(call.function.name, call.function.arguments);
  messages.push({
    role: 'tool',
    name: call.function.name,
    content: JSON.stringify(result),
    toolCallId: call.id,  // REQUIRED — must match call.id
  });
}

400 Bad Request — Context Window Exceeded

Error: Maximum context length exceeded

Fix: Determine the selected model's current context window from its model card, count both input and requested output tokens, and trim conversation history while preserving the system message:

function trimToFit(
  messages: any[],
  countTokens: (candidate: any[]) => number,
  maxContextTokens: number,
  reservedOutputTokens: number,
): any[] {
  const system = messages.find(m => m.role === 'system');
  const rest = messages.filter(m => m.role !== 'system');
  const kept: any[] = system ? [system] : [];
  const inputBudget = maxContextTokens - reservedOutputTokens;

  // Keep the newest complete messages that fit the tokenizer-backed budget.
  for (let i = rest.length - 1; i >= 0; i--) {
    const insertAt = system ? 1 : 0;
    const candidate = [...kept];
    candidate.splice(insertAt, 0, rest[i]);
    if (countTokens(candidate) > inputBudget) break;
    kept.splice(insertAt, 0, rest[i]);
  }
  return kept;
}

500/502/503/504 Server Error

Error: Internal server error

Causes: A transient Mistral service or gateway issue.

Fix:

class CircuitBreaker {
  private failures = 0;
  private lastFailure = 0;
  private readonly threshold = 5;
  private readonly resetMs = 60_000;

  async call<T>(fn: () => Promise<T>): Promise<T> {
    if (this.failures >= this.threshold) {
      if (Date.now() - this.lastFailure < this.resetMs) {
        throw new Error('Circuit breaker open — Mistral service unavailable');
      }
      this.failures = 0; // Reset after timeout
    }
    try {
      const result = await fn();
      this.failures = 0;
      return result;
    } catch (error: any) {
      if ([500, 502, 503, 504].includes(error.status)) {
        this.failures++;
        this.lastFailure = Date.now();
      }
      throw error;
    }
  }
}

ERR_REQUIRE_ESM (Node.js)

Error [ERR_REQUIRE_ESM]: require() of ES Module not supported

Cause: @mistralai/mistralai is ESM-only since v1.x.

Fix: Either use import syntax (recommended) or dynamic import:

// Option 1: Convert to ESM
// package.json: "type": "module"
import { Mistral } from '@mistralai/mistralai';

// Option 2: Dynamic import in CJS
const { Mistral } = await import('@mistralai/mistralai');

Network Timeout

Error: Request timeout after 30000ms

Fix:

const client = new Mistral({
  apiKey: process.env.MISTRAL_API_KEY,
  timeoutMs: 60_000, // Increase for long completions
});

// For streaming, the timeout applies to initial connection
// Individual chunks have no timeout

Escalation Path

  1. Collect evidence with mistral-debug-bundle
  2. Check status.mistral.ai
  3. Contact support via Discord or console.mistral.ai

Error Handling

Error Cause Solution
401 Auth failure Regenerate key at console.mistral.ai
429 Rate limit Backoff + check tier limits
400 Bad params Validate model, messages, tools
400 context-window error Input plus requested output exceeds the model limit Count tokens and trim conversation history
5xx Service error Retry with circuit breaker
ERR_REQUIRE_ESM CJS import Use ESM import syntax

For the evidence to collect and the safe decision boundary for each class, read the error triage playbook.

Output

Return a redacted diagnostic report with these fields:

Mistral incident: <short symptom>
Observed at: <UTC timestamp>
Scope: <endpoint, model, environment, affected request percentage>
Evidence: <HTTP status, error type/code, request ID; never credentials>
Classification: <caller defect | auth | authorization | capacity | transient provider | network>
Action taken: <one reversible mitigation>
Verification: <probe or application check and result>
Next action: <owner and trigger, or "none — resolved">

Do not claim resolution from one successful retry. Require the application's normal health signal to recover and a short observation window with no repeat of the same error class.

Examples

Authentication failure

Input evidence: production requests return 401 authentication_error; the same key fails a redacted /v1/models probe. Classify this as authentication, rotate the credential through the secret manager, restart only the consumers that need the new version, and verify with both the probe and application telemetry. The report records the secret version identifier, never the key value or prefix.

Rate-limit saturation

Input evidence: a burst produces 429 rate_limit_error while ordinary traffic is healthy. Preserve the response request ID and rate-limit headers, reduce concurrency, honor server retry guidance, and use exponential backoff with jitter. Escalate for a limit increase only after comparing observed requests and tokens against the current organization limits.

Resources

Next Steps

For comprehensive debugging, see mistral-debug-bundle. For an active outage with user impact, switch to mistral-incident-runbook after preserving the redacted request evidence.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/jeremylongshore-tons-of-skills-marketplace-mistral-commo-edf77d/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

jeremylongshore-tons-of-skills-marketplace-mistral-commo-edf77d.ocm.jsonjson
{
  "ocm": "1",
  "id": "jeremylongshore-tons-of-skills-marketplace-mistral-commo-edf77d",
  "kind": "skill",
  "name": "mistral-common-errors",
  "description": "Diagnose and fix Mistral AI common errors and exceptions. Use when encountering Mistral errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like \"mistral error\", \"fix mistral\", \"mistral not working\", \"debug mistral\".",
  "publisher": "jeremylongshore",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "coding",
      "customer_support"
    ],
    "tags": [
      "skill-md",
      "saas",
      "mistral",
      "debugging",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Diagnose and fix Mistral AI common errors and exceptions. Use when encountering Mistral errors, debugging failed requests, or troubleshooting integration issues. Trigger with phrases like \"mistral error\", \"fix mistral\", \"mistral not working\", \"debug mistral\"."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/jeremylongshore/tons-of-skills-marketplace",
      "path": "skills/.curated/mistral-common-errors/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/jeremylongshore/tons-of-skills-marketplace/blob/HEAD/skills/.curated/mistral-common-errors/SKILL.md",
      "key": "jeremylongshore/tons-of-skills-marketplace/skills/.curated/mistral-common-errors/SKILL.md"
    },
    "compatibility": "Designed for Claude Code",
    "allowed_tools": [
      "Read,",
      "Grep,",
      "Bash(curl:*)"
    ],
    "license": "MIT"
  },
  "instructions": "# Mistral AI Common Errors\n\n## Overview\n\nQuick reference for diagnosing and fixing Mistral AI API errors. Covers HTTP status codes, SDK-specific issues, streaming failures, and tool calling problems with real solutions.\n\n## Prerequisites\n\n- Mistral AI SDK installed\n- `MISTRAL_API_KEY` configured\n- Read-only access to application logs and configuration\n- `curl` and `jq` available for the diagnostic probe\n- Access to the secret manager if a credential must be rotated\n\n## Instructions\n\n### Step 1: Quick Diagnostic\n\nUse `Read` for the relevant configuration and log files, then `Grep` for the exact",
  "cost": {
    "context_tokens": 2674
  }
}

Fetch it by URL: GET /api/v1/registry/jeremylongshore-tons-of-skills-marketplace-mistral-commo-edf77d/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.