Azure AI OCR

Azure AI OCR (Mistral, Cohere Parse)

Azure AI의 OCR 모델로 PDF와 이미지에서 텍스트를 추출해요. Mistral 기반 모델과 Cohere Parse 배포를 지원해요. LiteLLM의 azure_ai/ 라우트로 통합 /ocr 작업을 제공해요.

출처: 문서

본문

개요 (Overview)

속성 설명
설명 Mistral과 Cohere Parse 기반의 문서 인텔리전스 기능. PDF와 이미지에서 텍스트 추출 제공
LiteLLM 라우트 azure_ai/
지원 작업 /ocr
공급자 문서 Azure AI

빠른 시작 (Quick Start)

LiteLLM SDK:

import litellm
import os

# Set environment variables
os.environ["AZURE_AI_API_KEY"] = ""
os.environ["AZURE_AI_API_BASE"] = ""

# OCR with PDF URL
response = litellm.ocr(
    model="azure_ai/mistral-document-ai-2505",
    document={
        "type": "document_url",
        "document_url": "https://example.com/document.pdf"
    }
)

# Access extracted text
for page in response.pages:
    print(page.markdown)

LiteLLM Proxy (proxy_config.yaml):

model_list:
  - model_name: azure-ocr
    litellm_params:
      model: azure_ai/mistral-document-ai-2505
      api_key: "os.environ/AZURE_AI_API_KEY"
      api_base: "os.environ/AZURE_AI_API_BASE"
      model_info:
        mode: ocr

문서 유형 (Document Types)

Azure AI OCR은 PDF와 이미지를 모두 지원해요.

PDF 문서

response = litellm.ocr(
    model="azure_ai/mistral-document-ai-2505",
    document={
        "type": "document_url",
        "document_url": "https://example.com/document.pdf"
    }
)

이미지 문서

response = litellm.ocr(
    model="azure_ai/mistral-document-ai-2505",
    document={
        "type": "image_url",
        "image_url": "https://example.com/image.png"
    }
)

Base64 인코딩 문서

import base64

# Read and encode PDF
with open("document.pdf", "rb") as f:
    pdf_base64 = base64.b64encode(f.read()).decode()

response = litellm.ocr(
    model="azure_ai/mistral-document-ai-2505",
    document={
        "type": "document_url",
        "document_url": f"data:application/pdf;base64,{pdf_base64}"
    }
)

지원 파라미터 (Supported Parameters)

response = litellm.ocr(
    model="azure_ai/mistral-document-ai-2505",
    document={  # Required: Document to process
        "type": "document_url",
        "document_url": "https://..."
    },
    include_image_base64=True,  # Optional: Include base64 images
    pages=[0, 1, 2],            # Optional: Specific pages to process
    image_limit=10              # Optional: Limit number of images
)

응답 형식 (Response Format)

# Response has the following structure
response.pages          # List of pages with extracted text
response.model          # Model used
response.object         # "ocr"
response.usage_info     # Token usage information

# Access page content
for page in response.pages:
    print(f"Page {page.index}:")
    print(page.markdown)

비동기 지원 (Async Support)

import litellm

response = await litellm.aocr(
    model="azure_ai/mistral-document-ai-2505",
    document={
        "type": "document_url",
        "document_url": "https://example.com/document.pdf"
    }
)

중요 참고 사항 (Important Notes)

  • URL 변환: Azure AI OCR 엔드포인트는 인터넷에 접근할 수 없어요. LiteLLM이 Azure AI로 요청을 보내기 전에 공개 URL을 base64 data URI로 자동 변환해요.

Cohere Parse

Azure AI Foundry는 같은 /ocr 엔드포인트를 통해 Cohere Parse도 서비스해요. azure_ai/<deployment name>을 사용하세요: 이름에 cohereparse를 모두 포함하는 배포(카탈로그 기본 이름 Cohere-parse-v5가 그러함)는 Foundry 리소스의 {api_base}/providers/cohere/v2/parse에 있는 Cohere Parse API로 전송돼요. 다른 이름은 Mistral OCR로 계속 라우팅되므로 이름을 바꾼다면 배포 이름에 cohereparse를 유지하세요.

Parse는 image_url 문서만 받아요 — 이미지 URL 또는 base64 data:image/... URI. PDF와 document_url 입력은 Azure로 아무것도 보내기 전에 400으로 거부돼요. Foundry는 외부 URL을 가져올 수 없으므로 LiteLLM이 원격 이미지를 다운로드해 data URI로 인라인 전송해요 (위 Mistral 모델에 적용하는 것과 동일한 변환).

LiteLLM SDK

import litellm
import os

os.environ["AZURE_AI_API_KEY"] = ""
os.environ["AZURE_AI_API_BASE"] = "https://<resource>.services.ai.azure.com"

response = litellm.ocr(
    model="azure_ai/Cohere-parse-v5",
    document={
        "type": "image_url",
        "image_url": "https://raw.githubusercontent.com/mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png",
    },
    output_format="markdown",
)

for page in response.pages:
    print(page.markdown)
print(response.usage_info.pages_processed)

LiteLLM Proxy

proxy_config.yaml:

model_list:
  - model_name: azure-cohere-parse
    litellm_params:
      model: azure_ai/Cohere-parse-v5
      api_key: "os.environ/AZURE_AI_API_KEY"
      api_base: "os.environ/AZURE_AI_API_BASE"

테스트 요청:

curl http://0.0.0.0:4000/v1/ocr \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "azure-cohere-parse",
    "document": {
      "type": "image_url",
      "image_url": "https://raw.githubusercontent.com/mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png"
    }
  }'

output_format은 markdown(기본) 또는 blocks를 받고, req_format: native는 LiteLLM OCR 형식 대신 Cohere 자체 응답 본문을 반환해요. 비용 추적은 usage_info.pages_processed를 모델 비용 맵의 페이지당 가격으로 계산해요.

모델 비용 맵은 azure_ai/Cohere-parse-v5를 Cohere의 공개 요율인 1,000페이지당 $1.50으로 책정해요. 이는 Foundry 카탈로그가 이 모델에 링크하는 가격이에요.

헬스 체크(/health와 Admin UI의 Test Connection 버튼)는 Mistral OCR에 사용하는 PDF 대신 Parse에 작은 PNG를 보내요. 각 프로브는 실제 1페이지 Parse 호출이므로 배포당 체크당 한 페이지가 청구돼요. ocr 프로브 모드와 페이지당 가격은 모두 모델 비용 맵에서 Cohere-parse-v5로 조회돼요. 다른 이름의 배포는 model_list 항목에 model_info: {mode: ocr, base_model: azure_ai/Cohere-parse-v5}가 필요해요 — 다른 모든 Azure 모델이 쓰는 것과 동일한 mode/base_model 규칙이라서, 헬스 체크가 OCR로 프로브하고 지출 추적이 $0을 기록하는 대신 Parse 가격을 찾게 돼요.

더 알아보기 (Learn more)