Skip to content

[ContentUnderstanding] Expose usage property on AnalyzeLROPoller#46278

Merged
chienyuanchang merged 23 commits into
mainfrom
cu-sdk/add_usage
Apr 20, 2026
Merged

[ContentUnderstanding] Expose usage property on AnalyzeLROPoller#46278
chienyuanchang merged 23 commits into
mainfrom
cu-sdk/add_usage

Conversation

@chienyuanchang

@chienyuanchang chienyuanchang commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes #46249

The Content Understanding REST API returns a usage field as a sibling of result in the LRO response envelope (ContentAnalyzerAnalyzeOperationStatus). The generated get_long_running_output callback only extracts the result field, discarding usage. This PR adds a usage property to both AnalyzeLROPoller (sync) and AnalyzeAsyncLROPoller (async) that reads the usage data directly from the final polling response and deserializes it into a UsageDetails model.

Changes

Bug fix

  • models/_patch.py / aio/models/_patch.py: Added usage property to AnalyzeLROPoller and AnalyzeAsyncLROPoller. The property reads usage from the final HTTP response JSON and deserializes it into UsageDetails. Returns None if unavailable.

Samples

  • samples/sample_analyze_invoice.py / samples/async_samples/sample_analyze_invoice_async.py: Added # [START get_usage] / # [END get_usage] snippet demonstrating how to access billing and token consumption details after analysis completes.

Tests

  • tests/test_analyzer_operation_id.py: Added TestAnalyzeLROPollerUsage with 4 unit tests covering usage deserialization, missing usage, and malformed response handling.
  • tests/test_helpers.py: Added assert_analyze_poller_usage() shared helper for live/recorded test assertions.
  • tests/test_content_understanding_content_analyzers_operations.py: Added usage assertions to 3 sync recorded tests.
  • tests/test_content_understanding_content_analyzers_operations_async.py: Added usage assertions to 3 async recorded tests.
  • tests/samples/test_sample_analyze_invoice.py / test_sample_analyze_invoice_async.py: Added usage assertions to sample tests.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message. This means that previously merged commits do not appear in the history of the PR. For more information on cleaning up the commits in your PR, see this page.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

@chienyuanchang chienyuanchang marked this pull request as ready for review April 13, 2026 20:09
Copilot AI review requested due to automatic review settings April 13, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes the Content Understanding analyze LRO response envelope’s usage field via a new usage property on the custom sync/async analyze pollers, and updates samples/tests to demonstrate and validate the new surface area.

Changes:

  • Added usage property to AnalyzeLROPoller and AnalyzeAsyncLROPoller, deserializing into UsageDetails.
  • Updated sync/async invoice samples (and sample tests) to show how to read poller.usage after completion.
  • Added/updated unit + recorded tests and bumped package version/docs/changelog for the fix.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/models/_patch.py Adds sync poller .usage property reading/deserializing usage from final polling response.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/aio/models/_patch.py Adds async poller .usage property reading/deserializing usage from final polling response.
sdk/contentunderstanding/azure-ai-contentunderstanding/tests/test_analyzer_operation_id.py Adds unit tests for usage deserialization and missing usage scenarios.
sdk/contentunderstanding/azure-ai-contentunderstanding/tests/test_helpers.py Adds shared helper assertion for .usage presence on completed pollers.
sdk/contentunderstanding/azure-ai-contentunderstanding/tests/test_content_understanding_content_analyzers_operations.py Adds recorded-test assertions that .usage is available after analyze completes (sync).
sdk/contentunderstanding/azure-ai-contentunderstanding/tests/test_content_understanding_content_analyzers_operations_async.py Adds recorded-test assertions that .usage is available after analyze completes (async).
sdk/contentunderstanding/azure-ai-contentunderstanding/samples/sample_analyze_invoice.py Adds snippet showing how to access/print .usage in sync sample.
sdk/contentunderstanding/azure-ai-contentunderstanding/samples/async_samples/sample_analyze_invoice_async.py Adds snippet showing how to access/print .usage in async sample.
sdk/contentunderstanding/azure-ai-contentunderstanding/tests/samples/test_sample_analyze_invoice.py Adds sample test assertions validating .usage is present and has expected metrics (sync).
sdk/contentunderstanding/azure-ai-contentunderstanding/tests/samples/test_sample_analyze_invoice_async.py Adds sample test assertions validating .usage is present and has expected metrics (async).
sdk/contentunderstanding/azure-ai-contentunderstanding/samples/README.md Notes usage access as part of the invoice sample coverage.
sdk/contentunderstanding/azure-ai-contentunderstanding/azure/ai/contentunderstanding/_version.py Bumps package version to 1.0.2.
sdk/contentunderstanding/azure-ai-contentunderstanding/README.md Updates SDK↔service API version mapping table with 1.0.2.
sdk/contentunderstanding/azure-ai-contentunderstanding/CHANGELOG.md Adds 1.0.2 changelog entry describing the fix.

@github-actions

github-actions Bot commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

API Change Check

APIView identified API level changes in this PR and created the following API reviews

azure-ai-contentunderstanding

@chienyuanchang chienyuanchang enabled auto-merge (squash) April 14, 2026 18:21
@chienyuanchang chienyuanchang merged commit 56d4334 into main Apr 20, 2026
20 checks passed
@chienyuanchang chienyuanchang deleted the cu-sdk/add_usage branch April 20, 2026 11:44
fafhrd91 pushed a commit to fafhrd91/azure-sdk-for-python that referenced this pull request Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python SDK (azure-ai-contentunderstanding 1.0.1) does not expose usage field returned by REST API

3 participants