# 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, NoneType, 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 SyncCursorIDPage, AsyncCursorIDPage from ..._base_client import AsyncPaginator, make_request_options from ...types.agents import call_list_params from ...types.agents.agent_call import AgentCall __all__ = ["CallsResource", "AsyncCallsResource"] class CallsResource(SyncAPIResource): @cached_property def with_raw_response(self) -> CallsResourceWithRawResponse: """ 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/cartesia-ai/cartesia-python#accessing-raw-response-data-eg-headers """ return CallsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> CallsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/cartesia-ai/cartesia-python#with_streaming_response """ return CallsResourceWithStreamingResponse(self) def retrieve( self, call_id: str, *, # 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, ) -> AgentCall: """ Get Call Args: 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 call_id: raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}") return self._get( path_template("/agents/calls/{call_id}", call_id=call_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentCall, ) def list( self, *, agent_id: str, ending_before: Optional[str] | Omit = omit, expand: Optional[str] | Omit = omit, limit: Optional[int] | Omit = omit, starting_after: Optional[str] | 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, ) -> SyncCursorIDPage[AgentCall]: """ Lists calls sorted by start time in descending order for a specific agent. `agent_id` is required and if you want to include `transcript` in the response, add `expand=transcript` to the request. This endpoint is paginated. Args: agent_id: The ID of the agent. ending_before: (Pagination option) The ID of the call to end before. expand: The fields to expand in the response. Currently, the only supported value is `transcript`. limit: (Pagination option) The number of calls to return per page, ranging between 1 and 100. starting_after: (Pagination option)The ID of the call to start after. 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( "/agents/calls", page=SyncCursorIDPage[AgentCall], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "agent_id": agent_id, "ending_before": ending_before, "expand": expand, "limit": limit, "starting_after": starting_after, }, call_list_params.CallListParams, ), ), model=AgentCall, ) def download_audio( self, call_id: str, *, # 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, ) -> None: """The downloaded audio file is in .wav format. This endpoint streams the audio file content (WAV format) to the client. Args: 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 call_id: raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._get( path_template("/agents/calls/{call_id}/audio", call_id=call_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) class AsyncCallsResource(AsyncAPIResource): @cached_property def with_raw_response(self) -> AsyncCallsResourceWithRawResponse: """ 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/cartesia-ai/cartesia-python#accessing-raw-response-data-eg-headers """ return AsyncCallsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncCallsResourceWithStreamingResponse: """ An alternative to `.with_raw_response` that doesn't eagerly read the response body. For more information, see https://www.github.com/cartesia-ai/cartesia-python#with_streaming_response """ return AsyncCallsResourceWithStreamingResponse(self) async def retrieve( self, call_id: str, *, # 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, ) -> AgentCall: """ Get Call Args: 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 call_id: raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}") return await self._get( path_template("/agents/calls/{call_id}", call_id=call_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentCall, ) def list( self, *, agent_id: str, ending_before: Optional[str] | Omit = omit, expand: Optional[str] | Omit = omit, limit: Optional[int] | Omit = omit, starting_after: Optional[str] | 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[AgentCall, AsyncCursorIDPage[AgentCall]]: """ Lists calls sorted by start time in descending order for a specific agent. `agent_id` is required and if you want to include `transcript` in the response, add `expand=transcript` to the request. This endpoint is paginated. Args: agent_id: The ID of the agent. ending_before: (Pagination option) The ID of the call to end before. expand: The fields to expand in the response. Currently, the only supported value is `transcript`. limit: (Pagination option) The number of calls to return per page, ranging between 1 and 100. starting_after: (Pagination option)The ID of the call to start after. 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( "/agents/calls", page=AsyncCursorIDPage[AgentCall], options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout, query=maybe_transform( { "agent_id": agent_id, "ending_before": ending_before, "expand": expand, "limit": limit, "starting_after": starting_after, }, call_list_params.CallListParams, ), ), model=AgentCall, ) async def download_audio( self, call_id: str, *, # 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, ) -> None: """The downloaded audio file is in .wav format. This endpoint streams the audio file content (WAV format) to the client. Args: 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 call_id: raise ValueError(f"Expected a non-empty value for `call_id` but received {call_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._get( path_template("/agents/calls/{call_id}/audio", call_id=call_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) class CallsResourceWithRawResponse: def __init__(self, calls: CallsResource) -> None: self._calls = calls self.retrieve = to_raw_response_wrapper( calls.retrieve, ) self.list = to_raw_response_wrapper( calls.list, ) self.download_audio = to_raw_response_wrapper( calls.download_audio, ) class AsyncCallsResourceWithRawResponse: def __init__(self, calls: AsyncCallsResource) -> None: self._calls = calls self.retrieve = async_to_raw_response_wrapper( calls.retrieve, ) self.list = async_to_raw_response_wrapper( calls.list, ) self.download_audio = async_to_raw_response_wrapper( calls.download_audio, ) class CallsResourceWithStreamingResponse: def __init__(self, calls: CallsResource) -> None: self._calls = calls self.retrieve = to_streamed_response_wrapper( calls.retrieve, ) self.list = to_streamed_response_wrapper( calls.list, ) self.download_audio = to_streamed_response_wrapper( calls.download_audio, ) class AsyncCallsResourceWithStreamingResponse: def __init__(self, calls: AsyncCallsResource) -> None: self._calls = calls self.retrieve = async_to_streamed_response_wrapper( calls.retrieve, ) self.list = async_to_streamed_response_wrapper( calls.list, ) self.download_audio = async_to_streamed_response_wrapper( calls.download_audio, )