[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-bf828d19-b120-4e74-8657-a53f0a3a8e82":3,"$fLe0i2iEkHKIbtdidJcSEjssag4ZIramWxdezgdqqnI4":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"bf828d19-b120-4e74-8657-a53f0a3a8e82","azure-ai-document-intelligence-ts","使用预建和自定义模型从文档中提取文本、表格和结构化数据。","cat_coding_devops","mod_coding","sickn33,coding","---\nname: azure-ai-document-intelligence-ts\ndescription: \"Extract text, tables, and structured data from documents using prebuilt and custom models.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# Azure Document Intelligence REST SDK for TypeScript\n\nExtract text, tables, and structured data from documents using prebuilt and custom models.\n\n## Installation\n\n```bash\nnpm install @azure-rest\u002Fai-document-intelligence @azure\u002Fidentity\n```\n\n## Environment Variables\n\n```bash\nDOCUMENT_INTELLIGENCE_ENDPOINT=https:\u002F\u002F\u003Cresource>.cognitiveservices.azure.com\nDOCUMENT_INTELLIGENCE_API_KEY=\u003Capi-key>\n```\n\n## Authentication\n\n**Important**: This is a REST client. `DocumentIntelligence` is a **function**, not a class.\n\n### DefaultAzureCredential\n\n```typescript\nimport DocumentIntelligence from \"@azure-rest\u002Fai-document-intelligence\";\nimport { DefaultAzureCredential } from \"@azure\u002Fidentity\";\n\nconst client = DocumentIntelligence(\n  process.env.DOCUMENT_INTELLIGENCE_ENDPOINT!,\n  new DefaultAzureCredential()\n);\n```\n\n### API Key\n\n```typescript\nimport DocumentIntelligence from \"@azure-rest\u002Fai-document-intelligence\";\n\nconst client = DocumentIntelligence(\n  process.env.DOCUMENT_INTELLIGENCE_ENDPOINT!,\n  { key: process.env.DOCUMENT_INTELLIGENCE_API_KEY! }\n);\n```\n\n## Analyze Document (URL)\n\n```typescript\nimport DocumentIntelligence, {\n  isUnexpected,\n  getLongRunningPoller,\n  AnalyzeOperationOutput\n} from \"@azure-rest\u002Fai-document-intelligence\";\n\nconst initialResponse = await client\n  .path(\"\u002FdocumentModels\u002F{modelId}:analyze\", \"prebuilt-layout\")\n  .post({\n    contentType: \"application\u002Fjson\",\n    body: {\n      urlSource: \"https:\u002F\u002Fexample.com\u002Fdocument.pdf\"\n    },\n    queryParameters: { locale: \"en-US\" }\n  });\n\nif (isUnexpected(initialResponse)) {\n  throw initialResponse.body.error;\n}\n\nconst poller = getLongRunningPoller(client, initialResponse);\nconst result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;\n\nconsole.log(\"Pages:\", result.analyzeResult?.pages?.length);\nconsole.log(\"Tables:\", result.analyzeResult?.tables?.length);\n```\n\n## Analyze Document (Local File)\n\n```typescript\nimport { readFile } from \"node:fs\u002Fpromises\";\n\nconst fileBuffer = await readFile(\".\u002Fdocument.pdf\");\nconst base64Source = fileBuffer.toString(\"base64\");\n\nconst initialResponse = await client\n  .path(\"\u002FdocumentModels\u002F{modelId}:analyze\", \"prebuilt-invoice\")\n  .post({\n    contentType: \"application\u002Fjson\",\n    body: { base64Source }\n  });\n\nif (isUnexpected(initialResponse)) {\n  throw initialResponse.body.error;\n}\n\nconst poller = getLongRunningPoller(client, initialResponse);\nconst result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;\n```\n\n## Prebuilt Models\n\n| Model ID | Description |\n|----------|-------------|\n| `prebuilt-read` | OCR - text and language extraction |\n| `prebuilt-layout` | Text, tables, selection marks, structure |\n| `prebuilt-invoice` | Invoice fields |\n| `prebuilt-receipt` | Receipt fields |\n| `prebuilt-idDocument` | ID document fields |\n| `prebuilt-tax.us.w2` | W-2 tax form fields |\n| `prebuilt-healthInsuranceCard.us` | Health insurance card fields |\n| `prebuilt-contract` | Contract fields |\n| `prebuilt-bankStatement.us` | Bank statement fields |\n\n## Extract Invoice Fields\n\n```typescript\nconst initialResponse = await client\n  .path(\"\u002FdocumentModels\u002F{modelId}:analyze\", \"prebuilt-invoice\")\n  .post({\n    contentType: \"application\u002Fjson\",\n    body: { urlSource: invoiceUrl }\n  });\n\nif (isUnexpected(initialResponse)) {\n  throw initialResponse.body.error;\n}\n\nconst poller = getLongRunningPoller(client, initialResponse);\nconst result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;\n\nconst invoice = result.analyzeResult?.documents?.[0];\nif (invoice) {\n  console.log(\"Vendor:\", invoice.fields?.VendorName?.content);\n  console.log(\"Total:\", invoice.fields?.InvoiceTotal?.content);\n  console.log(\"Due Date:\", invoice.fields?.DueDate?.content);\n}\n```\n\n## Extract Receipt Fields\n\n```typescript\nconst initialResponse = await client\n  .path(\"\u002FdocumentModels\u002F{modelId}:analyze\", \"prebuilt-receipt\")\n  .post({\n    contentType: \"application\u002Fjson\",\n    body: { urlSource: receiptUrl }\n  });\n\nconst poller = getLongRunningPoller(client, initialResponse);\nconst result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;\n\nconst receipt = result.analyzeResult?.documents?.[0];\nif (receipt) {\n  console.log(\"Merchant:\", receipt.fields?.MerchantName?.content);\n  console.log(\"Total:\", receipt.fields?.Total?.content);\n  \n  for (const item of receipt.fields?.Items?.values || []) {\n    console.log(\"Item:\", item.properties?.Description?.content);\n    console.log(\"Price:\", item.properties?.TotalPrice?.content);\n  }\n}\n```\n\n## List Document Models\n\n```typescript\nimport DocumentIntelligence, { isUnexpected, paginate } from \"@azure-rest\u002Fai-document-intelligence\";\n\nconst response = await client.path(\"\u002FdocumentModels\").get();\n\nif (isUnexpected(response)) {\n  throw response.body.error;\n}\n\nfor await (const model of paginate(client, response)) {\n  console.log(model.modelId);\n}\n```\n\n## Build Custom Model\n\n```typescript\nconst initialResponse = await client.path(\"\u002FdocumentModels:build\").post({\n  body: {\n    modelId: \"my-custom-model\",\n    description: \"Custom model for purchase orders\",\n    buildMode: \"template\",  \u002F\u002F or \"neural\"\n    azureBlobSource: {\n      containerUrl: process.env.TRAINING_CONTAINER_SAS_URL!,\n      prefix: \"training-data\u002F\"\n    }\n  }\n});\n\nif (isUnexpected(initialResponse)) {\n  throw initialResponse.body.error;\n}\n\nconst poller = getLongRunningPoller(client, initialResponse);\nconst result = await poller.pollUntilDone();\nconsole.log(\"Model built:\", result.body);\n```\n\n## Build Document Classifier\n\n```typescript\nimport { DocumentClassifierBuildOperationDetailsOutput } from \"@azure-rest\u002Fai-document-intelligence\";\n\nconst containerSasUrl = process.env.TRAINING_CONTAINER_SAS_URL!;\n\nconst initialResponse = await client.path(\"\u002FdocumentClassifiers:build\").post({\n  body: {\n    classifierId: \"my-classifier\",\n    description: \"Invoice vs Receipt classifier\",\n    docTypes: {\n      invoices: {\n        azureBlobSource: { containerUrl: containerSasUrl, prefix: \"invoices\u002F\" }\n      },\n      receipts: {\n        azureBlobSource: { containerUrl: containerSasUrl, prefix: \"receipts\u002F\" }\n      }\n    }\n  }\n});\n\nif (isUnexpected(initialResponse)) {\n  throw initialResponse.body.error;\n}\n\nconst poller = getLongRunningPoller(client, initialResponse);\nconst result = (await poller.pollUntilDone()).body as DocumentClassifierBuildOperationDetailsOutput;\nconsole.log(\"Classifier:\", result.result?.classifierId);\n```\n\n## Classify Document\n\n```typescript\nconst initialResponse = await client\n  .path(\"\u002FdocumentClassifiers\u002F{classifierId}:analyze\", \"my-classifier\")\n  .post({\n    contentType: \"application\u002Fjson\",\n    body: { urlSource: documentUrl },\n    queryParameters: { split: \"auto\" }\n  });\n\nif (isUnexpected(initialResponse)) {\n  throw initialResponse.body.error;\n}\n\nconst poller = getLongRunningPoller(client, initialResponse);\nconst result = await poller.pollUntilDone();\nconsole.log(\"Classification:\", result.body.analyzeResult?.documents);\n```\n\n## Get Service Info\n\n```typescript\nconst response = await client.path(\"\u002Finfo\").get();\n\nif (isUnexpected(response)) {\n  throw response.body.error;\n}\n\nconsole.log(\"Custom model limit:\", response.body.customDocumentModels.limit);\nconsole.log(\"Custom model count:\", response.body.customDocumentModels.count);\n```\n\n## Polling Pattern\n\n```typescript\nimport DocumentIntelligence, {\n  isUnexpected,\n  getLongRunningPoller,\n  AnalyzeOperationOutput\n} from \"@azure-rest\u002Fai-document-intelligence\";\n\n\u002F\u002F 1. Start operation\nconst initialResponse = await client\n  .path(\"\u002FdocumentModels\u002F{modelId}:analyze\", \"prebuilt-layout\")\n  .post({ contentType: \"application\u002Fjson\", body: { urlSource } });\n\n\u002F\u002F 2. Check for errors\nif (isUnexpected(initialResponse)) {\n  throw initialResponse.body.error;\n}\n\n\u002F\u002F 3. Create poller\nconst poller = getLongRunningPoller(client, initialResponse);\n\n\u002F\u002F 4. Optional: Monitor progress\npoller.onProgress((state) => {\n  console.log(\"Status:\", state.status);\n});\n\n\u002F\u002F 5. Wait for completion\nconst result = (await poller.pollUntilDone()).body as AnalyzeOperationOutput;\n```\n\n## Key Types\n\n```typescript\nimport DocumentIntelligence, {\n  isUnexpected,\n  getLongRunningPoller,\n  paginate,\n  parseResultIdFromResponse,\n  AnalyzeOperationOutput,\n  DocumentClassifierBuildOperationDetailsOutput\n} from \"@azure-rest\u002Fai-document-intelligence\";\n```\n\n## Best Practices\n\n1. **Use getLongRunningPoller()** - Document analysis is async, always poll for results\n2. **Check isUnexpected()** - Type guard for proper error handling\n3. **Choose the right model** - Use prebuilt models when possible, custom for specialized docs\n4. **Handle confidence scores** - Fields have confidence values, set thresholds for your use case\n5. **Use pagination** - Use `paginate()` helper for listing models\n6. **Prefer neural mode** - For custom models, neural handles more variation than template\n\n## When to Use\nThis skill is applicable to execute the workflow or actions described in the overview.\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,100,513,"2026-05-16 13:05:14",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"DevOps","devops","mdi-cog-outline","CI\u002FCD、容器化、部署运维",3,162,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"d8d02969-0681-4107-9392-f3ce62679ebe","1.0.0","azure-ai-document-intelligence-ts.zip",2619,"uploads\u002Fskills\u002Fbf828d19-b120-4e74-8657-a53f0a3a8e82\u002Fazure-ai-document-intelligence-ts.zip","efbfb69db058990271a348654889239d82e803e5d8fd132706fcd79c890d51a0","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":9417}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]