forked from chulahlou/CU-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCU-API-Testing-Guide.http
More file actions
556 lines (498 loc) · 21.5 KB
/
CU-API-Testing-Guide.http
File metadata and controls
556 lines (498 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
# ====================================================================
# Azure Content Understanding - API Testing Guide
# ====================================================================
#
# See README.md for prerequisites and setup instructions.
#
# DOCUMENTATION:
# - Overview: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/overview
# - REST API Reference: https://learn.microsoft.com/en-us/rest/api/contentunderstanding/operation-groups
#
# ====================================================================
#
# TABLE OF CONTENTS
# ====================================================================
# Use Ctrl+F (Windows) or Cmd+F (Mac) to jump to sections:
#
# QUICK START: Get Started in 3 Steps
# SECTION 1: Content Extraction (No LLM Required)
# SECTION 2: Domain-Specific Analyzers (invoice, tax, ID, etc.)
# SECTION 3: RAG Analyzers
# SECTION 4: Custom Analyzers with Field Extraction
# SECTION 5: Custom Video Analysis with Field Extraction
# SECTION 6: Analyzer Management (List, Copy, Delete)
#
# ====================================================================
# Variables - Loaded from .env file in the same directory
@subscriptionKey = {{$dotenv API_KEY}}
@endpoint = {{$dotenv ENDPOINT_URL}}
@apiVersion = 2025-11-01
# ====================================================================
# QUICK START: Get Started in 3 Steps
# ====================================================================
#
# Follow these steps to start analyzing content:
# 1. Check model deployments for 4.1, 4.1-mini, and text-embedding-ada-002 (required for RAG and domain analyzers)
# 2. Try content extraction (no LLM required)
# 3. Try domain-specific analyzer like invoice (may require LLM)
#
# Learn more: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/quickstart/use-rest-api
#
### STEP 1: Check current model deployment settings
# If you configured your resource via https://aka.ms/cu-studio, this should already be set
GET {{endpoint}}/contentunderstanding/defaults?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### STEP 1b: Configure model deployments (if needed)
# Only required if using BYOC (Bring Your Own Compute) with custom Azure OpenAI deployments
# Learn more: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/concepts/models-deployments
PATCH {{endpoint}}/contentunderstanding/defaults?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
Content-Type: application/json
{
"modelDeployments": {
"gpt-4.1": "<<your gpt-4.1 deployment name>>",
"gpt-4.1-mini": "<<your gpt-4.1-mini deployment name>>",
"text-embedding-ada-002": "<<your text-embedding-ada-002 deployment name>>",
"text-embedding-3-large": "<<your text-embedding-3-large deployment name>>"
}
}
### STEP 2: Try content extraction with prebuilt-layout
# ⚡ This analyzer does NOT require LLM models - works immediately!
# Extracts text, tables, figures, sections, hyperlinks, and annotations
# ────────────────────────────────────────────────────────────────────
# 📋 TWO-STEP PROCESS:
# ────────────────────────────────────────────────────────────────────
# This is a long-running async operation:
#
# STEP 1: POST request initiates the analysis (returns operation ID)
# STEP 2: GET request retrieves results using the operation ID
# ────────────────────────────────────────────────────────────────────
# STEP 1: POST to start layout analysis
# @name quickStartLayout
POST {{endpoint}}/contentunderstanding/analyzers/prebuilt-layout:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://github.com/Azure-Samples/cognitive-services-sample-data-files/raw/master/ComputerVision/Images/printed_text.jpg"
}
]
}
### STEP 2: Get layout analysis results
GET {{endpoint}}/contentunderstanding/analyzerResults/{{quickStartLayout.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### STEP 3: Try domain-specific analyzer, ex. prebuilt-invoice
# Extracts vendor, items, totals, dates from invoices
# This will use the LLM in default/models to perform Field Extraction
#
# You can also use other prebuilt analyzers like prebuilt-receipt, prebuilt-idDocument,
# prebuilt-tax.us.1040, just by changing the analyzer ID below.
# See full list: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/concepts/prebuilt-analyzers
# @name quickStartInvoice
POST {{endpoint}}/contentunderstanding/analyzers/prebuilt-invoice:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://github.com/Azure-Samples/azure-ai-content-understanding-python/raw/refs/heads/main/data/invoice.pdf"
}
]
}
### Get invoice analysis results
GET {{endpoint}}/contentunderstanding/analyzerResults/{{quickStartInvoice.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
# ====================================================================
# SECTION 1: CONTENT EXTRACTION (No LLM Required)
# ====================================================================
#
# ⚠️ These analyzers do NOT require LLM or embedding models.
# They work immediately after resource creation.
#
# - prebuilt-read: Basic OCR (words, paragraphs, formulas, barcodes)
# - prebuilt-layout: Advanced OCR with layout (tables, figures, sections)
#
# Learn more: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/document/overview
#
### 1.1 prebuilt-read: Basic OCR
# Extracts words, paragraphs, formulas, barcodes without layout analysis
# Example with handwritten text
# @name readAnalysis
POST {{endpoint}}/contentunderstanding/analyzers/prebuilt-read:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://github.com/Azure-Samples/cognitive-services-sample-data-files/raw/master/ComputerVision/Images/handwritten_text.jpg"
}
]
}
### Get read analysis results
GET {{endpoint}}/contentunderstanding/analyzerResults/{{readAnalysis.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### 1.2 prebuilt-layout: OCR with layout analysis
# Extracts text, tables, figures, sections, hyperlinks, annotations
# Example with document containing paragraphs and printed text
# @name layoutAnalysis
POST {{endpoint}}/contentunderstanding/analyzers/prebuilt-layout:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://github.com/Azure-Samples/cognitive-services-sample-data-files/raw/master/ComputerVision/Images/printed_text.jpg"
}
]
}
### Get layout analysis results
GET {{endpoint}}/contentunderstanding/analyzerResults/{{layoutAnalysis.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
# ====================================================================
# SECTION 2: DOMAIN-SPECIFIC ANALYZERS
# ====================================================================
#
# Preconfigured analyzers for common document types (invoice, receipt, tax forms,
# ID documents, etc.). Powered by rich knowledge bases of real-world examples.
#
# These analyzers may require LLM models depending on document complexity.
# Replace 'prebuilt-invoice' with any analyzer from the list below:
#
# Financial: prebuilt-invoice, prebuilt-receipt, prebuilt-creditCard
# Identity: prebuilt-idDocument, prebuilt-healthInsuranceCard.us
# Tax (US): prebuilt-tax.us.1040, prebuilt-tax.us.w2, prebuilt-tax.us.1099*
# Mortgage (US): prebuilt-mortgage.us.1003, prebuilt-mortgage.us.1004
# Other: prebuilt-utilityBill, prebuilt-payStub.us, prebuilt-contract
#
# Learn more: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/concepts/prebuilt-analyzers
#
### 2.1 Analyze with prebuilt-invoice
# Extracts vendor, items, totals, dates from invoices
# @name invoiceAnalysis
POST {{endpoint}}/contentunderstanding/analyzers/prebuilt-invoice:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://github.com/Azure-Samples/azure-ai-content-understanding-python/raw/refs/heads/main/data/invoice.pdf"
}
]
}
### Get invoice analysis results
GET {{endpoint}}/contentunderstanding/analyzerResults/{{invoiceAnalysis.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### 2.2 Analyze with prebuilt-document
# General-purpose document analysis with tables, key-value pairs, entities
# Works with any document type - no domain-specific training needed
# @name documentAnalysis
POST {{endpoint}}/contentunderstanding/analyzers/prebuilt-document:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://github.com/Azure-Samples/azure-ai-content-understanding-python/raw/refs/heads/main/data/mixed_financial_docs.pdf"
}
]
}
### Get document analysis results
GET {{endpoint}}/contentunderstanding/analyzerResults/{{documentAnalysis.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
# ====================================================================
# SECTION 3: RAG ANALYZERS (Requires LLM + Embeddings)
# ====================================================================
#
# ⚠️ These analyzers REQUIRE gpt-4.1-mini (or gpt-4.1) and embedding models.
# Configure model deployments in QUICK START before using these analyzers.
#
# Optimized for RAG scenarios with semantic analysis and markdown extraction:
# - prebuilt-documentSearch: Document ingestion with summaries
# - prebuilt-imageSearch: Image analysis with descriptions
# - prebuilt-audioSearch: Audio transcription with summaries
# - prebuilt-videoSearch: Video segmentation with transcripts
#
# Learn more:
# - Documents: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/document/overview
# - Images: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/image/overview
# - Audio: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/audio/overview
# - Video: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/video/overview
#
### 3.1 prebuilt-documentSearch: Document ingestion for RAG
# Extracts content, tables, figures with descriptions, chart.js/mermaid.js output
# Generates document summaries, captures annotations, supports many formats
#
# ⚡ Uses GPT-4.1-mini to generate detailed descriptions of all figures/charts
# Search results for "figures" to see AI-generated visual descriptions like:
# "id": "1.1", "description": "Five wind turbines with three blades each,
# solar panels in foreground, sunset sky..."
#
# 💡 TIP: Use "range" parameter to limit analysis to specific pages
# Format: "1-3" (pages 1-3), "1,5,7" (specific pages), or "1-3,7-9" (mixed)
# This processes only the specified pages, reducing cost and latency
#
# @name ragAnalysis
POST {{endpoint}}/contentunderstanding/analyzers/prebuilt-documentSearch:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://raw.githubusercontent.com/Azure-Samples/azure-search-sample-data/refs/heads/main/sustainable-ai-pdf/Accelerating-Sustainability-with-AI-2025.pdf",
"range": "1-3"
}
]
}
### Get RAG analysis results
GET {{endpoint}}/contentunderstanding/analyzerResults/{{ragAnalysis.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### Get RAG analyser definition
GET {{endpoint}}/contentunderstanding/analyzers/prebuilt-documentSearch?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### 3.2 Other RAG analyzers (similar pattern)
# Replace 'prebuilt-documentSearch' with:
# - prebuilt-imageSearch: Image analysis with descriptions
# - prebuilt-audioSearch: Audio transcription with summaries
# - prebuilt-videoSearch: Video segmentation with transcripts
# and swap input URLs accordingly.
# ====================================================================
# SECTION 4: CUSTOM ANALYZERS WITH FIELD EXTRACTION
# ====================================================================
#
# FIELD EXTRACTION is the core value proposition of custom analyzers.
# Define a field schema to extract specific structured data from your content.
#
# Field extraction methods:
# - extract: Extract existing data from the content (e.g., policy number)
# - classify: Classify content into predefined categories (e.g., loss type)
# - generate: Generate new insights from the content (e.g., summaries)
#
# Learn more: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/tutorial/create-custom-analyzer
#
### 4.1 Create custom analyzer with field extraction
# Example: Custom invoice analyzer extracting top-level fields and line items
PUT {{endpoint}}/contentunderstanding/analyzers/custom_invoice?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
Content-Type: application/json
{
"baseAnalyzerId": "prebuilt-document",
"analyzerId": "custom_invoice",
"models": {
"completion": "gpt-4.1",
"embedding": "text-embedding-ada-002"
},
"fieldSchema": {
"fields": {
"InvoiceNumber": {
"type": "string",
"method": "extract",
"description": "The invoice number (e.g., INV-100)"
},
"InvoiceDate": {
"type": "string",
"method": "extract",
"description": "The invoice date"
},
"CustomerName": {
"type": "string",
"method": "extract",
"description": "The customer name or company name"
},
"TotalAmount": {
"type": "number",
"method": "extract",
"description": "The total amount due on the invoice"
},
"Subtotal": {
"type": "number",
"method": "extract",
"description": "The subtotal before taxes"
},
"SalesTax": {
"type": "number",
"method": "extract",
"description": "The sales tax amount"
},
"LineItems": {
"type": "array",
"method": "extract",
"description": "Individual line items from the invoice",
"items": {
"type": "object",
"properties": {
"Date": {
"type": "string",
"description": "Date of the service or item"
},
"Description": {
"type": "string",
"description": "Description of the service or item"
},
"Quantity": {
"type": "number",
"description": "Quantity or hours"
},
"Price": {
"type": "number",
"description": "Unit price"
},
"Amount": {
"type": "number",
"description": "Line item total amount"
}
}
}
}
},
"definitions": {}
},
"omitContent": true
}
### Get analyzer definition
GET {{endpoint}}/contentunderstanding/analyzers/custom_invoice?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### 4.2 Test the custom analyzer with invoice
# @name customAnalysis
POST {{endpoint}}/contentunderstanding/analyzers/custom_invoice:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://github.com/Azure-Samples/azure-ai-content-understanding-python/raw/refs/heads/main/data/invoice.pdf"
}
]
}
### Get custom analysis results
GET {{endpoint}}/contentunderstanding/analyzerResults/{{customAnalysis.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
# ====================================================================
# SECTION 5: CUSTOM VIDEO ANALYSIS WITH FIELD EXTRACTION
# ====================================================================
#
# Video analyzers demonstrate advanced field extraction with nested structures.
# Extract segments, scenes, timestamps, and generated insights from video content.
#
# Learn more: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/video/overview
#
### 5.1 Create custom video analyzer with field extraction
# Example: Dynamic chaptering with segments, scenes, and timestamps
PUT {{endpoint}}/contentunderstanding/analyzers/video_scenes_list?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
Content-Type: application/json
{
"description": "Dynamic video chaptering with scene detection",
"scenario": "videoShot",
"baseAnalyzerId": "prebuilt-video",
"models": {
"completion": "gpt-4.1"
},
"config": {
"returnDetails": true,
"enableSegmentation": true,
"locales": ["en-US"]
},
"fieldSchema": {
"name": "Content Understanding - Dynamic Chaptering",
"fields": {
"Segments": {
"type": "array",
"items": {
"type": "object",
"properties": {
"SegmentId": {
"type": "string"
},
"SegmentType": {
"type": "string",
"method": "generate",
"description": "The short title or a short summary of the story or chapter."
},
"Scenes": {
"type": "array",
"items": {
"type": "object",
"properties": {
"Description": {
"type": "string",
"method": "generate",
"description": "A five-word description of the scene. A scene is a smaller segment of the segment where a continous block for storytelling unfolds within a specific time, place, and set of characters. A scene can only belong to a single chapter, and cannot overlap with other scenes. Scenes are sequential across the video."
},
"StartTimestamp": {
"type": "string",
"description": "the start timestamp of the scene"
},
"EndTimestamp": {
"type": "string",
"description": "the end timestamp of the scene"
}
}
}
}
}
}
}
}
}
}
### Get video analyzer definition
GET {{endpoint}}/contentunderstanding/analyzers/video_chaptering?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### 5.2 Test video analyzer
# @name videoAnalysis
POST {{endpoint}}/contentunderstanding/analyzers/video_chaptering:analyze?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"inputs": [
{
"url": "https://github.com/Azure-Samples/azure-ai-content-understanding-python/raw/refs/heads/main/data/FlightSimulator.mp4"
}
]
}
### Get video analysis results
# ⏱️ NOTE: Video processing takes 1-2x the video duration
# A 2-minute video may take 2-4 minutes to complete analysis
# The service processes video at 2-3x human viewing speed
GET {{endpoint}}/contentunderstanding/analyzerResults/{{videoAnalysis.response.body.id}}?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
# ====================================================================
# SECTION 6: ANALYZER MANAGEMENT (List, Copy, Delete)
# ====================================================================
#
# Explore, copy, and manage your analyzers.
#
# Learn more: https://learn.microsoft.com/en-us/azure/ai-services/content-understanding/concepts/prebuilt-analyzers
#
### 6.1 List all available analyzers
GET {{endpoint}}/contentunderstanding/analyzers?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### 6.2 List only prebuilt analyzers
GET {{endpoint}}/contentunderstanding/analyzers?api-version={{apiVersion}}&$filter=startswith(analyzerId,'prebuilt-')
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### 6.3 Get specific analyzer definition
GET {{endpoint}}/contentunderstanding/analyzers/prebuilt-invoice?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
### 6.4 Copy analyzer within same resource
# Useful for versioning or creating variations
POST {{endpoint}}/contentunderstanding/analyzers/video_scenes_list-v2:copy?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"sourceAnalyzerId": "video_scenes_list"
}
### 6.5 Copy prebuilt to create stable version
# Lock a prebuilt analyzer definition to prevent changes across API versions
POST {{endpoint}}/contentunderstanding/analyzers/my-invoice:copy?api-version={{apiVersion}}
Content-Type: application/json
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
{
"sourceAnalyzerId": "prebuilt-invoice"
}
### 6.6 Delete custom analyzer
DELETE {{endpoint}}/contentunderstanding/analyzers/my-invoice?api-version={{apiVersion}}
Ocp-Apim-Subscription-Key: {{subscriptionKey}}
# ====================================================================
# END OF GUIDE
# ====================================================================