# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Optional import httpx from ..._types import Body, Omit, Query, Headers, NotGiven, omit, not_given from ..._utils import path_template, maybe_transform from ..._compat import cached_property from ..._resource import SyncAPIResource, AsyncAPIResource from ..._response import ( to_raw_response_wrapper, to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, ) from ...pagination import SyncDefaultFlatPagination, AsyncDefaultFlatPagination from ..._base_client import AsyncPaginator, make_request_options from ...types.pricing import product_list_params, product_retrieve_params from ...types.pricing.product_list_response import ProductListResponse from ...types.pricing.product_retrieve_response import ProductRetrieveResponse __all__ = ["ProductsResource", "AsyncProductsResource"] class ProductsResource(SyncAPIResource): """Public pricing operations""" @cached_property def with_raw_response(self) -> ProductsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return ProductsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> ProductsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return ProductsResourceWithStreamingResponse(self) def retrieve( self, slug: str, *, filter_country_iso: Optional[str] | Omit = omit, page_number: int | Omit = omit, page_size: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncDefaultFlatPagination[ProductRetrieveResponse]: """Returns pricing entries for a single product. Most products return standard rate entries with fields like rate, unit, country_iso, direction, and tiers. Inference products return model-specific fields (model, input_rate, output_rate, cached_input_rate) with tiered pricing. Some products use rate decks (pricing_type: rate_deck) where rates are determined dynamically. Args: filter_country_iso: Two-letter ISO 3166-1 alpha-2 country code (uppercase, e.g. US) to filter pricing to a single country. page_number: Page number (1-based). page_size: Number of items per page (max 100). extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not slug: raise ValueError(f"Expected a non-empty value for `slug` but received {slug!r}") return self._get_api_list( path_template("/pricing/products/{slug}", slug=slug), page=SyncDefaultFlatPagination[ProductRetrieveResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "filter_country_iso": filter_country_iso, "page_number": page_number, "page_size": page_size, }, product_retrieve_params.ProductRetrieveParams, ), ), model=ProductRetrieveResponse, ) def list( self, *, page_number: int | Omit = omit, page_size: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> SyncDefaultFlatPagination[ProductListResponse]: """Returns the full product catalog with pagination. Each entry contains a slug, display name, and description. Use the slug to fetch per-product pricing via GET /pricing/products/{slug}. Args: page_number: Page number (1-based). page_size: Number of items per page (max 100). extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._get_api_list( "/pricing/products", page=SyncDefaultFlatPagination[ProductListResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "page_number": page_number, "page_size": page_size, }, product_list_params.ProductListParams, ), ), model=ProductListResponse, ) class AsyncProductsResource(AsyncAPIResource): """Public pricing operations""" @cached_property def with_raw_response(self) -> AsyncProductsResourceWithRawResponse: """ This property can be used as a prefix for any HTTP method call to return the raw response object instead of the parsed content. For more information, see https://www.github.com/team-telnyx/telnyx-python#accessing-raw-response-data-eg-headers """ return AsyncProductsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncProductsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/team-telnyx/telnyx-python#with_streaming_response """ return AsyncProductsResourceWithStreamingResponse(self) def retrieve( self, slug: str, *, filter_country_iso: Optional[str] | Omit = omit, page_number: int | Omit = omit, page_size: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[ProductRetrieveResponse, AsyncDefaultFlatPagination[ProductRetrieveResponse]]: """Returns pricing entries for a single product. Most products return standard rate entries with fields like rate, unit, country_iso, direction, and tiers. Inference products return model-specific fields (model, input_rate, output_rate, cached_input_rate) with tiered pricing. Some products use rate decks (pricing_type: rate_deck) where rates are determined dynamically. Args: filter_country_iso: Two-letter ISO 3166-1 alpha-2 country code (uppercase, e.g. US) to filter pricing to a single country. page_number: Page number (1-based). page_size: Number of items per page (max 100). extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ if not slug: raise ValueError(f"Expected a non-empty value for `slug` but received {slug!r}") return self._get_api_list( path_template("/pricing/products/{slug}", slug=slug), page=AsyncDefaultFlatPagination[ProductRetrieveResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "filter_country_iso": filter_country_iso, "page_number": page_number, "page_size": page_size, }, product_retrieve_params.ProductRetrieveParams, ), ), model=ProductRetrieveResponse, ) def list( self, *, page_number: int | Omit = omit, page_size: int | Omit = omit, # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. # The extra values given here take precedence over values defined on the client or passed to this method. extra_headers: Headers | None = None, extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncPaginator[ProductListResponse, AsyncDefaultFlatPagination[ProductListResponse]]: """Returns the full product catalog with pagination. Each entry contains a slug, display name, and description. Use the slug to fetch per-product pricing via GET /pricing/products/{slug}. Args: page_number: Page number (1-based). page_size: Number of items per page (max 100). extra_headers: Send extra headers extra_query: Add additional query parameters to the request extra_body: Add additional JSON properties to the request timeout: Override the client-level default timeout for this request, in seconds """ return self._get_api_list( "/pricing/products", page=AsyncDefaultFlatPagination[ProductListResponse], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "page_number": page_number, "page_size": page_size, }, product_list_params.ProductListParams, ), ), model=ProductListResponse, ) class ProductsResourceWithRawResponse: def __init__(self, products: ProductsResource) -> None: self._products = products self.retrieve = to_raw_response_wrapper( products.retrieve, ) self.list = to_raw_response_wrapper( products.list, ) class AsyncProductsResourceWithRawResponse: def __init__(self, products: AsyncProductsResource) -> None: self._products = products self.retrieve = async_to_raw_response_wrapper( products.retrieve, ) self.list = async_to_raw_response_wrapper( products.list, ) class ProductsResourceWithStreamingResponse: def __init__(self, products: ProductsResource) -> None: self._products = products self.retrieve = to_streamed_response_wrapper( products.retrieve, ) self.list = to_streamed_response_wrapper( products.list, ) class AsyncProductsResourceWithStreamingResponse: def __init__(self, products: AsyncProductsResource) -> None: self._products = products self.retrieve = async_to_streamed_response_wrapper( products.retrieve, ) self.list = async_to_streamed_response_wrapper( products.list, )