Example
Request

# pip install requests
import requests
api_key = "UPSTAGE_API_KEY"
filename = "YOUR_FILE_NAME"
url = "https://api.upstage.ai/v1/document-digitization"
headers = {"Authorization": f"Bearer {api_key}"}
files = {"document": open(filename, "rb")}
data = {"model": "ocr"}
response = requests.post(url, headers=headers, files=files, data=data)
print(response.json())Response
{
"apiVersion": "1.1",
"confidence": 0.9924988460974842,
"metadata": {
"pages": [
{
"height": 256,
"page": 1,
"width": 786
}
]
},
"mimeType": "multipart/form-data",
"modelVersion": "ocr-260630",
"numBilledPages": 1,
"pages": [
{
"confidence": 0.9924988460974842,
"height": 256,
"id": 0,
"text": "Print the words \nhello, world",
"width": 786,
"words": [
{
"boundingBox": {
"vertices": [
{
"x": 65,
"y": 52
},
{
"x": 221,
"y": 55
},
{
"x": 221,
"y": 104
},
{
"x": 64,
"y": 101
}
]
},
"confidence": 0.9950619419121907,
"id": 0,
"text": "Print"
},
{
"boundingBox": {
"vertices": [
{
"x": 243,
"y": 49
},
{
"x": 341,
"y": 52
},
{
"x": 340,
"y": 105
},
{
"x": 241,
"y": 102
}
]
},
"confidence": 0.9989913157886589,
"id": 1,
"text": "the"
},
{
"boundingBox": {
"vertices": [
{
"x": 368,
"y": 52
},
{
"x": 553,
"y": 51
},
{
"x": 553,
"y": 105
},
{
"x": 368,
"y": 105
}
]
},
"confidence": 0.9890200556796326,
"id": 2,
"text": "words"
},
{
"boundingBox": {
"vertices": [
{
"x": 214,
"y": 131
},
{
"x": 470,
"y": 149
},
{
"x": 467,
"y": 206
},
{
"x": 210,
"y": 188
}
]
},
"confidence": 0.9933670202605895,
"id": 3,
"text": "hello,"
},
{
"boundingBox": {
"vertices": [
{
"x": 527,
"y": 145
},
{
"x": 748,
"y": 143
},
{
"x": 749,
"y": 192
},
{
"x": 527,
"y": 194
}
]
},
"confidence": 0.986053896846349,
"id": 4,
"text": "world"
}
]
}
],
"stored": true,
"text": "Print the words \nhello, world"
}Asynchronous API
Process documents with up to 2,000 pages asynchronously. Submit requests and retrieve results in batches.
Universal extraction
Extract structured fields from any document using your own JSON schema. Covers the request body (model, messages, response_format, chunking), the chat.completion response, and example requests.