API 文档

使用我们强大的REST API将OLM OCR集成到您的应用程序中。支持多种上传方法和灵活的身份验证。

API 密钥身份验证
多种上传方式
REST API
1

获取API密钥

登录您的帐户,然后从设置页面生成 API 密钥。

转到设置
2

选择上传方式

选择 Base64 编码(适用于小文件)或 URL 上传(适用于大文件)。

Base64:< 1MB
URL:> 1MB
3

开始处理

将您的图像或 PDF 发送到我们的 OCR API,并接收结构化文本数据作为响应。

JSON、Markdown和纯文本

OCR 处理

从图像和PDF中提取文本

POST
POST https://www.freeolmocr.com/api/ocr/process

方法1:Base64上传

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

方法 2:URL 上传

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

响应

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

身份验证

在请求中包含您的API密钥

标头选项

选项 1:x-api-key 标头

x-api-key: mk_your_api_key_here

选项 2:Authorization 标头

Authorization: Bearer mk_your_api_key_here

MCP 协议支持

用于 AI 代理和工具的模型上下文协议

MCP

HTTP/JSON-RPC 端点:

POST https://www.freeolmocr.com/api/mcp

SSE 流端点:

GET https://www.freeolmocr.com/api/mcp

协议特性

HTTP 传输

  • 通过 HTTP POST 的 JSON-RPC 2.0
  • 同步请求/响应
  • 为 Web 客户端启用 CORS
  • API 密钥身份验证

SSE 传输

  • 服务器发送事件流
  • 实时双向通信
  • 事件驱动的消息处理
  • 支持持久连接

可用的 MCP 工具

🔍 extract_text

使用 OCR 从文档和图像中提取文本。支持 PDF 文件、JPEG、PNG、WebP 图像。接受 base64 数据和 URL(同步处理)

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

推荐工作流程

小文档/图片(<1MB):
extract_text 使用 base64 数据(PDF、JPEG、PNG、WebP)
大型文档/图像(>1MB):
extract_text 使用 URL
支持的文件类型:
PDF documents, JPEG/JPG images, PNG images, WebP images

客户端集成

Cursor/Claude Desktop

开发

在 Cursor 中使用 MCP 工具,从图像中进行代码分析和文档提取。

MCP 配置: cursor_mcp_config.json

{
  "mcp": {
    "servers": {
      "mistral-ocr": {
        "url": "https://www.freeolmocr.com/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"
    ]
  }
}

在 Cursor 中使用:

使用快捷键: @ocr
支持小文件和大文件的工作流程

自定义 MCP 客户端

高级

使用我们的 HTTP/SSE 端点构建您自己的 MCP 客户端或与其他 AI 工具集成。

通用客户端配置: mcp_config.json

{
  "mcp": {
    "servers": {
      "mistral-ocr": {
        "url": "https://www.freeolmocr.com/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 客户端示例:

// Initialize MCP connection
const response = await fetch('https://www.freeolmocr.com/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 客户端示例:

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

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

身份验证

所有 MCP 请求都需要使用以下方法之一进行 API 密钥身份验证:

  • x-api-key: mk_your_api_key (标头)
  • Authorization: Bearer mk_your_api_key (标头)
  • FETCH_MCP_SERVER_API_KEY=mk_your_api_key (环境变量)

在此处获取您的 API 密钥

测试与调试

测试 HTTP 端点

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

测试 SSE 端点

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

代码示例

即用型代码片段

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.freeolmocr.com/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.freeolmocr.com/api/ocr/process \
  -H "x-api-key: mk_your_api_key" \
  -H "Content-Type: application/json" \
  -d "{\"image\": \"$IMAGE_DATA\"}"

需要帮助?

通过我们的API快速入门或寻求支持。