> ## Documentation Index
> Fetch the complete documentation index at: https://docs.portkey.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Mistral AI

> Integrate Mistral AI models with Prisma AIRS AI Gateway

The AI Gateway provides a robust and secure gateway to integrate various Large Language Models (LLMs) into applications, including [Mistral AI's models](https://docs.mistral.ai/api/).

With the AI Gateway, take advantage of features like fast AI gateway access, observability, prompt management, and more, while securely managing API keys through [Model Catalog](/docs/aigw/product/model-catalog).

## Quick Start

Get Mistral AI working in 3 steps:

<CodeGroup>
  ```sh cURL icon="square-terminal" theme={"system"}
  # 1. Add @mistral-ai provider in model catalog
  # 2. Use it:

  curl https://aigw.portkey.ai/v1/chat/completions \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer $PORTKEY_API_KEY" \
    -d '{
      "model": "@mistral-ai/mistral-large-latest",
      "messages": [
        { "role": "user", "content": "Say this is a test" }
      ]
    }'
  ```

  ```python OpenAI Py icon="python" theme={"system"}
  from openai import OpenAI

  # 1. Install: pip install openai
  # 2. Add @mistral-ai provider in model catalog
  # 3. Use it:

  client = OpenAI(
      api_key="PORTKEY_API_KEY",  # AI Gateway API key
      base_url="https://aigw.portkey.ai/v1"
  )

  response = client.chat.completions.create(
      model="@mistral-ai/mistral-large-latest",
      messages=[{"role": "user", "content": "Say this is a test"}]
  )

  print(response.choices[0].message.content)
  ```

  ```js OpenAI JS icon="square-js" theme={"system"}
  import OpenAI from "openai"

  // 1. Install: npm install openai
  // 2. Add @mistral-ai provider in model catalog
  // 3. Use it:

  const client = new OpenAI({
      apiKey: "PORTKEY_API_KEY",  // AI Gateway API key
      baseURL: "https://aigw.portkey.ai/v1"
  })

  const response = await client.chat.completions.create({
      model: "@mistral-ai/mistral-large-latest",
      messages: [{ role: "user", content: "Say this is a test" }]
  })

  console.log(response.choices[0].message.content)
  ```
</CodeGroup>

<Note>
  **Tip:** You can also send `x-portkey-provider: @mistral-ai` as a header and use just `model="mistral-large-latest"` in the request.
</Note>

## Add Provider in Model Catalog

1. Go to [**Model Catalog → Add Provider**](https://stratacloudmanager.paloaltonetworks.com/)
2. Select **Mistral AI**
3. Choose existing credentials or create new by entering your [Mistral AI API key](https://console.mistral.ai/api-keys/)
4. Name your provider (e.g., `mistral-ai-prod`)

<Card title="Complete Setup Guide →" href="/docs/aigw/product/model-catalog">
  See all setup options, code examples, and detailed instructions
</Card>

## Codestral Endpoint

Mistral AI provides a dedicated Codestral endpoint for code generation. Use the `customHost` property to access it:

Your Codestral requests will show up on AI Gateway logs with code snippets rendered beautifully:

## Structured Output (response\_format)

Mistral AI supports structured output via the `response_format` parameter. You can enforce JSON schema validation for deterministic, structured responses:

## Mistral Tool Calling

Tool calling lets models trigger external tools based on conversation context. You define available functions, the model chooses when to use them, and your application executes them and returns results.

The AI Gateway supports Mistral tool calling and makes it interoperable across multiple providers. With AI Gateway Prompts, you can templatize your prompts and tool schemas.

<CodeGroup>
  ```sh cURL theme={"system"}
  curl -X POST "https://aigw.portkey.ai/v1/chat/completions" \
       -H "Content-Type: application/json" \
       -H "Authorization: Bearer $PORTKEY_API_KEY" \
       -d '{
         "model": "@mistral-ai/mistral-large-latest",
         "messages": [
           {"role": "system", "content": "You are a helpful assistant."},
           {"role": "user", "content": "What'\''s the weather like in Delhi?"}
         ],
         "tools": [{
           "type": "function",
           "function": {
             "name": "getWeather",
             "description": "Get the current weather",
             "parameters": {
               "type": "object",
               "properties": {
                 "location": {"type": "string", "description": "City and state"},
                 "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
               },
               "required": ["location"]
             }
           }
         }],
         "tool_choice": "auto"
       }'
  ```
</CodeGroup>

## OCR (Document Processing)

Mistral AI's OCR models extract text and structured content from PDFs and images. Use the `/v1/ocr` endpoint:

<CodeGroup>
  ```sh cURL theme={"system"}
  curl -X POST "https://aigw.portkey.ai/v1/ocr" \
       -H "Content-Type: application/json" \
       -H "Authorization: Bearer $PORTKEY_API_KEY" \
       -d '{
         "model": "@mistral-ai/mistral-ocr-latest",
         "document": {
           "type": "document_url",
           "document_url": "https://example.com/document.pdf"
         },
         "include_image_base64": true
       }'
  ```
</CodeGroup>

**Supported Models:** `mistral-ocr-latest`, `mistral-ocr-4-0`

<Info>
  The native `/v1/ocr` endpoint requires gateway version **2.18.0** or higher for hybrid (self-hosted) deployments.
</Info>

***

## Managing Mistral AI Prompts

Manage all prompt templates to Mistral AI in the Prompt Library. All current Mistral AI models are supported, and you can easily test different prompts.

Call the `POST /v1/prompts/{promptId}/completions` endpoint to use the prompt in an application.

## Next Steps

<CardGroup cols={2}>
  <Card title="Add Metadata" icon="tags" href="/docs/aigw/product/observability/metadata">
    Add metadata to your Mistral AI requests
  </Card>

  <Card title="Gateway Configs" icon="gear" href="/docs/aigw/product/ai-gateway/configs">
    Add gateway configs to your Mistral AI requests
  </Card>

  <Card title="Tracing" icon="chart-line" href="/docs/aigw/product/observability/traces">
    Trace your Mistral AI requests
  </Card>

  <Card title="Fallbacks" icon="arrow-rotate-left" href="/docs/aigw/product/ai-gateway/fallbacks">
    Setup fallback from OpenAI to Mistral AI
  </Card>
</CardGroup>


## Related topics

- [Mistral](/docs/aigw/integrations/guardrails/mistral.md)
- [Pydantic AI](/docs/aigw/integrations/agents/pydantic-ai.md)
- [Strands Agents](/docs/aigw/integrations/agents/strands.md)
- [Mastra Agents](/docs/aigw/integrations/agents/mastra-agents.md)
- [OpenAI Agents SDK (Python)](/docs/aigw/integrations/agents/openai-agents.md)
