Skip to main content
Working with Azure AI Document Intelligence — practical guidance for calling the API, handling results, and using prebuilt models in the portal. This article shows the common request pattern (REST and SDK), how to poll and retrieve results, what the structured response contains, and how to test prebuilt models in Document Intelligence Studio. How the API call pattern works
  1. Set up the request — define your resource endpoint and include the API key to authenticate.
  2. Send the request — the service accepts the request and returns a poller/tracker. For REST this is the Operation-Location response header; SDKs handle polling internally.
  3. Retrieve results — poll the Operation-Location URL until the operation completes (REST) or call the SDK’s wait/complete mechanism to get the final results.
When using the REST API you must explicitly poll the Operation-Location URL to receive results. SDKs abstract the polling and return a language-native result object when processing completes.
A dark-themed slide titled "Calling the API" showing a three-step horizontal flow. Steps: set up the request with resource endpoint and key, send the request and receive a poller to track results, then query the poller to retrieve extracted data.
REST call pattern example Below is a minimal REST POST to the prebuilt layout analyze endpoint. Note the Operation-Location header returned after submission — you poll that URL to check the status and fetch results.
POST {endpoint}/documentintelligence/documentModels/prebuilt-layout:analyze?api-version={version}
Ocp-Apim-Subscription-Key: {key}
Content-Type: application/json

