# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. from __future__ import annotations from typing import Optional import httpx from .calls import ( CallsResource, AsyncCallsResource, CallsResourceWithRawResponse, AsyncCallsResourceWithRawResponse, CallsResourceWithStreamingResponse, AsyncCallsResourceWithStreamingResponse, ) from ...types import agent_update_params from ..._types import Body, Omit, Query, Headers, NoneType, NotGiven, omit, not_given from ..._utils import path_template, maybe_transform, async_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 .deployments import ( DeploymentsResource, AsyncDeploymentsResource, DeploymentsResourceWithRawResponse, AsyncDeploymentsResourceWithRawResponse, DeploymentsResourceWithStreamingResponse, AsyncDeploymentsResourceWithStreamingResponse, ) from ..._base_client import make_request_options from .metrics.metrics import ( MetricsResource, AsyncMetricsResource, MetricsResourceWithRawResponse, AsyncMetricsResourceWithRawResponse, MetricsResourceWithStreamingResponse, AsyncMetricsResourceWithStreamingResponse, ) from ...types.agent_summary import AgentSummary from ...types.agent_list_response import AgentListResponse from ...types.agent_list_templates_response import AgentListTemplatesResponse from ...types.agent_list_phone_numbers_response import AgentListPhoneNumbersResponse __all__ = ["AgentsResource", "AsyncAgentsResource"] class AgentsResource(SyncAPIResource): @cached_property def calls(self) -> CallsResource: return CallsResource(self._client) @cached_property def metrics(self) -> MetricsResource: return MetricsResource(self._client) @cached_property def deployments(self) -> DeploymentsResource: return DeploymentsResource(self._client) @cached_property def with_raw_response(self) -> AgentsResourceWithRawResponse: """ 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 AgentsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AgentsResourceWithStreamingResponse: """ 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 AgentsResourceWithStreamingResponse(self) def retrieve( self, agent_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, ) -> AgentSummary: """Returns the details of a specific agent. To create an agent, use the CLI or the Playground for the best experience and integration with Github. 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 agent_id: raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") return self._get( path_template("/agents/{agent_id}", agent_id=agent_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentSummary, ) def update( self, agent_id: str, *, description: Optional[str] | Omit = omit, name: Optional[str] | Omit = omit, tts_language: Optional[str] | Omit = omit, tts_voice: 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, ) -> AgentSummary: """ Update Agent Args: description: The description of the agent. name: The name of the agent. tts_language: The language to use for text-to-speech. tts_voice: The voice to use for text-to-speech. 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 agent_id: raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") return self._patch( path_template("/agents/{agent_id}", agent_id=agent_id), body=maybe_transform( { "description": description, "name": name, "tts_language": tts_language, "tts_voice": tts_voice, }, agent_update_params.AgentUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentSummary, ) def list( self, *, # 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, ) -> AgentListResponse: """Lists all agents associated with your account.""" return self._get( "/agents", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentListResponse, ) def delete( self, agent_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: """ Delete Agent 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 agent_id: raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return self._delete( path_template("/agents/{agent_id}", agent_id=agent_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) def list_phone_numbers( self, agent_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, ) -> AgentListPhoneNumbersResponse: """List the phone numbers associated with an agent. Currently, you can only have one phone number per agent and these are provisioned by Cartesia. 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 agent_id: raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") return self._get( path_template("/agents/{agent_id}/phone-numbers", agent_id=agent_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentListPhoneNumbersResponse, ) def list_templates( self, *, # 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, ) -> AgentListTemplatesResponse: """List of public, Cartesia-provided agent templates to help you get started.""" return self._get( "/agents/templates", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentListTemplatesResponse, ) class AsyncAgentsResource(AsyncAPIResource): @cached_property def calls(self) -> AsyncCallsResource: return AsyncCallsResource(self._client) @cached_property def metrics(self) -> AsyncMetricsResource: return AsyncMetricsResource(self._client) @cached_property def deployments(self) -> AsyncDeploymentsResource: return AsyncDeploymentsResource(self._client) @cached_property def with_raw_response(self) -> AsyncAgentsResourceWithRawResponse: """ 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 AsyncAgentsResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> AsyncAgentsResourceWithStreamingResponse: """ 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 AsyncAgentsResourceWithStreamingResponse(self) async def retrieve( self, agent_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, ) -> AgentSummary: """Returns the details of a specific agent. To create an agent, use the CLI or the Playground for the best experience and integration with Github. 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 agent_id: raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") return await self._get( path_template("/agents/{agent_id}", agent_id=agent_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentSummary, ) async def update( self, agent_id: str, *, description: Optional[str] | Omit = omit, name: Optional[str] | Omit = omit, tts_language: Optional[str] | Omit = omit, tts_voice: 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, ) -> AgentSummary: """ Update Agent Args: description: The description of the agent. name: The name of the agent. tts_language: The language to use for text-to-speech. tts_voice: The voice to use for text-to-speech. 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 agent_id: raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") return await self._patch( path_template("/agents/{agent_id}", agent_id=agent_id), body=await async_maybe_transform( { "description": description, "name": name, "tts_language": tts_language, "tts_voice": tts_voice, }, agent_update_params.AgentUpdateParams, ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentSummary, ) async def list( self, *, # 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, ) -> AgentListResponse: """Lists all agents associated with your account.""" return await self._get( "/agents", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentListResponse, ) async def delete( self, agent_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: """ Delete Agent 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 agent_id: raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") extra_headers = {"Accept": "*/*", **(extra_headers or {})} return await self._delete( path_template("/agents/{agent_id}", agent_id=agent_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=NoneType, ) async def list_phone_numbers( self, agent_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, ) -> AgentListPhoneNumbersResponse: """List the phone numbers associated with an agent. Currently, you can only have one phone number per agent and these are provisioned by Cartesia. 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 agent_id: raise ValueError(f"Expected a non-empty value for `agent_id` but received {agent_id!r}") return await self._get( path_template("/agents/{agent_id}/phone-numbers", agent_id=agent_id), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentListPhoneNumbersResponse, ) async def list_templates( self, *, # 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, ) -> AgentListTemplatesResponse: """List of public, Cartesia-provided agent templates to help you get started.""" return await self._get( "/agents/templates", options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout ), cast_to=AgentListTemplatesResponse, ) class AgentsResourceWithRawResponse: def __init__(self, agents: AgentsResource) -> None: self._agents = agents self.retrieve = to_raw_response_wrapper( agents.retrieve, ) self.update = to_raw_response_wrapper( agents.update, ) self.list = to_raw_response_wrapper( agents.list, ) self.delete = to_raw_response_wrapper( agents.delete, ) self.list_phone_numbers = to_raw_response_wrapper( agents.list_phone_numbers, ) self.list_templates = to_raw_response_wrapper( agents.list_templates, ) @cached_property def calls(self) -> CallsResourceWithRawResponse: return CallsResourceWithRawResponse(self._agents.calls) @cached_property def metrics(self) -> MetricsResourceWithRawResponse: return MetricsResourceWithRawResponse(self._agents.metrics) @cached_property def deployments(self) -> DeploymentsResourceWithRawResponse: return DeploymentsResourceWithRawResponse(self._agents.deployments) class AsyncAgentsResourceWithRawResponse: def __init__(self, agents: AsyncAgentsResource) -> None: self._agents = agents self.retrieve = async_to_raw_response_wrapper( agents.retrieve, ) self.update = async_to_raw_response_wrapper( agents.update, ) self.list = async_to_raw_response_wrapper( agents.list, ) self.delete = async_to_raw_response_wrapper( agents.delete, ) self.list_phone_numbers = async_to_raw_response_wrapper( agents.list_phone_numbers, ) self.list_templates = async_to_raw_response_wrapper( agents.list_templates, ) @cached_property def calls(self) -> AsyncCallsResourceWithRawResponse: return AsyncCallsResourceWithRawResponse(self._agents.calls) @cached_property def metrics(self) -> AsyncMetricsResourceWithRawResponse: return AsyncMetricsResourceWithRawResponse(self._agents.metrics) @cached_property def deployments(self) -> AsyncDeploymentsResourceWithRawResponse: return AsyncDeploymentsResourceWithRawResponse(self._agents.deployments) class AgentsResourceWithStreamingResponse: def __init__(self, agents: AgentsResource) -> None: self._agents = agents self.retrieve = to_streamed_response_wrapper( agents.retrieve, ) self.update = to_streamed_response_wrapper( agents.update, ) self.list = to_streamed_response_wrapper( agents.list, ) self.delete = to_streamed_response_wrapper( agents.delete, ) self.list_phone_numbers = to_streamed_response_wrapper( agents.list_phone_numbers, ) self.list_templates = to_streamed_response_wrapper( agents.list_templates, ) @cached_property def calls(self) -> CallsResourceWithStreamingResponse: return CallsResourceWithStreamingResponse(self._agents.calls) @cached_property def metrics(self) -> MetricsResourceWithStreamingResponse: return MetricsResourceWithStreamingResponse(self._agents.metrics) @cached_property def deployments(self) -> DeploymentsResourceWithStreamingResponse: return DeploymentsResourceWithStreamingResponse(self._agents.deployments) class AsyncAgentsResourceWithStreamingResponse: def __init__(self, agents: AsyncAgentsResource) -> None: self._agents = agents self.retrieve = async_to_streamed_response_wrapper( agents.retrieve, ) self.update = async_to_streamed_response_wrapper( agents.update, ) self.list = async_to_streamed_response_wrapper( agents.list, ) self.delete = async_to_streamed_response_wrapper( agents.delete, ) self.list_phone_numbers = async_to_streamed_response_wrapper( agents.list_phone_numbers, ) self.list_templates = async_to_streamed_response_wrapper( agents.list_templates, ) @cached_property def calls(self) -> AsyncCallsResourceWithStreamingResponse: return AsyncCallsResourceWithStreamingResponse(self._agents.calls) @cached_property def metrics(self) -> AsyncMetricsResourceWithStreamingResponse: return AsyncMetricsResourceWithStreamingResponse(self._agents.metrics) @cached_property def deployments(self) -> AsyncDeploymentsResourceWithStreamingResponse: return AsyncDeploymentsResourceWithStreamingResponse(self._agents.deployments)