"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from .basesdk import BaseSDK
from flexprice_py import errors, models, utils
from flexprice_py._hooks import HookContext
from flexprice_py.types import OptionalNullable, UNSET
from flexprice_py.utils.unmarshal_json_response import unmarshal_json_response
from typing import Any, Dict, List, Mapping, Optional, Union


class Events(BaseSDK):
    def ingest_event(
        self,
        *,
        event_name: str,
        external_customer_id: str,
        customer_id: Optional[str] = None,
        event_id: Optional[str] = None,
        properties: Optional[Dict[str, str]] = None,
        source: Optional[str] = None,
        timestamp: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Dict[str, str]:
        r"""Ingest event

        Use when sending a single usage event from your app (e.g. one API call or one GB stored). Events are processed asynchronously; returns 202 with event_id.

        :param event_name:
        :param external_customer_id:
        :param customer_id:
        :param event_id:
        :param properties: Handled separately for dynamic columns
        :param source:
        :param timestamp: Handled separately due to parsing
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoIngestEventRequest(
            customer_id=customer_id,
            event_id=event_id,
            event_name=event_name,
            external_customer_id=external_customer_id,
            properties=properties,
            source=source,
            timestamp=timestamp,
        )

        req = self._build_request(
            method="POST",
            path="/events",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.components.DtoIngestEventRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="ingestEvent",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "application/json"):
            return unmarshal_json_response(Dict[str, str], http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    async def ingest_event_async(
        self,
        *,
        event_name: str,
        external_customer_id: str,
        customer_id: Optional[str] = None,
        event_id: Optional[str] = None,
        properties: Optional[Dict[str, str]] = None,
        source: Optional[str] = None,
        timestamp: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Dict[str, str]:
        r"""Ingest event

        Use when sending a single usage event from your app (e.g. one API call or one GB stored). Events are processed asynchronously; returns 202 with event_id.

        :param event_name:
        :param external_customer_id:
        :param customer_id:
        :param event_id:
        :param properties: Handled separately for dynamic columns
        :param source:
        :param timestamp: Handled separately due to parsing
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoIngestEventRequest(
            customer_id=customer_id,
            event_id=event_id,
            event_name=event_name,
            external_customer_id=external_customer_id,
            properties=properties,
            source=source,
            timestamp=timestamp,
        )

        req = self._build_request_async(
            method="POST",
            path="/events",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.components.DtoIngestEventRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="ingestEvent",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "application/json"):
            return unmarshal_json_response(Dict[str, str], http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    def get_usage_analytics(
        self,
        *,
        external_customer_id: str,
        end_time: Optional[str] = None,
        expand: Optional[List[str]] = None,
        feature_ids: Optional[List[str]] = None,
        group_by: Optional[List[str]] = None,
        property_filters: Optional[Dict[str, List[str]]] = None,
        sources: Optional[List[str]] = None,
        start_time: Optional[str] = None,
        window_size: Optional[models.components.WindowSize] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetUsageAnalyticsResponse:
        r"""Get usage analytics

        Use when building analytics views (e.g. usage by feature or customer over time). Supports filtering, grouping, and time-series breakdown.

        :param external_customer_id:
        :param end_time:
        :param expand: allowed values: \"price\", \"meter\", \"feature\", \"subscription_line_item\",\"plan\",\"addon\"
        :param feature_ids:
        :param group_by: allowed values: \"source\", \"feature_id\", \"properties.<field_name>\"
        :param property_filters: Property filters to filter the events by the keys in `properties` field of the event
        :param sources:
        :param start_time:
        :param window_size:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoGetUsageAnalyticsRequest(
            end_time=end_time,
            expand=expand,
            external_customer_id=external_customer_id,
            feature_ids=feature_ids,
            group_by=group_by,
            property_filters=property_filters,
            sources=sources,
            start_time=start_time,
            window_size=window_size,
        )

        req = self._build_request(
            method="POST",
            path="/events/analytics",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request,
                False,
                False,
                "json",
                models.components.DtoGetUsageAnalyticsRequest,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getUsageAnalytics",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetUsageAnalyticsResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    async def get_usage_analytics_async(
        self,
        *,
        external_customer_id: str,
        end_time: Optional[str] = None,
        expand: Optional[List[str]] = None,
        feature_ids: Optional[List[str]] = None,
        group_by: Optional[List[str]] = None,
        property_filters: Optional[Dict[str, List[str]]] = None,
        sources: Optional[List[str]] = None,
        start_time: Optional[str] = None,
        window_size: Optional[models.components.WindowSize] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetUsageAnalyticsResponse:
        r"""Get usage analytics

        Use when building analytics views (e.g. usage by feature or customer over time). Supports filtering, grouping, and time-series breakdown.

        :param external_customer_id:
        :param end_time:
        :param expand: allowed values: \"price\", \"meter\", \"feature\", \"subscription_line_item\",\"plan\",\"addon\"
        :param feature_ids:
        :param group_by: allowed values: \"source\", \"feature_id\", \"properties.<field_name>\"
        :param property_filters: Property filters to filter the events by the keys in `properties` field of the event
        :param sources:
        :param start_time:
        :param window_size:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoGetUsageAnalyticsRequest(
            end_time=end_time,
            expand=expand,
            external_customer_id=external_customer_id,
            feature_ids=feature_ids,
            group_by=group_by,
            property_filters=property_filters,
            sources=sources,
            start_time=start_time,
            window_size=window_size,
        )

        req = self._build_request_async(
            method="POST",
            path="/events/analytics",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request,
                False,
                False,
                "json",
                models.components.DtoGetUsageAnalyticsRequest,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getUsageAnalytics",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetUsageAnalyticsResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    def ingest_events_bulk(
        self,
        *,
        events: Union[
            List[models.components.DtoIngestEventRequest],
            List[models.components.DtoIngestEventRequestTypedDict],
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Dict[str, str]:
        r"""Bulk ingest events

        Use when batching usage events (e.g. backfill or high-volume ingestion). More efficient than single event calls; returns 202 when accepted.

        :param events:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoBulkIngestEventRequest(
            events=utils.get_pydantic_model(
                events, List[models.components.DtoIngestEventRequest]
            ),
        )

        req = self._build_request(
            method="POST",
            path="/events/bulk",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request,
                False,
                False,
                "json",
                models.components.DtoBulkIngestEventRequest,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="ingestEventsBulk",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "application/json"):
            return unmarshal_json_response(Dict[str, str], http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    async def ingest_events_bulk_async(
        self,
        *,
        events: Union[
            List[models.components.DtoIngestEventRequest],
            List[models.components.DtoIngestEventRequestTypedDict],
        ],
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> Dict[str, str]:
        r"""Bulk ingest events

        Use when batching usage events (e.g. backfill or high-volume ingestion). More efficient than single event calls; returns 202 when accepted.

        :param events:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoBulkIngestEventRequest(
            events=utils.get_pydantic_model(
                events, List[models.components.DtoIngestEventRequest]
            ),
        )

        req = self._build_request_async(
            method="POST",
            path="/events/bulk",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request,
                False,
                False,
                "json",
                models.components.DtoBulkIngestEventRequest,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="ingestEventsBulk",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "202", "application/json"):
            return unmarshal_json_response(Dict[str, str], http_res)
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    def get_huggingface_inference_data(
        self,
        *,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetHuggingFaceBillingDataResponse:
        r"""Get Hugging Face inference data

        Use when fetching Hugging Face inference usage or billing data (e.g. for HF-specific reporting or reconciliation).

        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)
        req = self._build_request(
            method="POST",
            path="/events/huggingface-inference",
            base_url=base_url,
            url_variables=url_variables,
            request=None,
            request_body_required=False,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getHuggingfaceInferenceData",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetHuggingFaceBillingDataResponse, http_res
            )
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    async def get_huggingface_inference_data_async(
        self,
        *,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetHuggingFaceBillingDataResponse:
        r"""Get Hugging Face inference data

        Use when fetching Hugging Face inference usage or billing data (e.g. for HF-specific reporting or reconciliation).

        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)
        req = self._build_request_async(
            method="POST",
            path="/events/huggingface-inference",
            base_url=base_url,
            url_variables=url_variables,
            request=None,
            request_body_required=False,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getHuggingfaceInferenceData",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetHuggingFaceBillingDataResponse, http_res
            )
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    def list_raw_events(
        self,
        *,
        end_time: Optional[str] = None,
        event_id: Optional[str] = None,
        event_name: Optional[str] = None,
        external_customer_id: Optional[str] = None,
        iter_first_key: Optional[str] = None,
        iter_last_key: Optional[str] = None,
        offset: Optional[int] = None,
        order: Optional[str] = None,
        page_size: Optional[int] = None,
        property_filters: Optional[Dict[str, List[str]]] = None,
        sort: Optional[str] = None,
        source: Optional[str] = None,
        start_time: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetEventsResponse:
        r"""List raw events

        Use when debugging ingestion or exporting raw event data (e.g. support or audit). Returns a paginated list; supports time range and sorting.

        :param end_time: End time of the events to be fetched in ISO 8601 format
            Defaults to now if not provided
        :param event_id: Event ID is the idempotency key for the event
        :param event_name: Event name / Unique identifier for the event in your system
        :param external_customer_id: Customer ID in your system that was sent with the event
        :param iter_first_key: First key to iterate over the events
        :param iter_last_key: Last key to iterate over the events
        :param offset: Offset to fetch the events and is set to 0 by default
        :param order: Order by condition. Allowed values (case sensitive): asc, desc (default: desc)
        :param page_size: Page size to fetch the events and is set to 50 by default
        :param property_filters: Property filters to filter the events by the keys in `properties` field of the event
        :param sort: Sort by the field. Allowed values (case sensitive): timestamp, event_name (default: timestamp)
        :param source: Source to filter the events by the source
        :param start_time: Start time of the events to be fetched in ISO 8601 format
            Defaults to last 7 days from now if not provided
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoGetEventsRequest(
            end_time=end_time,
            event_id=event_id,
            event_name=event_name,
            external_customer_id=external_customer_id,
            iter_first_key=iter_first_key,
            iter_last_key=iter_last_key,
            offset=offset,
            order=order,
            page_size=page_size,
            property_filters=property_filters,
            sort=sort,
            source=source,
            start_time=start_time,
        )

        req = self._build_request(
            method="POST",
            path="/events/query",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.components.DtoGetEventsRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="listRawEvents",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetEventsResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    async def list_raw_events_async(
        self,
        *,
        end_time: Optional[str] = None,
        event_id: Optional[str] = None,
        event_name: Optional[str] = None,
        external_customer_id: Optional[str] = None,
        iter_first_key: Optional[str] = None,
        iter_last_key: Optional[str] = None,
        offset: Optional[int] = None,
        order: Optional[str] = None,
        page_size: Optional[int] = None,
        property_filters: Optional[Dict[str, List[str]]] = None,
        sort: Optional[str] = None,
        source: Optional[str] = None,
        start_time: Optional[str] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetEventsResponse:
        r"""List raw events

        Use when debugging ingestion or exporting raw event data (e.g. support or audit). Returns a paginated list; supports time range and sorting.

        :param end_time: End time of the events to be fetched in ISO 8601 format
            Defaults to now if not provided
        :param event_id: Event ID is the idempotency key for the event
        :param event_name: Event name / Unique identifier for the event in your system
        :param external_customer_id: Customer ID in your system that was sent with the event
        :param iter_first_key: First key to iterate over the events
        :param iter_last_key: Last key to iterate over the events
        :param offset: Offset to fetch the events and is set to 0 by default
        :param order: Order by condition. Allowed values (case sensitive): asc, desc (default: desc)
        :param page_size: Page size to fetch the events and is set to 50 by default
        :param property_filters: Property filters to filter the events by the keys in `properties` field of the event
        :param sort: Sort by the field. Allowed values (case sensitive): timestamp, event_name (default: timestamp)
        :param source: Source to filter the events by the source
        :param start_time: Start time of the events to be fetched in ISO 8601 format
            Defaults to last 7 days from now if not provided
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoGetEventsRequest(
            end_time=end_time,
            event_id=event_id,
            event_name=event_name,
            external_customer_id=external_customer_id,
            iter_first_key=iter_first_key,
            iter_last_key=iter_last_key,
            offset=offset,
            order=order,
            page_size=page_size,
            property_filters=property_filters,
            sort=sort,
            source=source,
            start_time=start_time,
        )

        req = self._build_request_async(
            method="POST",
            path="/events/query",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.components.DtoGetEventsRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="listRawEvents",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetEventsResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    def get_usage_statistics(
        self,
        *,
        aggregation_type: models.components.AggregationType,
        event_name: str,
        billing_anchor: Optional[str] = None,
        bucket_size: Optional[models.components.WindowSize] = None,
        customer_id: Optional[str] = None,
        end_time: Optional[str] = None,
        external_customer_id: Optional[str] = None,
        filters: Optional[Dict[str, List[str]]] = None,
        group_by_property: Optional[str] = None,
        multiplier: Optional[str] = None,
        property_name: Optional[str] = None,
        start_time: Optional[str] = None,
        window_size: Optional[models.components.WindowSize] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetUsageResponse:
        r"""Get usage statistics

        Use when building usage reports or dashboards across events. Supports filters and grouping; defaults to last 7 days if no range provided.

        :param aggregation_type:
        :param event_name:
        :param billing_anchor: BillingAnchor enables custom monthly billing periods for usage aggregation.

            When to use:
            - WindowSize = \"MONTH\" AND you need custom monthly periods (not calendar months)
            - Subscription billing that doesn't align with calendar months
            - Example: Customer signed up on 15th, so billing periods are 15th to 15th

            When NOT to use:
            - WindowSize != \"MONTH\" (ignored for DAY, HOUR, WEEK, etc.)
            - Standard calendar-based billing (1st to 1st of each month)

            Example values:
            - \"2024-03-05T14:30:45.123456789Z\" (5th of each month at 2:30:45 PM)
            - \"2024-01-15T00:00:00Z\" (15th of each month at midnight)
            - \"2024-02-29T12:00:00Z\" (29th of each month at noon - handles leap years)
        :param bucket_size:
        :param customer_id:
        :param end_time:
        :param external_customer_id:
        :param filters:
        :param group_by_property: GroupByProperty is the property name in event.properties to group by before aggregating.
            When set, aggregation is applied per unique value of this property within each bucket,
            then the per-group results are summed to produce the bucket total.
        :param multiplier:
        :param property_name: will be empty/ignored in case of COUNT
        :param start_time:
        :param window_size:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoGetUsageRequest(
            aggregation_type=aggregation_type,
            billing_anchor=billing_anchor,
            bucket_size=bucket_size,
            customer_id=customer_id,
            end_time=end_time,
            event_name=event_name,
            external_customer_id=external_customer_id,
            filters=filters,
            group_by_property=group_by_property,
            multiplier=multiplier,
            property_name=property_name,
            start_time=start_time,
            window_size=window_size,
        )

        req = self._build_request(
            method="POST",
            path="/events/usage",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.components.DtoGetUsageRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getUsageStatistics",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetUsageResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    async def get_usage_statistics_async(
        self,
        *,
        aggregation_type: models.components.AggregationType,
        event_name: str,
        billing_anchor: Optional[str] = None,
        bucket_size: Optional[models.components.WindowSize] = None,
        customer_id: Optional[str] = None,
        end_time: Optional[str] = None,
        external_customer_id: Optional[str] = None,
        filters: Optional[Dict[str, List[str]]] = None,
        group_by_property: Optional[str] = None,
        multiplier: Optional[str] = None,
        property_name: Optional[str] = None,
        start_time: Optional[str] = None,
        window_size: Optional[models.components.WindowSize] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetUsageResponse:
        r"""Get usage statistics

        Use when building usage reports or dashboards across events. Supports filters and grouping; defaults to last 7 days if no range provided.

        :param aggregation_type:
        :param event_name:
        :param billing_anchor: BillingAnchor enables custom monthly billing periods for usage aggregation.

            When to use:
            - WindowSize = \"MONTH\" AND you need custom monthly periods (not calendar months)
            - Subscription billing that doesn't align with calendar months
            - Example: Customer signed up on 15th, so billing periods are 15th to 15th

            When NOT to use:
            - WindowSize != \"MONTH\" (ignored for DAY, HOUR, WEEK, etc.)
            - Standard calendar-based billing (1st to 1st of each month)

            Example values:
            - \"2024-03-05T14:30:45.123456789Z\" (5th of each month at 2:30:45 PM)
            - \"2024-01-15T00:00:00Z\" (15th of each month at midnight)
            - \"2024-02-29T12:00:00Z\" (29th of each month at noon - handles leap years)
        :param bucket_size:
        :param customer_id:
        :param end_time:
        :param external_customer_id:
        :param filters:
        :param group_by_property: GroupByProperty is the property name in event.properties to group by before aggregating.
            When set, aggregation is applied per unique value of this property within each bucket,
            then the per-group results are summed to produce the bucket total.
        :param multiplier:
        :param property_name: will be empty/ignored in case of COUNT
        :param start_time:
        :param window_size:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoGetUsageRequest(
            aggregation_type=aggregation_type,
            billing_anchor=billing_anchor,
            bucket_size=bucket_size,
            customer_id=customer_id,
            end_time=end_time,
            event_name=event_name,
            external_customer_id=external_customer_id,
            filters=filters,
            group_by_property=group_by_property,
            multiplier=multiplier,
            property_name=property_name,
            start_time=start_time,
            window_size=window_size,
        )

        req = self._build_request_async(
            method="POST",
            path="/events/usage",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request, False, False, "json", models.components.DtoGetUsageRequest
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getUsageStatistics",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetUsageResponse, http_res
            )
        if utils.match_response(http_res, "400", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    def get_usage_by_meter(
        self,
        *,
        meter_id: str,
        billing_anchor: Optional[str] = None,
        bucket_size: Optional[models.components.WindowSize] = None,
        customer_id: Optional[str] = None,
        end_time: Optional[str] = None,
        external_customer_id: Optional[str] = None,
        filters: Optional[Dict[str, List[str]]] = None,
        start_time: Optional[str] = None,
        window_size: Optional[models.components.WindowSize] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetUsageResponse:
        r"""Get usage by meter

        Use when showing usage for a specific meter (e.g. dashboard or overage check). Supports time range, filters, and grouping by customer or subscription.

        :param meter_id:
        :param billing_anchor: BillingAnchor enables custom monthly billing periods for meter usage aggregation.

            Usage guidelines:
            - Only effective when WindowSize = \"MONTH\"
            - For other window sizes (DAY, HOUR, WEEK), this field is ignored
            - When nil, uses standard calendar months (1st to 1st)
            - When provided, creates custom monthly periods (e.g., 5th to 5th)

            Common use cases:
            - Subscription billing periods that don't align with calendar months
            - Customer-specific billing cycles (e.g., signed up on 15th)
            - Multi-tenant systems with different billing anchor dates

            Example: If BillingAnchor = \"2024-03-05T14:30:45Z\" and WindowSize = \"MONTH\":
            - March period: 2024-03-05 14:30:45 to 2024-04-05 14:30:45
            - April period: 2024-04-05 14:30:45 to 2024-05-05 14:30:45
        :param bucket_size:
        :param customer_id:
        :param end_time:
        :param external_customer_id:
        :param filters:
        :param start_time:
        :param window_size:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoGetUsageByMeterRequest(
            billing_anchor=billing_anchor,
            bucket_size=bucket_size,
            customer_id=customer_id,
            end_time=end_time,
            external_customer_id=external_customer_id,
            filters=filters,
            meter_id=meter_id,
            start_time=start_time,
            window_size=window_size,
        )

        req = self._build_request(
            method="POST",
            path="/events/usage/meter",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request,
                False,
                False,
                "json",
                models.components.DtoGetUsageByMeterRequest,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getUsageByMeter",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "404", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetUsageResponse, http_res
            )
        if utils.match_response(http_res, ["400", "404"], "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    async def get_usage_by_meter_async(
        self,
        *,
        meter_id: str,
        billing_anchor: Optional[str] = None,
        bucket_size: Optional[models.components.WindowSize] = None,
        customer_id: Optional[str] = None,
        end_time: Optional[str] = None,
        external_customer_id: Optional[str] = None,
        filters: Optional[Dict[str, List[str]]] = None,
        start_time: Optional[str] = None,
        window_size: Optional[models.components.WindowSize] = None,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetUsageResponse:
        r"""Get usage by meter

        Use when showing usage for a specific meter (e.g. dashboard or overage check). Supports time range, filters, and grouping by customer or subscription.

        :param meter_id:
        :param billing_anchor: BillingAnchor enables custom monthly billing periods for meter usage aggregation.

            Usage guidelines:
            - Only effective when WindowSize = \"MONTH\"
            - For other window sizes (DAY, HOUR, WEEK), this field is ignored
            - When nil, uses standard calendar months (1st to 1st)
            - When provided, creates custom monthly periods (e.g., 5th to 5th)

            Common use cases:
            - Subscription billing periods that don't align with calendar months
            - Customer-specific billing cycles (e.g., signed up on 15th)
            - Multi-tenant systems with different billing anchor dates

            Example: If BillingAnchor = \"2024-03-05T14:30:45Z\" and WindowSize = \"MONTH\":
            - March period: 2024-03-05 14:30:45 to 2024-04-05 14:30:45
            - April period: 2024-04-05 14:30:45 to 2024-05-05 14:30:45
        :param bucket_size:
        :param customer_id:
        :param end_time:
        :param external_customer_id:
        :param filters:
        :param start_time:
        :param window_size:
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.components.DtoGetUsageByMeterRequest(
            billing_anchor=billing_anchor,
            bucket_size=bucket_size,
            customer_id=customer_id,
            end_time=end_time,
            external_customer_id=external_customer_id,
            filters=filters,
            meter_id=meter_id,
            start_time=start_time,
            window_size=window_size,
        )

        req = self._build_request_async(
            method="POST",
            path="/events/usage/meter",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=True,
            request_has_path_params=False,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            get_serialized_body=lambda: utils.serialize_request_body(
                request,
                False,
                False,
                "json",
                models.components.DtoGetUsageByMeterRequest,
            ),
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getUsageByMeter",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["400", "404", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetUsageResponse, http_res
            )
        if utils.match_response(http_res, ["400", "404"], "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    def get_event(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetEventByIDResponse:
        r"""Get event

        Use when debugging a specific event (e.g. why it failed or how it was aggregated). Includes processing status and debug info.

        :param id: Event ID
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.operations.GetEventRequest(
            id=id,
        )

        req = self._build_request(
            method="GET",
            path="/events/{id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = self.do_request(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getEvent",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["404", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetEventByIDResponse, http_res
            )
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = utils.stream_to_text(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)

    async def get_event_async(
        self,
        *,
        id: str,
        retries: OptionalNullable[utils.RetryConfig] = UNSET,
        server_url: Optional[str] = None,
        timeout_ms: Optional[int] = None,
        http_headers: Optional[Mapping[str, str]] = None,
    ) -> models.components.DtoGetEventByIDResponse:
        r"""Get event

        Use when debugging a specific event (e.g. why it failed or how it was aggregated). Includes processing status and debug info.

        :param id: Event ID
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        """
        base_url = None
        url_variables = None
        if timeout_ms is None:
            timeout_ms = self.sdk_configuration.timeout_ms

        if server_url is not None:
            base_url = server_url
        else:
            base_url = self._get_url(base_url, url_variables)

        request = models.operations.GetEventRequest(
            id=id,
        )

        req = self._build_request_async(
            method="GET",
            path="/events/{id}",
            base_url=base_url,
            url_variables=url_variables,
            request=request,
            request_body_required=False,
            request_has_path_params=True,
            request_has_query_params=True,
            user_agent_header="user-agent",
            accept_header_value="application/json",
            http_headers=http_headers,
            security=self.sdk_configuration.security,
            allow_empty_value=None,
            timeout_ms=timeout_ms,
        )

        if retries == UNSET:
            if self.sdk_configuration.retry_config is not UNSET:
                retries = self.sdk_configuration.retry_config

        retry_config = None
        if isinstance(retries, utils.RetryConfig):
            retry_config = (retries, ["429", "500", "502", "503", "504"])

        http_res = await self.do_request_async(
            hook_ctx=HookContext(
                config=self.sdk_configuration,
                base_url=base_url or "",
                operation_id="getEvent",
                oauth2_scopes=None,
                security_source=self.sdk_configuration.security,
            ),
            request=req,
            error_status_codes=["404", "4XX", "500", "5XX"],
            retry_config=retry_config,
        )

        response_data: Any = None
        if utils.match_response(http_res, "200", "application/json"):
            return unmarshal_json_response(
                models.components.DtoGetEventByIDResponse, http_res
            )
        if utils.match_response(http_res, "404", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "500", "application/json"):
            response_data = unmarshal_json_response(
                errors.ErrorsErrorResponseData, http_res
            )
            raise errors.ErrorsErrorResponse(response_data, http_res)
        if utils.match_response(http_res, "4XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )
        if utils.match_response(http_res, "5XX", "*"):
            http_res_text = await utils.stream_to_text_async(http_res)
            raise errors.FlexpriceDefaultError(
                "API error occurred", http_res, http_res_text
            )

        raise errors.FlexpriceDefaultError("Unexpected response received", http_res)
