API Documentation

Integrate Mistral OCR into your applications with our powerful REST API. Support for multiple upload methods and flexible authentication.

API Key Authentication
Multiple Upload Methods
REST API
1

Get API Key

Sign in to your account and generate an API key from the settings page.

Go to Settings
2

Choose Upload Method

Select between Base64 encoding (for small files) or URL upload (for large files).

Base64: < 1MB
URL: > 1MB
3

Start Processing

Send your images or PDFs to our OCR API and receive structured text data in response.

JSON, Markdown & Plain Text

OCR Processing

Extract text from images and PDFs

POST
POST https://www.mistralocr.app/api/ocr/process

Method 1: Base64 Upload

{
  "image": "base64_encoded_image_data",
  "options": {
    "format": "text" # json, text, markdown
  }
}

Method 2: URL Upload

{
  "imageUrl": "https://img.mistralocr.app/mistral-ocr/...",
  "options": {
    "format": "text" # json, text, markdown
  }
}

Response

{
  "success": true,
  "userId": "user_123",
  "inputSource": "base64",
  "extractedText": "Extracted text content...",
  "confidence": 0.95,
  "processingTime": 1.2,
  "creditsUsed": 1
}

Authentication

Include your API key in requests

Header Options

Option 1: x-api-key header

x-api-key: mk_your_api_key_here

Option 2: Authorization header

Authorization: Bearer mk_your_api_key_here

MCP Protocol Support

Model Context Protocol for AI agents and tools

MCP

HTTP/JSON-RPC Endpoint:

POST https://www.mistralocr.app/api/mcp

SSE Streaming Endpoint:

GET https://www.mistralocr.app/api/mcp

Protocol Features

HTTP Transport

  • JSON-RPC 2.0 over HTTP POST
  • Synchronous request/response
  • CORS enabled for web clients
  • API key authentication

SSE Transport

  • Server-Sent Events streaming
  • Real-time bidirectional communication
  • Event-driven message handling
  • Persistent connection support

Available MCP Tools

🔍 extract_text

Extract text from documents and images using OCR. Supports PDF files, JPEG, PNG, WebP images. Accepts both base64 data and URLs (synchronous processing)

Parameters:
- image_source (object, required):
- type: 'base64' | 'url'
- data: base64 string or file URL
- filename: document.pdf, image.jpg, etc. (optional)
- output_format (string, optional): 'text'|'json'|'markdown'

Supported formats: PDF, JPEG, PNG, WebP

Recommended Workflows

Small Documents/Images (<1MB):
extract_text with base64 data (PDF, JPEG, PNG, WebP)
Large Documents/Images (>1MB):
extract_text with URL
Supported File Types:
PDF documents, JPEG/JPG images, PNG images, WebP images

Client Integrations

Cursor/Claude Desktop

Development

Use MCP tools in Cursor for code analysis and documentation extraction from images.

MCP Configuration: cursor_mcp_config.json

{
  "mcp": {
    "servers": {
      "mistral-ocr": {
        "url": "https://www.mistralocr.app/api/mcp",
        "transport": "http",
        "headers": {
          "x-api-key": "mk_your_api_key_here",
          "Content-Type": "application/json"
        },
        "capabilities": { "tools": true }
      }
    }
  },
  "shortcuts": {
    "ocr": "@mistral-ocr extract_text"
  },
  "workflows": {
    "large_file_ocr": [
      "extract_text with public_url"
    ],
    "small_file_ocr": [
      "extract_text with base64 data"
    ]
  }
}

Usage in Cursor:

Use shortcuts: @ocr
Workflow support for small and large files

Custom MCP Clients

Advanced

Build your own MCP client or integrate with other AI tools using our HTTP/SSE endpoints.

Generic Client Configuration: mcp_config.json

{
  "mcp": {
    "servers": {
      "mistral-ocr": {
        "url": "https://www.mistralocr.app/api/mcp",
        "transport": "http",
        "authentication": {
          "type": "api_key",
          "header": "x-api-key",
          "key": "mk_your_api_key_here"
        },
        "capabilities": {
          "tools": true,
          "resources": false,
          "prompts": false
        },
        "metadata": {
          "name": "Mistral OCR",
          "description": "OCR service for PDF and image text extraction",
          "version": "2.0.0"
        }
      }
    }
  },
  "client": {
    "timeout": 30000,
    "retries": 3,
    "transport_fallback": ["http", "sse"]
  }
}

HTTP Client Example:

// Initialize MCP connection
const response = await fetch('https://www.mistralocr.app/api/mcp', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x-api-key': 'mk_your_api_key'
  },
  body: JSON.stringify({
    jsonrpc: '2.0',
    id: 1,
    method: 'initialize',
    params: {
      protocolVersion: '2024-11-05',
      capabilities: { tools: {} }
    }
  })
});

SSE Client Example:

// Connect to SSE endpoint
const eventSource = new EventSource(
  'https://www.mistralocr.app/api/mcp?' +
  'api_key=mk_your_api_key'
);

eventSource.onmessage = (event) => {
  const data = JSON.parse(event.data);
  console.log('Received:', data);
};

Authentication

All MCP requests require API key authentication using one of these methods:

  • x-api-key: mk_your_api_key (header)
  • Authorization: Bearer mk_your_api_key (header)
  • FETCH_MCP_SERVER_API_KEY=mk_your_api_key (environment variable)

Get your API key here

Testing & Debugging

Test HTTP Endpoint

curl -X POST https://www.mistralocr.app/api/mcp \
  -H "Content-Type: application/json" \
  -H "x-api-key: mk_your_api_key" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/list"
  }'

Test SSE Endpoint

curl -N -H "Accept: text/event-stream" \
  -H "x-api-key: mk_your_api_key" \
  https://www.mistralocr.app/api/mcp

Code Examples

Ready-to-use code snippets

Python

import requests
import base64

# Base64 method
with open('image.jpg', 'rb') as f:
    image_data = base64.b64encode(f.read()).decode()

response = requests.post(
    'https://www.mistralocr.app/api/ocr/process',
    headers={'x-api-key': 'mk_your_api_key'},
    json={'image': image_data}
)

result = response.json()
print(result['extractedText'])

cURL

# Base64 method
IMAGE_DATA=$(base64 -i image.jpg)
curl -X POST https://www.mistralocr.app/api/ocr/process \
  -H "x-api-key: mk_your_api_key" \
  -H "Content-Type: application/json" \
  -d "{\"image\": \"$IMAGE_DATA\"}"

Need Help?

Get started quickly with our API or reach out for support.