Get OCR Job Result
Retrieve OCR processing results for a completed job with extracted text and structured data
Get OCR Job Result
Retrieve OCR processing results for a completed job with extracted text and structured data. Returns job status if processing is still in progress. Supports pagination for large documents.
Endpoint
GET /ocr/result/{job_id}Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
job_id | string | Yes | OCR job ID |
page | integer | No | Page number for result pagination (default: 1) |
limit | integer | No | Number of items per page (default: 100, max: 1000) |
SDK Examples
# Get job result
curl -X GET https://api.leapocr.com/api/v1/ocr/result/job_abc123 \
-H "X-API-Key: your-api-key"
# Response: (see Response section below for full example)
# {
# "job_id": "job_abc123",
# "status": "completed",
# "credits_used": 3,
# "file_name": "invoice.pdf",
# "model": "standard-v1",
# "result_format": "structured",
# "total_pages": 1,
# "processed_pages": 1,
# "pages": [...]
# }import { LeapOCR } from "leapocr";
const client = new LeapOCR({
apiKey: process.env.LEAPOCR_API_KEY,
});
// Wait for job to complete
const status = await client.ocr.waitUntilDone(jobId);
if (status.status === "completed") {
// Get the results
const result = await client.ocr.getJobResult(jobId);
console.log(`Credits used: ${result.credits_used}`);
console.log(`Total pages: ${result.total_pages}`);
console.log(`Processing time: ${result.processing_time_seconds}s`);
// Access extracted data
result.pages.forEach((page) => {
console.log(`Page ${page.page_number}:`, page.result);
});
}import asyncio
import os
from leapocr import LeapOCR
async def main():
async with LeapOCR(os.getenv("LEAPOCR_API_KEY")) as client:
# Wait for job to complete
status = await client.ocr.wait_until_done(job_id)
if status.status.value == "completed":
# Get the results
result = await client.ocr.get_results(job_id)
print(f"Credits used: {result.credits_used}")
print(f"Total pages: {result.total_pages}")
print(f"Model: {result.model}")
# Access extracted data
for page in result.pages:
if isinstance(page.result, dict):
print(f"Page {page.page_number} (structured):", page.result)
else:
print(f"Page {page.page_number} (markdown):", page.result[:100])
asyncio.run(main())package main
import (
"context"
"fmt"
"log"
"os"
"github.com/leapocr/leapocr-go"
)
func main() {
client, err := ocr.New(os.Getenv("LEAPOCR_API_KEY"))
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
// Wait for job to complete
result, err := client.WaitUntilDone(ctx, jobID)
if err != nil {
log.Fatal(err)
}
// Get the full results
fullResult, err := client.GetJobResult(ctx, jobID)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Credits used: %d\n", fullResult.Credits)
fmt.Printf("Total pages: %d\n", fullResult.TotalPages)
fmt.Printf("Processing time: %.2fs\n", fullResult.Duration)
// Access extracted data
fmt.Printf("Extracted data: %+v\n", fullResult.Data)
}Response
Structured Format
{
"job_id": "job_abc123",
"status": "completed",
"credits_used": 3,
"file_name": "invoice.pdf",
"model": "standard-v1",
"result_format": "structured",
"total_pages": 1,
"processed_pages": 1,
"completed_at": "2024-01-15T10:30:00Z",
"pages": [
{
"id": "page_xyz789",
"page_number": 1,
"result": {
"invoice_number": "INV-2024-001",
"date": "2024-01-15",
"total": 1234.56
}
}
],
"pagination": {
"page": 1,
"limit": 100,
"total": 1,
"total_pages": 1
}
}Markdown Format
{
"job_id": "job_abc123",
"status": "completed",
"credits_used": 2,
"file_name": "document.pdf",
"model": "standard-v1",
"result_format": "markdown",
"total_pages": 2,
"processed_pages": 2,
"completed_at": "2024-01-15T10:30:00Z",
"pages": [
{
"id": "page_xyz789",
"page_number": 1,
"result": "# Invoice\n\nInvoice Number: INV-2024-001\nDate: January 15, 2024\nTotal: $1,234.56"
},
{
"id": "page_xyz790",
"page_number": 2,
"result": "# Line Items\n\n- Item 1: $500.00\n- Item 2: $734.56"
}
]
}Result Type: The result field type depends on the output format: - For
structured or per_page_structured: result is a JSON object - For
markdown: result is a string containing the extracted text
Error Responses
| Status Code | Description |
|---|---|
200 | OCR processing completed, results available |
202 | OCR processing in progress, status returned |
400 | Bad request - invalid job ID or parameters |
401 | Unauthorized - authentication required |
403 | Forbidden - job belongs to different user |
404 | Not found - job does not exist |
500 | Internal server error |
Pagination
For documents with many pages, use pagination to retrieve results in chunks:
# Get first 50 pages
curl -X GET "https://api.leapocr.com/api/v1/ocr/result/job_abc123?page=1&limit=50" \
-H "X-API-Key: your-api-key"
# Get next page
curl -X GET "https://api.leapocr.com/api/v1/ocr/result/job_abc123?page=2&limit=50" \
-H "X-API-Key: your-api-key"// Get first 50 pages
const result = await client.ocr.getJobResult(jobId, {
page: 1,
pageSize: 50,
});
console.log(`Total pages: ${result.pagination.total}`);
console.log(`Current page: ${result.pagination.page}`);
// Get next page
if (result.pagination.page < result.pagination.total_pages) {
const nextPage = await client.ocr.getJobResult(jobId, {
page: 2,
pageSize: 50,
});
}# Get first 50 pages
result = await client.ocr.get_results(job_id, page=1, limit=50)
print(f"Total pages: {result.pagination.total}")
print(f"Current page: {result.pagination.page}")
# Get next page
if result.pagination.page < result.pagination.total_pages:
next_page = await client.ocr.get_results(job_id, page=2, limit=50)// Get first 50 pages
result, err := client.GetJobResult(ctx, jobID, ocr.WithPage(1), ocr.WithLimit(50))
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total pages: %d\n", result.Pagination.Total)
fmt.Printf("Current page: %d\n", result.Pagination.Page)
// Get next page
if result.Pagination.Page < result.Pagination.TotalPages {
nextPage, _ := client.GetJobResult(ctx, jobID, ocr.WithPage(2), ocr.WithLimit(50))
}Next Steps
- Delete Job - Remove sensitive data after processing
- Get Job Status - Check processing progress