File size: 840 Bytes
0c0a4f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3
import os, json
from mistralai import Mistral
from dotenv import load_dotenv

# ── Load your .env so the API key is available ──
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
load_dotenv(os.path.join(PROJECT_ROOT, ".env"))

# ── Init the client ──
api_key = os.getenv("MISTRAL_OCR_KEY")
if not api_key:
    raise RuntimeError("MISTRAL_OCR_KEY not set in .env")
client = Mistral(api_key=api_key)

# ── Call the public example PNG β†’ receipt.png ──
example_url = (
    "https://raw.githubusercontent.com/"
    "mistralai/cookbook/refs/heads/main/mistral/ocr/receipt.png"
)
resp = client.ocr.process(
    model="mistral-ocr-latest",
    document={"type": "image_url", "image_url": example_url},
)
print("➀ Raw response JSON:")
print(json.dumps(resp, indent=2))