Skip to content

get_metric_usage

get_metric_usage(
    app_id: AppId,
    user_id: UserId,
    started_at: Timestamp,
    ended_at: Timestamp,
    scope: RequestScope,
    *,
    config_overrides: Optional[AppMonetizationClientConfig] = None,
    max_results: Optional[GetMetricUsageMaxResults] = None,
    next_token: Optional[NextToken] = None,
) -> GetMetricUsageResponse

Returns a user's raw per-metric usage over a caller-supplied window. Usage is aggregated by event time with each metric's aggregation function: summed or counted, or the largest value for a MAX metric, in the environment the scope selects (the live app or its sandbox). It returns usage only: it does not resolve the user's plan, apply quota, or attribute usage to a plan. Combine it with GetSubscriptionHistory to compute charges for each plan the user was on, or compare it against a plan's allowance to make an entitlement decision. Usage is read at hour resolution: startedAt is floored to its hour and endedAt is rounded up to the next hour boundary, so the window read can be wider than the requested one. Paginated over the app's metric set: one page of per-metric usage per call, continued with nextToken. The window is fixed across a pagination sequence.

Parameters:

  • app_id (AppId) –

    The ID of the app.

  • user_id (UserId) –

    The end user whose usage is read. Do not include personally identifiable or otherwise sensitive data in this value.

  • started_at (Timestamp) –

    Inclusive start of the reporting window (half-open [startedAt, endedAt)).

  • ended_at (Timestamp) –

    Exclusive end of the reporting window. Must be after startedAt; the window may span at most 744 hours (31 days, the longest monthly billing period). Must not be in the future beyond a small clock-skew allowance.

  • scope (RequestScope) –

    Required. The environment: live or sandbox. sandbox reads the app's isolated test environment. Usage is kept separately per environment.

  • max_results (Optional[GetMetricUsageMaxResults], default: None ) –

    Maximum number of per-metric usage entries to return in this page (1-25, default 25).

  • next_token (Optional[NextToken], default: None ) –

    Opaque continuation token from a prior response. The window (startedAt/endedAt) must be unchanged across a pagination sequence.

Raises:

Source code in docs_src/capo_appmonetization/_services/app_monetization.py
def get_metric_usage(
    self,
    app_id: "capo_appmonetization.types.app_id.AppId",
    user_id: "capo_appmonetization.types.user_id.UserId",
    started_at: "capo_appmonetization.types.timestamp.Timestamp",
    ended_at: "capo_appmonetization.types.timestamp.Timestamp",
    scope: "capo_appmonetization.types.request_scope.RequestScope",
    *,
    config_overrides: Optional[AppMonetizationClientConfig] = None,
    max_results: Optional[
        "capo_appmonetization.types.get_metric_usage_max_results.GetMetricUsageMaxResults"
    ] = None,
    next_token: Optional["capo_appmonetization.types.next_token.NextToken"] = None,
) -> "capo_appmonetization.types.get_metric_usage_response.GetMetricUsageResponse":
    """Returns a user's raw per-metric usage over a caller-supplied window. Usage is aggregated by event time with each metric's aggregation function: summed or counted, or the largest value for a MAX metric, in the environment the scope selects (the live app or its sandbox). It returns usage only: it does not resolve the user's plan, apply quota, or attribute usage to a plan. Combine it with GetSubscriptionHistory to compute charges for each plan the user was on, or compare it against a plan's allowance to make an entitlement decision. Usage is read at hour resolution: startedAt is floored to its hour and endedAt is rounded up to the next hour boundary, so the window read can be wider than the requested one. Paginated over the app's metric set: one page of per-metric usage per call, continued with nextToken. The window is fixed across a pagination sequence.

    Args:
        app_id: The ID of the app.
        user_id: The end user whose usage is read. Do not include personally identifiable or otherwise sensitive data in this value.
        started_at: Inclusive start of the reporting window (half-open [startedAt, endedAt)).
        ended_at: Exclusive end of the reporting window. Must be after startedAt; the window may span at most 744 hours (31 days, the longest monthly billing period). Must not be in the future beyond a small clock-skew allowance.
        scope: Required. The environment: live or sandbox. sandbox reads the app's isolated test environment. Usage is kept separately per environment.
        max_results: Maximum number of per-metric usage entries to return in this page (1-25, default 25).
        next_token: Opaque continuation token from a prior response. The window (startedAt/endedAt) must be unchanged across a pagination sequence.

    Raises:
        capo_appmonetization.errors.access_denied_exception.AccessDeniedException: The caller does not have sufficient permission to perform this action.
        capo_appmonetization.errors.internal_server_exception.InternalServerException: An unexpected error occurred while processing the request.
        capo_appmonetization.errors.resource_not_found_exception.ResourceNotFoundException: The referenced resource does not exist.
        capo_appmonetization.errors.throttling_exception.ThrottlingException: The request was denied due to request throttling.
        capo_appmonetization.errors.validation_exception.ValidationException: The request failed input validation.
        capo_appmonetization.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_appmonetization.types.get_metric_usage_request.GetMetricUsageRequest]",
    ) -> OperationResponse[
        "capo_appmonetization.types.get_metric_usage_response.GetMetricUsageResponse"
    ]:
        import capo_appmonetization._operations.aws_monetization_ai_front_end.get_metric_usage

        output, http_response = (
            capo_appmonetization._operations.aws_monetization_ai_front_end.get_metric_usage.get_metric_usage(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("GetMetricUsage")
    )
    input_: capo_appmonetization.types.get_metric_usage_request.GetMetricUsageRequest = {
        "app_id": app_id,
        "user_id": user_id,
        "started_at": started_at,
        "ended_at": ended_at,
        "scope": scope,
    }
    if max_results is not None:
        input_["max_results"] = max_results
    if next_token is not None:
        input_["next_token"] = next_token

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output