Muokkaa

Jaa


SDK target: REST API v2.1 (GA)

Document Intelligence checkmark REST API version v2.1 (GA) 21-06-08

Azure AI Document Intelligence is a cloud service that uses machine learning to analyze text and structured data from documents. The Document Intelligence software development kit (SDK) is a set of libraries and tools that enable you to easily integrate Document Intelligence models and capabilities into your applications. Document Intelligence SDK is available across platforms in C#/.NET, Java, JavaScript, and Python programming languages.

Supported programming languages

Document Intelligence SDK supports the following languages and platforms:

Language → Document Intelligence SDK version Package Supported API version Platform support
.NET/C# → 3.1.x (GA) NuGet v2.1 Windows, macOS, Linux, Docker
Java → 3.1.x (GA) Maven repository v2.1 Windows, macOS, Linux
JavaScript → 3.1.0 (GA) npm v2.1 Browser, Windows, macOS, Linux
Python → 3.1.0 (GA) PyPI v2.1
Windows, macOS, Linux

For more information on other SDK versions, see:

Supported Clients

Language SDK version API version Supported clients
.NET/C#
Java
JavaScript
3.1.x v2.1 (default)
v2.0
FormRecognizerClient
FormTrainingClient
.NET/C#
Java
JavaScript
3.0.x v2.0 FormRecognizerClient
FormTrainingClient
Python 3.1.x v2.1 (default)
v2.0
FormRecognizerClient
FormTrainingClient
Python 3.0.0 v2.0 FormRecognizerClient
FormTrainingClient

Use Document Intelligence SDK in your applications

The Document Intelligence SDK enables the use and management of the Document Intelligence service in your application. The SDK builds on the underlying Document Intelligence REST API allowing you to easily use those APIs within your programming language paradigm. Here's how you use the Document Intelligence SDK for your preferred language:

1. Install the SDK client library

dotnet add package Azure.AI.FormRecognizer --version 3.1.0
Install-Package Azure.AI.FormRecognizer -Version 3.1.0

2. Import the SDK client library into your application

using Azure;
using Azure.AI.FormRecognizer.Models;

3. Set up authentication

There are two supported methods for authentication.

Use your API key

Here's where to find your Document Intelligence API key in the Azure portal:

Screenshot of the keys and endpoint location in the Azure portal.

Important

We recommend Microsoft Entra ID authentication with managed identities for Azure resources to avoid storing credentials with your applications that run in the cloud.

If you use an API key, store it securely somewhere else, such as in Azure Key Vault. Don't include the API key directly in your code, and never post it publicly.

For more information about AI services security, see Authenticate requests to Azure AI services.


//set `<your-endpoint>` and `<your-key>` variables with the values from the Azure portal to create your `AzureKeyCredential` and `FormRecognizerClient` instance
  string key = "<your-key>";
  string endpoint = "<your-endpoint>";
  FormRecognizerClient client = new FormRecognizerClient(new Uri(endpoint), new AzureKeyCredential(key));

Use a Microsoft Entra token credential

Note

Regional endpoints do not support Microsoft Entra authentication. Create a custom subdomain for your resource in order to use this type of authentication.

Authorization is easiest using the DefaultAzureCredential. It provides a default token credential, based upon the running environment, capable of handling most Azure authentication scenarios.

Here's how to acquire and use the DefaultAzureCredential for .NET applications:

  1. Install the Azure Identity library for .NET:

        dotnet add package Azure.Identity
    
        Install-Package Azure.Identity
    
  2. Register a Microsoft Entra application and create a new service principal.

  3. Grant access to Document Intelligence by assigning the Cognitive Services User role to your service principal.

  4. Set the values of the client ID, tenant ID, and client secret in the Microsoft Entra application as environment variables: AZURE_CLIENT_ID, AZURE_TENANT_ID, and AZURE_CLIENT_SECRET, respectively.

  5. Create your FormRecognizerClient instance including the DefaultAzureCredential:

    string endpoint = "<your-endpoint>";
    var client = new FormRecognizerClient(new Uri(endpoint), new DefaultAzureCredential());
    

For more information, see Authenticate the client.

4. Build your application

Create a client object to interact with the Document Intelligence SDK, and then call methods on that client object to interact with the service. The SDKs provide both synchronous and asynchronous methods. For more insight, try a quickstart in a language of your choice.

Help options

The Microsoft Q & A and Stack Overflow forums are available for the developer community to ask and answer questions about Azure AI Document Intelligence and other services. Microsoft monitors the forums and replies to questions that the community has yet to answer. To make sure that we see your question, tag it with azure-form-recognizer.

Next steps