> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Analyzing Documents Using Custom Model

> Guide for running a deployed Azure Document Intelligence custom model to analyze documents, authenticate requests, use SDKs, and retrieve structured AnalyzeResult via poller.

Analyze documents with a custom-trained model in [Azure Document Intelligence](https://learn.microsoft.com/azure/applied-ai-services/document-intelligence/). This guide covers the authentication and request pattern needed to run a deployed custom model and retrieve the structured results returned by the service.

Key workflow summary:

* Provide the Document Intelligence resource endpoint and an access key to authenticate API calls.
* Include the deployed custom model's ID in the analysis request so the service knows which model to execute.
* The service returns a poller object for long-running analysis operations; use it to monitor progress and obtain the final AnalyzeResult once processing completes.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/GllRB2BDGSXhqELa/images/AI-102-Microsoft-Certified-Azure-AI-Engineer-Associate/Develop-a-Document-Intelligence-Solution/Analyzing-Documents-Using-Custom-Model/analyzing-documents-custom-model-steps.jpg?fit=max&auto=format&n=GllRB2BDGSXhqELa&q=85&s=d2a4758d4156c846c1bbecd16ea91eb0" alt="A presentation slide titled &#x22;Analyzing Documents Using Custom Model&#x22; showing three numbered steps about needing an endpoint and key, including the deployed model ID in requests, and querying the poller to retrieve processed data. The design uses a dark blue background with teal accent bars and numbering." width="1920" height="1080" data-path="images/AI-102-Microsoft-Certified-Azure-AI-Engineer-Associate/Develop-a-Document-Intelligence-Solution/Analyzing-Documents-Using-Custom-Model/analyzing-documents-custom-model-steps.jpg" />
</Frame>

<Callout icon="lightbulb" color="#1CB2FE">
  Before calling the SDK, confirm your custom model is deployed and take note of the model ID. Ensure the document URI is reachable by the service (public URL or storage with proper access). If you use SAS-secured blobs, verify the token grants read access to the file.
</Callout>

Below are example usage patterns for the SDKs. The primary difference from built-in models is that you explicitly pass your custom model's ID when starting the analysis so the service can run the correct trained model.

C# example (async, using DocumentAnalysisClient)

```csharp theme={null}
using Azure;
using Azure.AI.DocumentAnalysis;
using System;

// create the client with the endpoint and key
var client = new DocumentAnalysisClient(new Uri("<your-endpoint>"), new AzureKeyCredential("<your-key>"));

// provide your deployed model ID and the document URI
string modelId = "your-custom-model-id";
Uri documentUri = new Uri("https://example.com/path/to/document.pdf");

// start analysis and wait for completion (poller)
AnalyzeDocumentOperation operation = await client.AnalyzeDocumentFromUriAsync(WaitUntil.Completed, modelId, documentUri);

// get the result once the operation finishes
AnalyzeResult result = operation.Value;

// 'result' now contains pages, fields extracted by your model, confidence scores, and layout metadata
```

Python example (poller)

```python theme={null}
from azure.ai.documentanalysis import DocumentAnalysisClient
from azure.core.credentials import AzureKeyCredential

# create the client
endpoint = "https://<your-endpoint>"
key = "<your-key>"
client = DocumentAnalysisClient(endpoint, AzureKeyCredential(key))

# specify your deployed model ID and the document URL
model_id = "your-custom-model-id"
file_url = "https://example.com/path/to/document.pdf"

# begin analysis; returns a poller for a long-running operation
poller = client.begin_analyze_document_from_url(model_id=model_id, document_url=file_url)

# wait for completion and obtain the result
result = poller.result()

# 'result' contains pages, extracted fields, confidence scores, and other structured output
```

Common SDK method mapping

|                     SDK / Language | Method to start analysis                                      | Returns                                     |
| ---------------------------------: | ------------------------------------------------------------- | ------------------------------------------- |
|     C# (Azure.AI.DocumentAnalysis) | AnalyzeDocumentFromUriAsync(WaitUntil, modelId, uri)          | AnalyzeDocumentOperation (poller)           |
| Python (azure.ai.documentanalysis) | begin\_analyze\_document\_from\_url(model\_id, document\_url) | LROPoller -> result() returns AnalyzeResult |

<Callout icon="warning" color="#FF6B6B">
  Be careful with secrets and endpoint values. Never check your Azure keys into source control. If using storage URIs with tokens, ensure the token provides read access and is valid for the duration of the analysis.
</Callout>

Inspecting results

* Once the poller completes, the returned AnalyzeResult (C#) or result (Python) contains:
  * Extracted fields as defined by your custom model (names, values, and confidence scores).
  * Page and layout information (text lines, bounding regions).
  * Additional metadata such as page ranges and any warnings produced during processing.
* Use these fields to populate downstream processes, persist structured data, or drive business logic that depends on the extracted content.

Links and references

* [Azure Document Intelligence documentation](https://learn.microsoft.com/azure/applied-ai-services/document-intelligence/)
* [Quickstart: Analyze documents using the Document Analysis client library](https://learn.microsoft.com/azure/applied-ai-services/document-intelligence/quickstarts)
* SDK packages:
  * C#: Azure.AI.DocumentAnalysis
  * Python: azure.ai.documentanalysis

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/ai-102-microsoft-certified-azure-ai-engineer-associate/module/85c9f500-329b-4e86-b15c-f2e499d8bee6/lesson/0188c6a9-34fd-4f24-a143-ad9ce7b7e5d0" />
</CardGroup>