{
  "urlSource": "{document_url}"
}
Example Operation-Location response header:
Operation-Location:
{endpoint}/documentintelligence/documentModels/prebuilt-layout/analyzeResults/ab12345c-12ab-23cd-b19c-2322a7f11034?api-version={version}
The api-version parameter in the request and operation URL selects which API behavior/version you want to use when Microsoft introduces changes. SDK usage (C# and Python)
  • C# (Azure SDK): call AnalyzeDocumentFromUriAsync, wait for completion, then read Operation.Value for the AnalyzeResult.
AnalyzeDocumentOperation operation = await client.AnalyzeDocumentFromUriAsync(
    WaitUntil.Completed,
    "prebuilt-layout",
    fileUri
);

AnalyzeResult result = operation.Value;
// result contains extracted contents such as text, tables, and layout information
  • Python (Azure SDK): start the analysis with a begin_* method and call poller.result() to obtain the structured result object.
poller = document_analysis_client.begin_analyze_document_from_url(
    "prebuilt-document",
    doc_url
)

result = poller.result()
# 'result' now contains structured output: pages, lines, words, tables, fields, etc.
Response structure and metadata The service returns a structured hierarchy that makes it easy to navigate OCR output: Pages → Lines → Words This structure lets you extract entire paragraphs, iterate line-by-line, or work with word-level details (content, bounding boxes, confidence, etc.).
A slide titled "API Response" showing a three-circle Venn diagram that labels data as structured into Pages, Lines, and Words with "AWD" at the center. The design has a dark blue background and a small "© Copyright KodeKloud" note.
A simplified REST JSON snippet (analyzeResult) showing modelId, pages, and word-level data:
{
  "analyzeResult": {
    "apiVersion": "{version}",
    "modelId": "prebuilt-invoice",
    "pages": [
      {
        "pageNumber": 1,
        "angle": 0,
        "width": 8.5,
        "height": 11,
        "unit": "inch",
        "words": [
          {
            "content": "Margie's",
            "boundingBox": [
              0.5911,
              0.6857,
              1.7451,
              0.6857,
              1.7451,
              0 ...
            ],
            "confidence": 1.0,
            "span": { "offset": 0, "length": 7 }
          }
        ]
      }
    ]
  }
}
The response contains rich metadata — bounding box coordinates, confidence scores, detected text style (including handwriting) — which you can use to validate fields, overlay extracted text on images, or apply post-processing rules.
A dark presentation slide titled "API Response" that shows three rounded panels describing additional metadata from an OCR-like API. The panels list: Bounding box coordinates / Detected text, Confidence scores / Accuracy assessment, and Text style details / Handwritten detection.
Deploying Document Intelligence in Azure and trying prebuilt models You can create either an AI multi-service (Cognitive Services) resource or a dedicated Document Intelligence resource in the Azure portal. After provisioning, open Document Intelligence Studio to test prebuilt models: invoices, receipts, IDs, health insurance cards, bank statements, and more.
A screenshot of the Azure AI Document Intelligence Studio web interface showing OCR and document-processing options and a grid of prebuilt model cards (Invoices, Receipts, Identity documents, US health insurance cards, etc.). Each card has an icon and a "Try it out" link for extracting data from those document types.
To use a prebuilt model in the Studio, configure the API endpoint and a key for your service and then run sample documents through the UI.
A screenshot of the Azure Document Intelligence Studio welcome dialog, prompting the user to configure a service resource by entering a Document Intelligence/Cognitive Services endpoint and an API key.
Try sample identity documents (passport, driver’s license, green card, etc.) and inspect extracted fields such as name, date of birth, document number, and expiration.
A screenshot of Azure AI Document Intelligence Studio displaying a scanned U.S. Permanent Resident (green card) image in the center with extracted identity fields (name, date of birth, document number, etc.) shown in a panel on the right. Thumbnails of other sample ID images appear in a left sidebar.
Python SDK example — analyze an identity document from a URL This consolidated Python example uses the Document Intelligence SDK to analyze an identity document at a given URL and iterate over extracted fields.
from azure.core.credentials import AzureKeyCredential
from azure.ai.documentintelligence import DocumentIntelligenceClient

DOCUMENT_URL = "https://azai102imagestore.blob.core.windows.net/us-id-cards/id1.jpeg"
DOC_INTEL_ENDPOINT = "https://aiservicesai900.cognitiveservices.azure.com/"
DOC_INTEL_KEY = "2nDOsJoeWNZsci1GmRVpC88rpvMsF3wF5KjGqcrSUqmjAXIN6zrLJQQJ99AKACYeBjFXJ3w3AAAAACOGR0oi"

client = DocumentIntelligenceClient(
    endpoint=DOC_INTEL_ENDPOINT,
    credential=AzureKeyCredential(DOC_INTEL_KEY)
)

poller = client.begin_analyze_document(
    model_id="prebuilt-idDocument",
    body={"urlSource": DOCUMENT_URL}
)

result = poller.result()

for i, doc in enumerate(result.documents, start=1):
    print(f"\n— Document #{i} (type: {doc.doc_type}) -----------------------------")
    for name, field in doc.fields.items():
        value = field.content if field.content is not None else "<no value>"
        print(f"{name:20s}: {str(value):30s} (confidence: {field.confidence:.2f})")
Sample trimmed output for id1.jpeg:
— Document #1 (type: idDocument.residencePermit) -----------------------------
Category             : IRL                            (confidence: 0.55)
CountryRegion        : <no value>                     (confidence: 0.99)
DateOfBirth          : 09 SEP 1988                    (confidence: 0.71)
DateOfExpiration     : 11/12/30                       (confidence: 0.76)
DateOfIssue          : 11/12/20                       (confidence: 0.72)
DocumentNumber       : 000-000-000                    (confidence: 0.72)
FirstName            : TIMOTHY                        (confidence: 0.72)
LastName             : TOMPKINS                       (confidence: 0.75)
PlaceOfBirth         : Ireland                        (confidence: 0.66)
Handling download errors If the service cannot download the document from the supplied URL (for example, wrong filename or access issues) you may receive an HttpResponseError similar to this:
azure.core.exceptions.HttpResponseError: (InvalidRequest) Invalid request.
Code: InvalidRequest
Message: Invalid request.
Inner error: {
  "code": "InvalidContent",
  "message": "Could not download the file from the given URL."
}
Common causes: incorrect blob name/extension, broken URL, or container not publicly accessible. Ensure the URL is reachable and points to the correct file before re-running the analysis.
Example: wrong extension (id2.jpeg vs id2.jpg) prevented download — after fixing the blob name and re-running the same code against id2.jpg the expected extraction was returned:
— Document #1 (type: idDocument.residencePermit) ---------------------------
Category             : IR1                      (confidence: 0.48)
CountryRegion        : <no value>               (confidence: 0.99)
DateOfBirth          : 20 OCT 2002              (confidence: 0.66)
DateOfExpiration     : 10/26/32                 (confidence: 0.71)
DateOfIssue          : 10/25/20                 (confidence: 0.66)
DocumentNumber       : 123-456-789              (confidence: 0.67)
FirstName            : TEST V                   (confidence: 0.65)
LastName             : SPECIMEN                 (confidence: 0.70)
PlaceOfBirth         : Mexico                   (confidence: 0.56)
Quick comparison: REST vs SDK
FeatureREST APISDKs (C#, Python, etc.)
PollingManual polling of Operation-Location requiredPolling handled internally (begin_* returns poller)
Language integrationRaw JSON and headersLanguage-native objects and helpers
Error handlingHTTP status + headersRich exceptions (typed)
Ease of useMore control, more workFaster startup and easier consumption
Best practices and tips
  • Use api-version to pin behavior and avoid breaking changes.
  • Prefer SDKs for quicker integration and less polling code.
  • Validate confidence scores and bounding boxes before trusting critical fields.
  • When overlaying text on images, use bounding box coordinates and page dimensions returned in the response.
  • Test prebuilt models in Document Intelligence Studio to verify expected fields and sample accuracy.
Links and references That demonstrates how to work with Document Intelligence: configure access, call the analyze endpoint (REST or SDK), poll (if REST), and consume the structured output (pages → lines → words and high-level fields).

Watch Video