DocTR

Use the DocTR OCR model through our Serverless Hosted API

DocTR is a document OCR model deployable via our Serverless Hosted API.

Code sample

Call the /doctr/ocr endpoint directly with curl:

curl --location 'https://serverless.roboflow.com/doctr/ocr' \
  --header 'Content-Type: application/json' \
  --data '{
    "api_key": "YOUR_API_KEY",
    "image": {"type": "url", "value": "https://media.roboflow.com/inference/license_plate_1.jpg"}
  }'

The same call through the SDK. Pass your Roboflow API Key via the API_KEY env variable.

pip install inference-sdk
import os
import urllib.request
from inference_sdk import InferenceHTTPClient

# Sample image containing text
urllib.request.urlretrieve(
    "https://media.roboflow.com/inference/license_plate_1.jpg",
    "./sample.jpg",
)

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.getenv("API_KEY"),
)

result = client.ocr_image(inference_input="./sample.jpg", model="doctr")

print(result["result"]) # Extracted text

The code above prints inference results to the terminal:

Set api_url to match your deployment target:

  • https://serverless.roboflow.com for the Serverless Hosted API.

  • http://localhost:9001 for a local Inference server.

  • Your Dedicated Deployment URL for a private endpoint.

Last updated

Was this helpful?