azure-ai-document-intelligence-ts
🤖 AI Summary
Extracts text, tables, and structured data from documents using Azure AI Document Intelligence, supporting both prebuilt and custom models via TypeScript.
How to Install
Claude Code:
git clone --depth 1 https://github.com/sickn33/antigravity-awesome-skills.git && cp antigravity-awesome-skills/skills/azure-ai-document-intelligence-ts ~/.claude/skills/azure-ai-document-intelligence-ts -rAzure Document Intelligence REST SDK for TypeScript
Extract text, tables, and structured data from documents using prebuilt and custom models.
Installation
npm install @azure-rest/ai-document-intelligence @azure/identity
Environment Variables
DOCUMENT_INTELLIGENCE_ENDPOINT=https://<resource>.cognitiveservices.azure.com
DOCUMENT_INTELLIGENCE_API_KEY=<api-key>
Authentication
Important: This is a REST client. DocumentIntelligence is a function, not a class.
DefaultAzureCredential
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
import { DefaultAzureCredential } from "@azure/identity";
const client = DocumentIntelligence(
process.env.DOCUMENT_INTELLIGENCE_ENDPOINT!,
new DefaultAzureCredential()
);
API Key
import DocumentIntelligence from "@azure-rest/ai-document-intelligence";
const client = DocumentIntelligence(
process.env.DOCUMENT_INTELLIGENCE_ENDPOINT!,
{ key: process.env.DOCUMENT_INTELLIGENCE_API_KEY! }
);
Analyze Document (URL)
import DocumentIntelligence, {
isUnexpected,
getLongRunningPoller,
AnalyzeOperationOutput
} from "@azure-rest/ai-document-intelligence";
const initialResponse = await client
.path("/documentModels/{modelId}:analyze", "prebuilt-layout")
.post({
contentType: "application/json",
body: {
urlSource: "https://example.com/document.pdf"
},
queryParameters: { locale: "en-US" }
});
if (isUnexpected(initialResponse)) {
throw initialResponse.body.error;
}
const poller = getLongRunningPoller(client, initialResponse);
const result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;
console.log("Pages:", result.analyzeResult?.pages?.length);
console.log("Tables:", result.analyzeResult?.tables?.length);
Analyze Document (Local File)
import { readFile } from "node:fs/promises";
const fileBuffer = await readFile("./document.pdf");
const base64Source = fileBuffer.toString("base64");
const initialResponse = await client
.path("/documentModels/{modelId}:analyze", "prebuilt-invoice")
.post({
contentType: "application/json",
body: { base64Source }
});
if (isUnexpected(initialResponse)) {
throw initialResponse.body.error;
}
const poller = getLongRunningPoller(client, initialResponse);
const result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;
Prebuilt Models
| Model ID | Description |
|---|---|
prebuilt-read |
OCR - text and language extraction |
prebuilt-layout |
Text, tables, selection marks, structure |
prebuilt-invoice |
Invoice fields |
prebuilt-receipt |
Receipt fields |
prebuilt-idDocument |
ID document fields |
prebuilt-tax.us.w2 |
W-2 tax form fields |
prebuilt-healthInsuranceCard.us |
Health insurance card fields |
prebuilt-contract |
Contract fields |
prebuilt-bankStatement.us |
Bank statement fields |
Extract Invoice Fields
const initialResponse = await client
.path("/documentModels/{modelId}:analyze", "prebuilt-invoice")
.post({
contentType: "application/json",
body: { urlSource: invoiceUrl }
});
if (isUnexpected(initialResponse)) {
throw initialResponse.body.error;
}
const poller = getLongRunningPoller(client, initialResponse);
const result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;
const invoice = result.analyzeResult?.documents?.[0];
if (invoice) {
console.log("Vendor:", invoice.fields?.VendorName?.content);
console.log("Total:", invoice.fields?.InvoiceTotal?.content);
console.log("Due Date:", invoice.fields?.DueDate?.content);
}
Extract Receipt Fields
const initialResponse = await client
.path("/documentModels/{modelId}:analyze", "prebuilt-receipt")
.post({
contentType: "application/json",
body: { urlSource: receiptUrl }
});
const poller = getLongRunningPoller(client, initialResponse);
const result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;
const receipt = result.analyzeResult?.documents?.[0];
if (receipt) {
console.log("Merchant:", receipt.fields?.MerchantName?.content);
console.log("Total:", receipt.fields?.Total?.content);
for (const item of receipt.fields?.Items?.values || []) {
console.log("Item:", item.properties?.Description?.content);
console.log("Price:", item.properties?.TotalPrice?.content);
}
}
List Document Models
import DocumentIntelligence, { isUnexpected, paginate } from "@azure-rest/ai-document-intelligence";
const response = await client.path("/documentModels").get();
if (isUnexpected(response)) {
throw response.body.error;
}
for await (const model of paginate(client, response)) {
console.log(model.modelId);
}
Build Custom Model
```typescript const initialResponse = await client.path("/documentModels:build").post({ body: { modelId: "my-custom-model", des
Details
| Category | DevOps → cicd |
| Source | sickn33/antigravity-awesome-skills |
| SKILL.md | View on GitHub → |
| Repo Stars | ★ 41.5K |
| Est. per Skill | 47 (shared across 868 skills from this repo) |
| Difficulty | Intermediate |
| Risk Level | N/A |
Related Skills
apify-audience-analysis
Audience Analysis Analyze and understand your audience using Apify Actors to extract follower demogr
apify-brand-reputation-monitoring
Brand Reputation Monitoring Scrape reviews, ratings, and brand mentions from multiple platforms usin
apify-competitor-intelligence
Competitor Intelligence Analyze competitors using Apify Actors to extract data from multiple platfor
apify-content-analytics
Content Analytics Track and analyze content performance using Apify Actors to extract engagement met
Works Well With
Skills from the same repository — often designed to work together
jq
jq — JSON Querying and Transformation Overview jq is the standard CLI tool for querying and reshapin
seo
SEO: Universal SEO Analysis Skill Comprehensive SEO analysis across all industries (SaaS, local serv
cirq
Cirq - Quantum Computing with Python Cirq is Google Quantum AI's open-source framework for designing