Skip to content

batch_meter_usage async

batch_meter_usage(
    usage_records: UsageRecordList,
    *,
    config_overrides: Optional[AsyncMarketplaceMeteringClientConfig] = None,
    product_code: Optional[ProductCode] = None,
) -> BatchMeterUsageResult

The Amazon Web Services Marketplace AI Metering Agent Skill (aws-marketplace-metering) helps an AI coding agent integrate your SaaS product's usage reporting with the BatchMeterUsage API. The skill is a curated package of instructions and reference material that guides your AI coding agent through building, deploying, and testing the metering integration. To get the skill on demand without checking it out locally, install the Amazon Web Services MCP Server in your coding agent; the agent then discovers and loads the skill at runtime. The skill source is also available on GitHub. For more information, see Get started with the Amazon Web Services Marketplace AI Metering Agent Skill on the Amazon Web Services Marketplace blog.

Amazon Web Services Marketplace is introducing Concurrent Agreements, enabling buyers to make multiple purchases per Amazon Web Services account. Starting June 1, 2026, new SaaS products must use CustomerAWSAccountId (instead of CustomerIdentifier), LicenseArn (instead of ProductCode) to support this feature. BatchMeterUsage does not support CustomerIdentifier for new integrations. Existing integrations continue to work. Review the new integration for Concurrent Agreements here. For additional implementation details, see BatchMeterUsage code example with LicenseArn in the Amazon Web Services Marketplace Seller Guide.

To post metering records for customers, SaaS applications call BatchMeterUsage, which is used for metering SaaS flexible consumption pricing (FCP). Identical requests are idempotent and can be retried with the same records or a subset of records. Each BatchMeterUsage request is for only one product. If you want to meter usage for multiple products, you must make multiple BatchMeterUsage calls.

Usage records should be submitted in quick succession following a recorded event. Usage records aren't accepted 24 hours or more after an event. At the end of each billing cycle, a 6-hour grace period applies. We accept usage records for the previous billing month until 06:00 UTC on the first day of the next month. For example, you must submit March usage records before 06:00 UTC on April 1. On April 1 at 05:00 UTC, you can still submit records for March 31 (within the 6-hour grace period). After 06:00 UTC on April 1, March records are rejected regardless of the normal 24-hour submission window. After this grace period, we return a TimestampOutOfBoundsException error.

BatchMeterUsage can process up to 25 UsageRecords at a time, and each request must be less than 1 MB in size.

Vendor-metered tagging

BatchMeterUsage supports vendor-metered tagging. Optionally, you can split the usage in a UsageRecord into buckets by including UsageAllocations, where each UsageAllocation has a set of Tags that you define. Vendor-metered tagging doesn't change the price, dimensions, or the total usage that you report. It gives buyers a more granular view of their usage of your product so they can perform cost allocation in the Amazon Web Services Billing and Cost Management console. For more information, see Vendor-metered tagging and BatchMeterUsage with usage allocation tagging code example in the Amazon Web Services Marketplace Seller Guide.

BatchMeterUsage returns a list of UsageRecordResult objects, which have each UsageRecord. It also returns a list of UnprocessedRecords, which indicate errors on the service side that should be retried.

For Amazon Web Services Regions that support BatchMeterUsage, see BatchMeterUsage Region support.

For an example of BatchMeterUsage, see BatchMeterUsage code example in the Amazon Web Services Marketplace Seller Guide.

Parameters:

  • usage_records (UsageRecordList) –

    The set of UsageRecords to submit. BatchMeterUsage accepts up to 25 UsageRecords at a time.

  • product_code (Optional[ProductCode], default: None ) –

    Product code is used to uniquely identify a product in Amazon Web Services Marketplace. The product code should be the same as the one used during the publishing of a new product.

    ProductCode is required only for legacy integrations that use CustomerIdentifier. For new integrations using LicenseArn (Concurrent Agreements), do NOT include ProductCode at the request level. The LicenseArn in each UsageRecord identifies both the product and the specific agreement.

    Sending metering records with both ProductCode and LicenseArn for the same customer within the same hour will result in duplicate billing. If you are migrating from product-based metering to license-based metering, stop sending ProductCode before you start sending LicenseArn.

Raises:

Source code in docs_src/capo_marketplace_metering/_services/async_marketplace_metering.py
async def batch_meter_usage(
    self,
    usage_records: "capo_marketplace_metering.types.usage_record_list.UsageRecordList",
    *,
    config_overrides: Optional[AsyncMarketplaceMeteringClientConfig] = None,
    product_code: Optional[
        "capo_marketplace_metering.types.product_code.ProductCode"
    ] = None,
) -> (
    "capo_marketplace_metering.types.batch_meter_usage_result.BatchMeterUsageResult"
):
    """<note> <p>The Amazon Web Services Marketplace AI Metering Agent Skill (<code>aws-marketplace-metering</code>) helps an AI coding agent integrate your SaaS product's usage reporting with the <code>BatchMeterUsage</code> API. The skill is a curated package of instructions and reference material that guides your AI coding agent through building, deploying, and testing the metering integration. To get the skill on demand without checking it out locally, install the <a href="https://docs.aws.amazon.com/agent-toolkit/latest/userguide/mcp-server.html">Amazon Web Services MCP Server</a> in your coding agent; the agent then discovers and loads the skill at runtime. The skill source is also available on <a href="https://github.com/aws/agent-toolkit-for-aws/blob/main/skills/specialized-skills/aws-marketplace-skills/aws-marketplace-metering">GitHub</a>. For more information, see <a href="https://aws.amazon.com/blogs/awsmarketplace/build-aws-marketplace-saas-metering-with-the-metering-agent-skill/">Get started with the Amazon Web Services Marketplace AI Metering Agent Skill</a> on the Amazon Web Services Marketplace blog.</p> </note> <important> <p>Amazon Web Services Marketplace is introducing Concurrent Agreements, enabling buyers to make multiple purchases per Amazon Web Services account. Starting June 1, 2026, new SaaS products must use <code>CustomerAWSAccountId</code> (instead of <code>CustomerIdentifier</code>), <code>LicenseArn</code> (instead of <code>ProductCode</code>) to support this feature. <code>BatchMeterUsage</code> does not support <code>CustomerIdentifier</code> for new integrations. Existing integrations continue to work. Review the new integration for Concurrent Agreements <a href="https://catalog.workshops.aws/mpseller/en-US/saas/integration-for-concurrent-agreements">here</a>. For additional implementation details, see <a href="https://docs.aws.amazon.com/marketplace/latest/userguide/saas-code-examples.html#saas-batchmeterusage-licensearn-example">BatchMeterUsage code example with LicenseArn</a> in the <i>Amazon Web Services Marketplace Seller Guide</i>.</p> </important> <p>To post metering records for customers, SaaS applications call <code>BatchMeterUsage</code>, which is used for metering SaaS flexible consumption pricing (FCP). Identical requests are idempotent and can be retried with the same records or a subset of records. Each <code>BatchMeterUsage</code> request is for only one product. If you want to meter usage for multiple products, you must make multiple <code>BatchMeterUsage</code> calls.</p> <p>Usage records should be submitted in quick succession following a recorded event. Usage records aren't accepted 24 hours or more after an event. At the end of each billing cycle, a 6-hour grace period applies. We accept usage records for the previous billing month until 06:00 UTC on the first day of the next month. For example, you must submit March usage records before 06:00 UTC on April 1. On April 1 at 05:00 UTC, you can still submit records for March 31 (within the 6-hour grace period). After 06:00 UTC on April 1, March records are rejected regardless of the normal 24-hour submission window. After this grace period, we return a <code>TimestampOutOfBoundsException</code> error.</p> <p> <code>BatchMeterUsage</code> can process up to 25 <code>UsageRecords</code> at a time, and each request must be less than 1 MB in size.</p> <p> <b>Vendor-metered tagging</b> </p> <p> <code>BatchMeterUsage</code> supports vendor-metered tagging. Optionally, you can split the usage in a <code>UsageRecord</code> into buckets by including <code>UsageAllocations</code>, where each <code>UsageAllocation</code> has a set of <code>Tags</code> that you define. Vendor-metered tagging doesn't change the price, dimensions, or the total usage that you report. It gives buyers a more granular view of their usage of your product so they can perform cost allocation in the Amazon Web Services Billing and Cost Management console. For more information, see <a href="https://docs.aws.amazon.com/marketplace/latest/userguide/metering-for-usage.html#saas-vendor-metered-tagging">Vendor-metered tagging</a> and <a href="https://docs.aws.amazon.com/marketplace/latest/userguide/saas-code-examples.html#saas-batchmeterusage-tagging">BatchMeterUsage with usage allocation tagging code example</a> in the <i>Amazon Web Services Marketplace Seller Guide</i>.</p> <p> <code>BatchMeterUsage</code> returns a list of <code>UsageRecordResult</code> objects, which have each <code>UsageRecord</code>. It also returns a list of <code>UnprocessedRecords</code>, which indicate errors on the service side that should be retried.</p> <p>For Amazon Web Services Regions that support <code>BatchMeterUsage</code>, see <a href="https://docs.aws.amazon.com/marketplace/latest/APIReference/metering-regions.html#batchmeterusage-region-support">BatchMeterUsage Region support</a>. </p> <note> <p>For an example of <code>BatchMeterUsage</code>, see <a href="https://docs.aws.amazon.com/marketplace/latest/userguide/saas-code-examples.html#saas-batchmeterusage-example"> BatchMeterUsage code example</a> in the <i>Amazon Web Services Marketplace Seller Guide</i>.</p> </note>

    Args:
        usage_records: <p>The set of <code>UsageRecords</code> to submit. <code>BatchMeterUsage</code> accepts up to 25 <code>UsageRecords</code> at a time.</p>
        product_code: <p>Product code is used to uniquely identify a product in Amazon Web Services Marketplace. The product code should be the same as the one used during the publishing of a new product.</p> <important> <p> <code>ProductCode</code> is required only for legacy integrations that use <code>CustomerIdentifier</code>. For new integrations using <code>LicenseArn</code> (Concurrent Agreements), do NOT include <code>ProductCode</code> at the request level. The <code>LicenseArn</code> in each <code>UsageRecord</code> identifies both the product and the specific agreement.</p> <p>Sending metering records with both <code>ProductCode</code> and <code>LicenseArn</code> for the same customer within the same hour will result in duplicate billing. If you are migrating from product-based metering to license-based metering, stop sending <code>ProductCode</code> before you start sending <code>LicenseArn</code>.</p> </important>

    Raises:
        capo_marketplace_metering.errors.disabled_api_exception.DisabledApiException: <p>The API is disabled in the Region.</p>
        capo_marketplace_metering.errors.internal_service_error_exception.InternalServiceErrorException: <p>An internal error has occurred. Retry your request. If the problem persists, post a message with details on the Amazon Web Services forums.</p>
        capo_marketplace_metering.errors.invalid_customer_identifier_exception.InvalidCustomerIdentifierException: <p>You have metered usage for a <code>CustomerIdentifier</code> that does not exist.</p>
        capo_marketplace_metering.errors.invalid_license_exception.InvalidLicenseException: <p>Ensure the <code>LicenseArn</code> is valid, matches the customer, and usage is within the license activation period.</p>
        capo_marketplace_metering.errors.invalid_product_code_exception.InvalidProductCodeException: <p>The product code passed does not match the product code used for publishing the product.</p>
        capo_marketplace_metering.errors.invalid_tag_exception.InvalidTagException: <p>The tag is invalid, or the number of tags is greater than 5.</p>
        capo_marketplace_metering.errors.invalid_usage_allocations_exception.InvalidUsageAllocationsException: <p>Sum of allocated usage quantities is not equal to the usage quantity.</p>
        capo_marketplace_metering.errors.invalid_usage_dimension_exception.InvalidUsageDimensionException: <p>The usage dimension does not match one of the <code>UsageDimensions</code> associated with products.</p>
        capo_marketplace_metering.errors.throttling_exception.ThrottlingException: <p>The calls to the API are throttled.</p>
        capo_marketplace_metering.errors.timestamp_out_of_bounds_exception.TimestampOutOfBoundsException: <p>The <code>timestamp</code> value passed in the <code>UsageRecord</code> is out of allowed range.</p> <p>For <code>BatchMeterUsage</code>, if any of the records are outside of the allowed range, the entire batch is not processed. You must remove invalid records and try again.</p>
        capo_marketplace_metering.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_marketplace_metering.types.batch_meter_usage_request.BatchMeterUsageRequest]",
    ) -> AsyncOperationResponse[
        "capo_marketplace_metering.types.batch_meter_usage_result.BatchMeterUsageResult"
    ]:
        import capo_marketplace_metering._operations.awsmp_metering_service.batch_meter_usage

        (
            output,
            http_response,
        ) = await capo_marketplace_metering._operations.awsmp_metering_service.batch_meter_usage.async_batch_meter_usage(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("BatchMeterUsage")
    )
    input_: capo_marketplace_metering.types.batch_meter_usage_request.BatchMeterUsageRequest = {
        "usage_records": usage_records
    }
    if product_code is not None:
        input_["product_code"] = product_code

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output