From 25995805baa020eb7c4dd49abd451c6e0203e7e0 Mon Sep 17 00:00:00 2001 From: Amy Wu Date: Wed, 20 May 2026 12:37:02 -0700 Subject: [PATCH] chore: internal cleanup FUTURE_COPYBARA_INTEGRATE_REVIEW=https://github.com/googleapis/python-genai/pull/2473 from googleapis:release-please--branches--main 806b12a3def2625d0434ea9cf20c4b992b7bfa03 PiperOrigin-RevId: 918595532 --- .../genai/_interactions/resources/agents.py | 263 ++-- .../_interactions/resources/interactions.py | 1186 ++++++++--------- .../genai/_interactions/resources/webhooks.py | 656 ++++----- .../genai/tests/interactions/test_agents.py | 159 +++ google/genai/tests/interactions/test_paths.py | 92 +- .../genai/tests/interactions/test_webhooks.py | 211 +++ 6 files changed, 1525 insertions(+), 1042 deletions(-) create mode 100644 google/genai/tests/interactions/test_agents.py create mode 100644 google/genai/tests/interactions/test_webhooks.py diff --git a/google/genai/_interactions/resources/agents.py b/google/genai/_interactions/resources/agents.py index 1bbbe9975..4f0e3cd4d 100644 --- a/google/genai/_interactions/resources/agents.py +++ b/google/genai/_interactions/resources/agents.py @@ -17,46 +17,49 @@ from __future__ import annotations -from typing import Iterable +from typing import Iterable, List, Union import httpx +from typing_extensions import Literal -from ..types import agent_list_params, agent_create_params -from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._base_client import make_request_options from .._compat import cached_property -from .._resource import SyncAPIResource, AsyncAPIResource +from .._resource import AsyncAPIResource, SyncAPIResource from .._response import ( - to_raw_response_wrapper, - to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, + to_raw_response_wrapper, + to_streamed_response_wrapper, ) +from .._types import Body, Headers, NotGiven, Omit, Query, not_given, omit +from .._utils import async_maybe_transform, maybe_transform +from ..types import agent_create_params, agent_list_params from ..types.agent import Agent -from .._base_client import make_request_options -from ..types.agent_list_response import AgentListResponse from ..types.agent_delete_response import AgentDeleteResponse +from ..types.agent_list_response import AgentListResponse __all__ = ["AgentsResource", "AsyncAgentsResource"] class AgentsResource(SyncAPIResource): + @cached_property def with_raw_response(self) -> AgentsResourceWithRawResponse: - """ - This property can be used as a prefix for any HTTP method call to return + """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/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-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. + """An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response """ return AgentsResourceWithStreamingResponse(self) @@ -77,36 +80,33 @@ def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Agent: - """ - Creates a new Agent (Typed version for SDK). + """Creates a new Agent (Typed version for SDK). Args: id: The unique identifier for the agent. - base_agent: The base agent to extend. - base_environment: The environment configuration for the agent. - - description: Agent description for developers to quickly read and understand. - + description: Agent description for developers to quickly read and + understand. system_instruction: System instruction for the agent. - tools: The tools available to the agent. - 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) return self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path='agents'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="agents" + ), body=maybe_transform( { "id": id, @@ -119,7 +119,10 @@ def create( agent_create_params.AgentCreateParams, ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Agent, ) @@ -138,24 +141,26 @@ def list( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AgentListResponse: - """ - Lists all Agents. + """Lists all Agents. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) return self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path='agents'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="agents" + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -185,28 +190,35 @@ def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AgentDeleteResponse: - """ - Deletes an Agent. + """Deletes an 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._delete( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'agents/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"agents/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=AgentDeleteResponse, ) @@ -223,50 +235,61 @@ def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Agent: - """ - Gets a specific Agent. + """Gets a specific 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'agents/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"agents/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Agent, ) class AsyncAgentsResource(AsyncAPIResource): + @cached_property def with_raw_response(self) -> AsyncAgentsResourceWithRawResponse: - """ - This property can be used as a prefix for any HTTP method call to return + """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/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-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. + 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/stainless-sdks/gemini-next-gen-api-python#with_streaming_response + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response """ return AsyncAgentsResourceWithStreamingResponse(self) @@ -287,36 +310,33 @@ async def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Agent: - """ - Creates a new Agent (Typed version for SDK). + """Creates a new Agent (Typed version for SDK). Args: id: The unique identifier for the agent. - base_agent: The base agent to extend. - base_environment: The environment configuration for the agent. - - description: Agent description for developers to quickly read and understand. - + description: Agent description for developers to quickly read and + understand. system_instruction: System instruction for the agent. - tools: The tools available to the agent. - 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) return await self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path='agents'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="agents" + ), body=await async_maybe_transform( { "id": id, @@ -329,7 +349,10 @@ async def create( agent_create_params.AgentCreateParams, ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Agent, ) @@ -348,24 +371,26 @@ async def list( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AgentListResponse: - """ - Lists all Agents. + """Lists all Agents. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) return await self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path='agents'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="agents" + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -395,28 +420,35 @@ async def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AgentDeleteResponse: - """ - Deletes an Agent. + """Deletes an 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._delete( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'agents/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"agents/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=AgentDeleteResponse, ) @@ -433,34 +465,42 @@ async def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Agent: - """ - Gets a specific Agent. + """Gets a specific 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'agents/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"agents/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Agent, ) class AgentsResourceWithRawResponse: + def __init__(self, agents: AgentsResource) -> None: self._agents = agents @@ -479,6 +519,7 @@ def __init__(self, agents: AgentsResource) -> None: class AsyncAgentsResourceWithRawResponse: + def __init__(self, agents: AsyncAgentsResource) -> None: self._agents = agents @@ -497,6 +538,7 @@ def __init__(self, agents: AsyncAgentsResource) -> None: class AgentsResourceWithStreamingResponse: + def __init__(self, agents: AgentsResource) -> None: self._agents = agents @@ -515,6 +557,7 @@ def __init__(self, agents: AgentsResource) -> None: class AsyncAgentsResourceWithStreamingResponse: + def __init__(self, agents: AsyncAgentsResource) -> None: self._agents = agents diff --git a/google/genai/_interactions/resources/interactions.py b/google/genai/_interactions/resources/interactions.py index 274c546c9..ad6d34b49 100644 --- a/google/genai/_interactions/resources/interactions.py +++ b/google/genai/_interactions/resources/interactions.py @@ -17,58 +17,62 @@ from __future__ import annotations -from typing import List, Union, Iterable -from typing_extensions import Literal, overload +from typing import Iterable, List, Union import httpx +from typing_extensions import Literal, overload -from ..types import interaction_get_params, interaction_create_params -from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from .._utils import required_args, 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 .._streaming import Stream, AsyncStream from .._base_client import make_request_options +from .._compat import cached_property from .._legacy_lyria import ( - LegacyLyriaInteractionStream, LegacyLyriaInteractionAsyncStream, - LegacyLyriaInteractionDetectingStream, LegacyLyriaInteractionDetectingAsyncStream, + LegacyLyriaInteractionDetectingStream, + LegacyLyriaInteractionStream, is_legacy_lyria_request, ) -from ..types.tool_param import ToolParam +from .._resource import AsyncAPIResource, SyncAPIResource +from .._response import ( + async_to_raw_response_wrapper, + async_to_streamed_response_wrapper, + to_raw_response_wrapper, + to_streamed_response_wrapper, +) +from .._streaming import AsyncStream, Stream +from .._types import Body, Headers, NotGiven, Omit, Query, not_given, omit +from .._utils import async_maybe_transform, maybe_transform, required_args +from ..types import interaction_create_params, interaction_get_params +from ..types.generation_config_param import GenerationConfigParam from ..types.interaction import Interaction +from ..types.interaction_sse_event import InteractionSSEEvent from ..types.model_param import ModelParam +from ..types.tool_param import ToolParam from ..types.webhook_config_param import WebhookConfigParam -from ..types.interaction_sse_event import InteractionSSEEvent -from ..types.generation_config_param import GenerationConfigParam __all__ = ["InteractionsResource", "AsyncInteractionsResource"] class InteractionsResource(SyncAPIResource): + @cached_property def with_raw_response(self) -> InteractionsResourceWithRawResponse: - """ - This property can be used as a prefix for any HTTP method call to return + """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/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers """ return InteractionsResourceWithRawResponse(self) @cached_property - def with_streaming_response(self) -> InteractionsResourceWithStreamingResponse: - """ - An alternative to `.with_raw_response` that doesn't eagerly read the response body. + def with_streaming_response( + self, + ) -> InteractionsResourceWithStreamingResponse: + """An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response """ return InteractionsResourceWithStreamingResponse(self) @@ -85,7 +89,9 @@ def create( previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Omit = omit, @@ -99,50 +105,39 @@ def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction: - """ - Creates a new interaction. + """Creates a new interaction. Args: input: The input for the interaction. - model: The name of the `Model` used for generating the interaction. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - - generation_config: Input only. Configuration parameters for the model interaction. - + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. + generation_config: Input only. Configuration parameters for the model + interaction. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - + store: Input only. Whether to store the response and request for later + retrieval. stream: Input only. Whether the interaction will be streamed. - system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -160,7 +155,9 @@ def create( previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -173,50 +170,39 @@ def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Stream[InteractionSSEEvent]: - """ - Creates a new interaction. + """Creates a new interaction. Args: input: The input for the interaction. - model: The name of the `Model` used for generating the interaction. - stream: Input only. Whether the interaction will be streamed. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - - generation_config: Input only. Configuration parameters for the model interaction. - + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. + generation_config: Input only. Configuration parameters for the model + interaction. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - + store: Input only. Whether to store the response and request for later + retrieval. system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -225,25 +211,20 @@ def create( self, *, api_version: str | None = None, - agent: Union[ - Literal[ - "deep-research-pro-preview-12-2025", - "deep-research-preview-04-2026", - "deep-research-max-preview-04-2026", - ], - str, - ], input: interaction_create_params.Input, - agent_config: interaction_create_params.AgentConfig | Omit = omit, + model: ModelParam, + stream: bool, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, + generation_config: GenerationConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, - stream: Literal[False] | Omit = omit, system_instruction: str | Omit = omit, tools: Iterable[ToolParam] | Omit = omit, webhook_config: WebhookConfigParam | Omit = omit, @@ -253,51 +234,40 @@ def create( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> Interaction: - """ - Creates a new interaction. + ) -> Interaction | Stream[InteractionSSEEvent]: + """Creates a new interaction. Args: - agent: The name of the `Agent` used for generating the interaction. - input: The input for the interaction. - - agent_config: Configuration parameters for the agent interaction. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - + model: The name of the `Model` used for generating the interaction. + stream: Input only. Whether the interaction will be streamed. + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. + generation_config: Input only. Configuration parameters for the model + interaction. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - - stream: Input only. Whether the interaction will be streamed. - + store: Input only. Whether to store the response and request for later + retrieval. system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -315,16 +285,18 @@ def create( str, ], input: interaction_create_params.Input, - stream: Literal[True], agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, + stream: Literal[False] | Omit = omit, system_instruction: str | Omit = omit, tools: Iterable[ToolParam] | Omit = omit, webhook_config: WebhookConfigParam | Omit = omit, @@ -334,51 +306,39 @@ def create( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> Stream[InteractionSSEEvent]: - """ - Creates a new interaction. + ) -> Interaction: + """Creates a new interaction. Args: agent: The name of the `Agent` used for generating the interaction. - input: The input for the interaction. - - stream: Input only. Whether the interaction will be streamed. - agent_config: Configuration parameters for the agent interaction. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - + store: Input only. Whether to store the response and request for later + retrieval. + stream: Input only. Whether the interaction will be streamed. system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -387,16 +347,25 @@ def create( self, *, api_version: str | None = None, + agent: Union[ + Literal[ + "deep-research-pro-preview-12-2025", + "deep-research-preview-04-2026", + "deep-research-max-preview-04-2026", + ], + str, + ], input: interaction_create_params.Input, - model: ModelParam, - stream: bool, + stream: Literal[True], + agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, - generation_config: GenerationConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -408,84 +377,81 @@ def create( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> Interaction | Stream[InteractionSSEEvent]: - """ - Creates a new interaction. + ) -> Stream[InteractionSSEEvent]: + """Creates a new interaction. Args: + agent: The name of the `Agent` used for generating the interaction. input: The input for the interaction. - - model: The name of the `Model` used for generating the interaction. - stream: Input only. Whether the interaction will be streamed. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - - generation_config: Input only. Configuration parameters for the model interaction. - + agent_config: Configuration parameters for the agent interaction. + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - + store: Input only. Whether to store the response and request for later + retrieval. system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... - @required_args(["input", "model"], ["input", "model", "stream"], ["agent", "input"], ["agent", "input", "stream"]) + @required_args( + ["input", "model"], + ["input", "model", "stream"], + ["agent", "input"], + ["agent", "input", "stream"], + ) def create( self, *, api_version: str | None = None, input: interaction_create_params.Input, - model: ModelParam | Omit = omit, + agent: ( + Union[ + Literal[ + "deep-research-pro-preview-12-2025", + "deep-research-preview-04-2026", + "deep-research-max-preview-04-2026", + ], + str, + ] + | Omit + ) = omit, + agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model: ModelParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Literal[True] | Omit = omit, system_instruction: str | Omit = omit, tools: Iterable[ToolParam] | Omit = omit, webhook_config: WebhookConfigParam | Omit = omit, - agent: Union[ - Literal[ - "deep-research-pro-preview-12-2025", - "deep-research-preview-04-2026", - "deep-research-max-preview-04-2026", - ], - str, - ] - | Omit = omit, - agent_config: interaction_create_params.AgentConfig | 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, @@ -493,34 +459,46 @@ def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction | Stream[InteractionSSEEvent]: + if model is not omit and agent_config is not omit: + raise ValueError( + "Invalid request: specified `model` and `agent_config`. If" + " specifying `model`, use `generation_config`." + ) + if agent is not omit and generation_config is not omit: + raise ValueError( + "Invalid request: specified `agent` and `generation_config`. If" + " specifying `agent`, use `agent_config`." + ) if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") - if model is not omit and agent_config is not omit: - raise ValueError("Invalid request: specified `model` and `agent_config`. If specifying `model`, use `generation_config`.") - if agent is not omit and generation_config is not omit: - raise ValueError("Invalid request: specified `agent` and `generation_config`. If specifying `agent`, use `agent_config`.") - - # For streaming requests against vertex+legacy-lyria, swap in the - # Stream subclass that activates the per-event SSE remap during - # iteration. Non-streaming and `get()` paths don't need any resource- - # layer signal here — `Interaction._maybe_coerce_outputs` looks at the - # response body's `model` field directly. + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) stream_cls = ( LegacyLyriaInteractionStream[InteractionSSEEvent] - if (stream and is_legacy_lyria_request(is_vertex=self._client._is_vertex, model=model)) + if ( + stream + and is_legacy_lyria_request( + is_vertex=self._client._is_vertex, model=model + ) + ) else Stream[InteractionSSEEvent] ) return self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path='interactions'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="interactions" + ), body=maybe_transform( { "input": input, - "model": model, + "agent": agent, + "agent_config": agent_config, "background": background, "environment": environment, "generation_config": generation_config, + "model": model, "previous_interaction_id": previous_interaction_id, "response_format": response_format, "response_mime_type": response_mime_type, @@ -531,15 +509,16 @@ def create( "system_instruction": system_instruction, "tools": tools, "webhook_config": webhook_config, - "agent": agent, - "agent_config": agent_config, }, interaction_create_params.CreateModelInteractionParamsStreaming if stream else interaction_create_params.CreateModelInteractionParamsNonStreaming, ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Interaction, stream=stream or False, @@ -558,28 +537,36 @@ def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> object: - """ - Deletes the interaction by id. + """Deletes the interaction by id. Args: + id: The unique identifier of the interaction to delete. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._delete( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'interactions/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"interactions/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=object, ) @@ -598,28 +585,36 @@ def cancel( ) -> Interaction: """Cancels an interaction by id. - This only applies to background interactions that - are still running. + This only applies to background interactions that are still running. Args: + id: The unique identifier of the interaction to cancel. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'interactions/{id}/cancel'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"interactions/{id}/cancel" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Interaction, ) @@ -640,25 +635,21 @@ def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction: - """ - Retrieves the full details of a single interaction based on its - `Interaction.id`. + """Retrieves the full details of a single interaction based on its `Interaction.id`. Args: + id: The unique identifier of the interaction to retrieve. include_input: If set to true, includes the input in the response. - - last_event_id: Optional. If set, resumes the interaction stream from the next chunk after the - event marked by the event id. Can only be used if `stream` is true. - - stream: If set to true, the generated content will be streamed incrementally. - + last_event_id: Optional. If set, resumes the interaction stream from + the next chunk after the event marked by the event id. Can only be + used if `stream` is true. + stream: If set to true, the generated content will be streamed + incrementally. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -678,25 +669,21 @@ def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Stream[InteractionSSEEvent]: - """ - Retrieves the full details of a single interaction based on its - `Interaction.id`. + """Retrieves the full details of a single interaction based on its `Interaction.id`. Args: - stream: If set to true, the generated content will be streamed incrementally. - + id: The unique identifier of the interaction to retrieve. + stream: If set to true, the generated content will be streamed + incrementally. include_input: If set to true, includes the input in the response. - - last_event_id: Optional. If set, resumes the interaction stream from the next chunk after the - event marked by the event id. Can only be used if `stream` is true. - + last_event_id: Optional. If set, resumes the interaction stream from + the next chunk after the event marked by the event id. Can only be + used if `stream` is true. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -716,25 +703,21 @@ def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction | Stream[InteractionSSEEvent]: - """ - Retrieves the full details of a single interaction based on its - `Interaction.id`. + """Retrieves the full details of a single interaction based on its `Interaction.id`. Args: - stream: If set to true, the generated content will be streamed incrementally. - + id: The unique identifier of the interaction to retrieve. + stream: If set to true, the generated content will be streamed + incrementally. include_input: If set to true, includes the input in the response. - - last_event_id: Optional. If set, resumes the interaction stream from the next chunk after the - event marked by the event id. Can only be used if `stream` is true. - + last_event_id: Optional. If set, resumes the interaction stream from + the next chunk after the event marked by the event id. Can only be + used if `stream` is true. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -753,25 +736,26 @@ def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction | Stream[InteractionSSEEvent]: + if not id: + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") - if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") - - # We don't know the model up front for `get`, so we can't apply the - # same `is_legacy_lyria_request` gate that `create` uses. Instead, on - # vertex we hand the stream off to the detecting subclass, which - # activates the shim only after observing the first legacy event_type. - # For non-legacy interactions the subclass is a no-op vs. plain Stream. + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) stream_cls = ( LegacyLyriaInteractionDetectingStream[InteractionSSEEvent] if (stream and self._client._is_vertex) else Stream[InteractionSSEEvent] ) return self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'interactions/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"interactions/{id}" + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -793,22 +777,26 @@ def get( class AsyncInteractionsResource(AsyncAPIResource): + @cached_property def with_raw_response(self) -> AsyncInteractionsResourceWithRawResponse: - """ - This property can be used as a prefix for any HTTP method call to return + """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/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers """ return AsyncInteractionsResourceWithRawResponse(self) @cached_property - def with_streaming_response(self) -> AsyncInteractionsResourceWithStreamingResponse: - """ - An alternative to `.with_raw_response` that doesn't eagerly read the response body. + def with_streaming_response( + self, + ) -> AsyncInteractionsResourceWithStreamingResponse: + """An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response """ return AsyncInteractionsResourceWithStreamingResponse(self) @@ -825,7 +813,9 @@ async def create( previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Omit = omit, @@ -839,50 +829,39 @@ async def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction: - """ - Creates a new interaction. + """Creates a new interaction. Args: input: The input for the interaction. - model: The name of the `Model` used for generating the interaction. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - - generation_config: Input only. Configuration parameters for the model interaction. - + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. + generation_config: Input only. Configuration parameters for the model + interaction. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - + store: Input only. Whether to store the response and request for later + retrieval. stream: Input only. Whether the interaction will be streamed. - system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -900,7 +879,9 @@ async def create( previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -913,50 +894,39 @@ async def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncStream[InteractionSSEEvent]: - """ - Creates a new interaction. + """Creates a new interaction. Args: input: The input for the interaction. - model: The name of the `Model` used for generating the interaction. - stream: Input only. Whether the interaction will be streamed. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - - generation_config: Input only. Configuration parameters for the model interaction. - + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. + generation_config: Input only. Configuration parameters for the model + interaction. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - + store: Input only. Whether to store the response and request for later + retrieval. system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -965,25 +935,20 @@ async def create( self, *, api_version: str | None = None, - agent: Union[ - Literal[ - "deep-research-pro-preview-12-2025", - "deep-research-preview-04-2026", - "deep-research-max-preview-04-2026", - ], - str, - ], input: interaction_create_params.Input, - agent_config: interaction_create_params.AgentConfig | Omit = omit, + model: ModelParam, + stream: bool, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, + generation_config: GenerationConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, - stream: Literal[False] | Omit = omit, system_instruction: str | Omit = omit, tools: Iterable[ToolParam] | Omit = omit, webhook_config: WebhookConfigParam | Omit = omit, @@ -993,51 +958,40 @@ async def create( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> Interaction: - """ - Creates a new interaction. + ) -> Interaction | AsyncStream[InteractionSSEEvent]: + """Creates a new interaction. Args: - agent: The name of the `Agent` used for generating the interaction. - input: The input for the interaction. - - agent_config: Configuration parameters for the agent interaction. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - + model: The name of the `Model` used for generating the interaction. + stream: Input only. Whether the interaction will be streamed. + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. + generation_config: Input only. Configuration parameters for the model + interaction. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - - stream: Input only. Whether the interaction will be streamed. - + store: Input only. Whether to store the response and request for later + retrieval. system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -1055,16 +1009,18 @@ async def create( str, ], input: interaction_create_params.Input, - stream: Literal[True], agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, + stream: Literal[False] | Omit = omit, system_instruction: str | Omit = omit, tools: Iterable[ToolParam] | Omit = omit, webhook_config: WebhookConfigParam | Omit = omit, @@ -1074,51 +1030,39 @@ async def create( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> AsyncStream[InteractionSSEEvent]: - """ - Creates a new interaction. + ) -> Interaction: + """Creates a new interaction. Args: agent: The name of the `Agent` used for generating the interaction. - input: The input for the interaction. - - stream: Input only. Whether the interaction will be streamed. - agent_config: Configuration parameters for the agent interaction. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - + store: Input only. Whether to store the response and request for later + retrieval. + stream: Input only. Whether the interaction will be streamed. system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -1127,16 +1071,25 @@ async def create( self, *, api_version: str | None = None, + agent: Union[ + Literal[ + "deep-research-pro-preview-12-2025", + "deep-research-preview-04-2026", + "deep-research-max-preview-04-2026", + ], + str, + ], input: interaction_create_params.Input, - model: ModelParam, - stream: bool, + stream: Literal[True], + agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, - generation_config: GenerationConfigParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -1148,84 +1101,81 @@ async def create( extra_query: Query | None = None, extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, - ) -> Interaction | AsyncStream[InteractionSSEEvent]: - """ - Creates a new interaction. + ) -> AsyncStream[InteractionSSEEvent]: + """Creates a new interaction. Args: + agent: The name of the `Agent` used for generating the interaction. input: The input for the interaction. - - model: The name of the `Model` used for generating the interaction. - stream: Input only. Whether the interaction will be streamed. - - background: Input only. Whether to run the model interaction in the background. - - environment: The environment configuration for the interaction. Can be an object specifying - remote environment sources or a string referencing an existing environment ID. - - generation_config: Input only. Configuration parameters for the model interaction. - + agent_config: Configuration parameters for the agent interaction. + background: Input only. Whether to run the model interaction in the + background. + environment: The environment configuration for the interaction. Can be + an object specifying remote environment sources or a string + referencing an existing environment ID. previous_interaction_id: The ID of the previous interaction, if any. - - response_format: Enforces that the generated response is a JSON object that complies with the - JSON schema specified in this field. - - response_mime_type: The mime type of the response. This is required if response_format is set. - - response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). - + response_format: Enforces that the generated response is a JSON object + that complies with the JSON schema specified in this field. + response_mime_type: The mime type of the response. This is required if + response_format is set. + response_modalities: The requested modalities of the response (TEXT, + IMAGE, AUDIO). service_tier: The service tier for the interaction. - - store: Input only. Whether to store the response and request for later retrieval. - + store: Input only. Whether to store the response and request for later + retrieval. system_instruction: System instruction for the interaction. - - tools: A list of tool declarations the model may call during interaction. - - webhook_config: Optional. Webhook configuration for receiving notifications when the interaction - completes. - + tools: A list of tool declarations the model may call during + interaction. + webhook_config: Optional. Webhook configuration for receiving + notifications when the interaction completes. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... - @required_args(["input", "model"], ["input", "model", "stream"], ["agent", "input"], ["agent", "input", "stream"]) + @required_args( + ["input", "model"], + ["input", "model", "stream"], + ["agent", "input"], + ["agent", "input", "stream"], + ) async def create( self, *, api_version: str | None = None, input: interaction_create_params.Input, - model: ModelParam | Omit = omit, + agent: ( + Union[ + Literal[ + "deep-research-pro-preview-12-2025", + "deep-research-preview-04-2026", + "deep-research-max-preview-04-2026", + ], + str, + ] + | Omit + ) = omit, + agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + model: ModelParam | Omit = omit, previous_interaction_id: str | Omit = omit, response_format: interaction_create_params.ResponseFormat | Omit = omit, response_mime_type: str | Omit = omit, - response_modalities: List[Literal["text", "image", "audio", "video", "document"]] | Omit = omit, + response_modalities: ( + List[Literal["text", "image", "audio", "video", "document"]] | Omit + ) = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Literal[True] | Omit = omit, system_instruction: str | Omit = omit, tools: Iterable[ToolParam] | Omit = omit, webhook_config: WebhookConfigParam | Omit = omit, - agent: Union[ - Literal[ - "deep-research-pro-preview-12-2025", - "deep-research-preview-04-2026", - "deep-research-max-preview-04-2026", - ], - str, - ] - | Omit = omit, - agent_config: interaction_create_params.AgentConfig | 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, @@ -1233,30 +1183,46 @@ async def create( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction | AsyncStream[InteractionSSEEvent]: + if model is not omit and agent_config is not omit: + raise ValueError( + "Invalid request: specified `model` and `agent_config`. If" + " specifying `model`, use `generation_config`." + ) + if agent is not omit and generation_config is not omit: + raise ValueError( + "Invalid request: specified `agent` and `generation_config`. If" + " specifying `agent`, use `agent_config`." + ) if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") - if model is not omit and agent_config is not omit: - raise ValueError("Invalid request: specified `model` and `agent_config`. If specifying `model`, use `generation_config`.") - if agent is not omit and generation_config is not omit: - raise ValueError("Invalid request: specified `agent` and `generation_config`. If specifying `agent`, use `agent_config`.") - - # See sync `create` above for rationale. + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) stream_cls = ( LegacyLyriaInteractionAsyncStream[InteractionSSEEvent] - if (stream and is_legacy_lyria_request(is_vertex=self._client._is_vertex, model=model)) + if ( + stream + and is_legacy_lyria_request( + is_vertex=self._client._is_vertex, model=model + ) + ) else AsyncStream[InteractionSSEEvent] ) return await self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path='interactions'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="interactions" + ), body=await async_maybe_transform( { "input": input, - "model": model, + "agent": agent, + "agent_config": agent_config, "background": background, "environment": environment, "generation_config": generation_config, + "model": model, "previous_interaction_id": previous_interaction_id, "response_format": response_format, "response_mime_type": response_mime_type, @@ -1267,15 +1233,16 @@ async def create( "system_instruction": system_instruction, "tools": tools, "webhook_config": webhook_config, - "agent": agent, - "agent_config": agent_config, }, interaction_create_params.CreateModelInteractionParamsStreaming if stream else interaction_create_params.CreateModelInteractionParamsNonStreaming, ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Interaction, stream=stream or False, @@ -1294,28 +1261,36 @@ async def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> object: - """ - Deletes the interaction by id. + """Deletes the interaction by id. Args: + id: The unique identifier of the interaction to delete. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._delete( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'interactions/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"interactions/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=object, ) @@ -1334,28 +1309,36 @@ async def cancel( ) -> Interaction: """Cancels an interaction by id. - This only applies to background interactions that - are still running. + This only applies to background interactions that are still running. Args: + id: The unique identifier of the interaction to cancel. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'interactions/{id}/cancel'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"interactions/{id}/cancel" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Interaction, ) @@ -1376,25 +1359,21 @@ async def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction: - """ - Retrieves the full details of a single interaction based on its - `Interaction.id`. + """Retrieves the full details of a single interaction based on its `Interaction.id`. Args: + id: The unique identifier of the interaction to retrieve. include_input: If set to true, includes the input in the response. - - last_event_id: Optional. If set, resumes the interaction stream from the next chunk after the - event marked by the event id. Can only be used if `stream` is true. - - stream: If set to true, the generated content will be streamed incrementally. - + last_event_id: Optional. If set, resumes the interaction stream from + the next chunk after the event marked by the event id. Can only be + used if `stream` is true. + stream: If set to true, the generated content will be streamed + incrementally. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -1414,25 +1393,21 @@ async def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> AsyncStream[InteractionSSEEvent]: - """ - Retrieves the full details of a single interaction based on its - `Interaction.id`. + """Retrieves the full details of a single interaction based on its `Interaction.id`. Args: - stream: If set to true, the generated content will be streamed incrementally. - + id: The unique identifier of the interaction to retrieve. + stream: If set to true, the generated content will be streamed + incrementally. include_input: If set to true, includes the input in the response. - - last_event_id: Optional. If set, resumes the interaction stream from the next chunk after the - event marked by the event id. Can only be used if `stream` is true. - + last_event_id: Optional. If set, resumes the interaction stream from + the next chunk after the event marked by the event id. Can only be + used if `stream` is true. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -1452,25 +1427,21 @@ async def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction | AsyncStream[InteractionSSEEvent]: - """ - Retrieves the full details of a single interaction based on its - `Interaction.id`. + """Retrieves the full details of a single interaction based on its `Interaction.id`. Args: - stream: If set to true, the generated content will be streamed incrementally. - + id: The unique identifier of the interaction to retrieve. + stream: If set to true, the generated content will be streamed + incrementally. include_input: If set to true, includes the input in the response. - - last_event_id: Optional. If set, resumes the interaction stream from the next chunk after the - event marked by the event id. Can only be used if `stream` is true. - + last_event_id: Optional. If set, resumes the interaction stream from + the next chunk after the event marked by the event id. Can only be + used if `stream` is true. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ ... @@ -1489,21 +1460,26 @@ async def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Interaction | AsyncStream[InteractionSSEEvent]: + if not id: + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") - if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") - - # See sync `get` above for rationale. + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) stream_cls = ( LegacyLyriaInteractionDetectingAsyncStream[InteractionSSEEvent] if (stream and self._client._is_vertex) else AsyncStream[InteractionSSEEvent] ) return await self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'interactions/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"interactions/{id}" + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -1525,6 +1501,7 @@ async def get( class InteractionsResourceWithRawResponse: + def __init__(self, interactions: InteractionsResource) -> None: self._interactions = interactions @@ -1543,6 +1520,7 @@ def __init__(self, interactions: InteractionsResource) -> None: class AsyncInteractionsResourceWithRawResponse: + def __init__(self, interactions: AsyncInteractionsResource) -> None: self._interactions = interactions @@ -1561,6 +1539,7 @@ def __init__(self, interactions: AsyncInteractionsResource) -> None: class InteractionsResourceWithStreamingResponse: + def __init__(self, interactions: InteractionsResource) -> None: self._interactions = interactions @@ -1579,6 +1558,7 @@ def __init__(self, interactions: InteractionsResource) -> None: class AsyncInteractionsResourceWithStreamingResponse: + def __init__(self, interactions: AsyncInteractionsResource) -> None: self._interactions = interactions diff --git a/google/genai/_interactions/resources/webhooks.py b/google/genai/_interactions/resources/webhooks.py index d1117cc45..667c1a291 100644 --- a/google/genai/_interactions/resources/webhooks.py +++ b/google/genai/_interactions/resources/webhooks.py @@ -17,55 +17,51 @@ from __future__ import annotations -from typing import List, Union -from typing_extensions import Literal +from typing import Iterable, List, Union import httpx +from typing_extensions import Literal -from ..types import ( - webhook_list_params, - webhook_ping_params, - webhook_create_params, - webhook_update_params, - webhook_rotate_signing_secret_params, -) -from .._types import Body, Omit, Query, Headers, NotGiven, omit, not_given -from .._utils import maybe_transform, async_maybe_transform +from .._base_client import make_request_options from .._compat import cached_property -from .._resource import SyncAPIResource, AsyncAPIResource +from .._resource import AsyncAPIResource, SyncAPIResource from .._response import ( - to_raw_response_wrapper, - to_streamed_response_wrapper, async_to_raw_response_wrapper, async_to_streamed_response_wrapper, + to_raw_response_wrapper, + to_streamed_response_wrapper, ) -from .._base_client import make_request_options +from .._types import Body, Headers, NotGiven, Omit, Query, not_given, omit +from .._utils import async_maybe_transform, maybe_transform +from ..types import webhook_create_params, webhook_list_params, webhook_ping_params, webhook_rotate_signing_secret_params, webhook_update_params from ..types.webhook import Webhook +from ..types.webhook_delete_response import WebhookDeleteResponse from ..types.webhook_list_response import WebhookListResponse from ..types.webhook_ping_response import WebhookPingResponse -from ..types.webhook_delete_response import WebhookDeleteResponse from ..types.webhook_rotate_signing_secret_response import WebhookRotateSigningSecretResponse __all__ = ["WebhooksResource", "AsyncWebhooksResource"] class WebhooksResource(SyncAPIResource): + @cached_property def with_raw_response(self) -> WebhooksResourceWithRawResponse: - """ - This property can be used as a prefix for any HTTP method call to return + """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/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers """ return WebhooksResourceWithRawResponse(self) @cached_property def with_streaming_response(self) -> WebhooksResourceWithStreamingResponse: - """ - An alternative to `.with_raw_response` that doesn't eagerly read the response body. + """An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response """ return WebhooksResourceWithStreamingResponse(self) @@ -75,16 +71,14 @@ def create( api_version: str | None = None, subscribed_events: List[ Union[ - Literal[ - "batch.succeeded", - "batch.expired", - "batch.failed", - "interaction.requires_action", - "interaction.completed", - "interaction.failed", - "video.generated", - ], str, + Literal["batch.succeeded"], + Literal["batch.expired"], + Literal["batch.failed"], + Literal["interaction.requires_action"], + Literal["interaction.completed"], + Literal["interaction.failed"], + Literal["video.generated"], ] ], uri: str, @@ -99,37 +93,29 @@ def create( """Creates a new Webhook. Args: - subscribed_events: - Required. - - The events that the webhook is subscribed to. Available events: - - - batch.succeeded - - batch.expired - - batch.failed - - interaction.requires_action - - interaction.completed - - interaction.failed - - video.generated - + subscribed_events: Required. The events that the webhook is subscribed + to. Available events: - batch.succeeded - batch.expired - + batch.failed - interaction.requires_action - interaction.completed - + interaction.failed - video.generated uri: Required. The URI to which webhook events will be sent. - name: Optional. The user-provided name of the webhook. - 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) return self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path='webhooks'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="webhooks" + ), body=maybe_transform( { "subscribed_events": subscribed_events, @@ -139,7 +125,10 @@ def create( webhook_create_params.WebhookCreateParams, ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Webhook, ) @@ -149,24 +138,27 @@ def update( id: str, *, api_version: str | None = None, - update_mask: str | Omit = omit, name: str | Omit = omit, - state: Literal["enabled", "disabled", "disabled_due_to_failed_deliveries"] | Omit = omit, - subscribed_events: List[ - Union[ - Literal[ - "batch.succeeded", - "batch.expired", - "batch.failed", - "interaction.requires_action", - "interaction.completed", - "interaction.failed", - "video.generated", - ], - str, + state: ( + Literal["enabled", "disabled", "disabled_due_to_failed_deliveries"] + | Omit + ) = omit, + subscribed_events: ( + List[ + Union[ + str, + Literal["batch.succeeded"], + Literal["batch.expired"], + Literal["batch.failed"], + Literal["interaction.requires_action"], + Literal["interaction.completed"], + Literal["interaction.failed"], + Literal["video.generated"], + ] ] - ] - | Omit = omit, + | Omit + ) = omit, + update_mask: str | Omit = omit, uri: 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. @@ -178,43 +170,35 @@ def update( """Updates an existing Webhook. Args: - update_mask: Optional. - - The list of fields to update. - name: Optional. The user-provided name of the webhook. - state: Optional. The state of the webhook. - - subscribed_events: - Optional. The events that the webhook is subscribed to. Available events: - - - batch.succeeded - - batch.expired - - batch.failed - - interaction.requires_action - - interaction.completed - - interaction.failed - - video.generated - + subscribed_events: Optional. The events that the webhook is subscribed + to. Available events: - batch.succeeded - batch.expired - + batch.failed - interaction.requires_action - interaction.completed - + interaction.failed - video.generated + update_mask: Optional. The list of fields to update. uri: Optional. The URI to which webhook events will be sent. - 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._patch( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"webhooks/{id}" + ), body=maybe_transform( { "name": name, @@ -229,7 +213,12 @@ def update( extra_query=extra_query, extra_body=extra_body, timeout=timeout, - query=maybe_transform({"update_mask": update_mask}, webhook_update_params.WebhookUpdateParams), + query=maybe_transform( + { + "update_mask": update_mask, + }, + webhook_update_params.WebhookUpdateParams, + ), ), cast_to=Webhook, ) @@ -250,29 +239,28 @@ def list( """Lists all Webhooks. Args: - page_size: Optional. - - The maximum number of webhooks to return. The service may return fewer - than this value. If unspecified, at most 50 webhooks will be returned. The - maximum value is 1000. - - page_token: Optional. A page token, received from a previous `ListWebhooks` call. Provide - this to retrieve the subsequent page. - + page_size: Optional. The maximum number of webhooks to return. The + service may return fewer than this value. If unspecified, at most 50 + webhooks will be returned. The maximum value is 1000. + page_token: Optional. A page token, received from a previous + `ListWebhooks` call. Provide this to retrieve the subsequent page. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) return self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path='webhooks'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="webhooks" + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -301,28 +289,35 @@ def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> WebhookDeleteResponse: - """ - Deletes a Webhook. + """Deletes a Webhook. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._delete( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"webhooks/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=WebhookDeleteResponse, ) @@ -339,28 +334,35 @@ def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Webhook: - """ - Gets a specific Webhook. + """Gets a specific Webhook. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"webhooks/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Webhook, ) @@ -378,31 +380,36 @@ def ping( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> WebhookPingResponse: - """ - Sends a ping event to a Webhook. + """Sends a ping event to a Webhook. Args: - body: Request message for WebhookService.PingWebhook. - 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}:ping'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"webhooks/{id}:ping" + ), body=maybe_transform(body, webhook_ping_params.WebhookPingParams), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=WebhookPingResponse, ) @@ -412,8 +419,13 @@ def rotate_signing_secret( id: str, *, api_version: str | None = None, - revocation_behavior: Literal["revoke_previous_secrets_after_h24", "revoke_previous_secrets_immediately"] - | Omit = omit, + revocation_behavior: ( + Literal[ + "revoke_previous_secrets_after_h24", + "revoke_previous_secrets_immediately", + ] + | 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, @@ -421,56 +433,70 @@ def rotate_signing_secret( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> WebhookRotateSigningSecretResponse: - """ - Generates a new signing secret for a Webhook. + """Generates a new signing secret for a Webhook. Args: - revocation_behavior: Optional. The revocation behavior for previous signing secrets. - + revocation_behavior: Optional. The revocation behavior for previous + signing secrets. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}:rotateSigningSecret'), + self._client._build_maybe_vertex_path( + api_version=api_version, + path=f"webhooks/{id}:rotateSigningSecret", + ), body=maybe_transform( - {"revocation_behavior": revocation_behavior}, + { + "revocation_behavior": revocation_behavior, + }, webhook_rotate_signing_secret_params.WebhookRotateSigningSecretParams, ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=WebhookRotateSigningSecretResponse, ) class AsyncWebhooksResource(AsyncAPIResource): + @cached_property def with_raw_response(self) -> AsyncWebhooksResourceWithRawResponse: - """ - This property can be used as a prefix for any HTTP method call to return + """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/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#accessing-raw-response-data-eg-headers """ return AsyncWebhooksResourceWithRawResponse(self) @cached_property - def with_streaming_response(self) -> AsyncWebhooksResourceWithStreamingResponse: - """ - An alternative to `.with_raw_response` that doesn't eagerly read the response body. + def with_streaming_response( + self, + ) -> AsyncWebhooksResourceWithStreamingResponse: + """An alternative to `.with_raw_response` that doesn't eagerly read the response body. - For more information, see https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response + For more information, see + https://www.github.com/stainless-sdks/gemini-next-gen-api-python#with_streaming_response """ return AsyncWebhooksResourceWithStreamingResponse(self) @@ -480,16 +506,14 @@ async def create( api_version: str | None = None, subscribed_events: List[ Union[ - Literal[ - "batch.succeeded", - "batch.expired", - "batch.failed", - "interaction.requires_action", - "interaction.completed", - "interaction.failed", - "video.generated", - ], str, + Literal["batch.succeeded"], + Literal["batch.expired"], + Literal["batch.failed"], + Literal["interaction.requires_action"], + Literal["interaction.completed"], + Literal["interaction.failed"], + Literal["video.generated"], ] ], uri: str, @@ -504,37 +528,29 @@ async def create( """Creates a new Webhook. Args: - subscribed_events: - Required. - - The events that the webhook is subscribed to. Available events: - - - batch.succeeded - - batch.expired - - batch.failed - - interaction.requires_action - - interaction.completed - - interaction.failed - - video.generated - + subscribed_events: Required. The events that the webhook is subscribed + to. Available events: - batch.succeeded - batch.expired - + batch.failed - interaction.requires_action - interaction.completed - + interaction.failed - video.generated uri: Required. The URI to which webhook events will be sent. - name: Optional. The user-provided name of the webhook. - 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) return await self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path='webhooks'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="webhooks" + ), body=await async_maybe_transform( { "subscribed_events": subscribed_events, @@ -544,7 +560,10 @@ async def create( webhook_create_params.WebhookCreateParams, ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Webhook, ) @@ -554,24 +573,27 @@ async def update( id: str, *, api_version: str | None = None, - update_mask: str | Omit = omit, name: str | Omit = omit, - state: Literal["enabled", "disabled", "disabled_due_to_failed_deliveries"] | Omit = omit, - subscribed_events: List[ - Union[ - Literal[ - "batch.succeeded", - "batch.expired", - "batch.failed", - "interaction.requires_action", - "interaction.completed", - "interaction.failed", - "video.generated", - ], - str, + state: ( + Literal["enabled", "disabled", "disabled_due_to_failed_deliveries"] + | Omit + ) = omit, + subscribed_events: ( + List[ + Union[ + str, + Literal["batch.succeeded"], + Literal["batch.expired"], + Literal["batch.failed"], + Literal["interaction.requires_action"], + Literal["interaction.completed"], + Literal["interaction.failed"], + Literal["video.generated"], + ] ] - ] - | Omit = omit, + | Omit + ) = omit, + update_mask: str | Omit = omit, uri: 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. @@ -583,43 +605,35 @@ async def update( """Updates an existing Webhook. Args: - update_mask: Optional. - - The list of fields to update. - name: Optional. The user-provided name of the webhook. - state: Optional. The state of the webhook. - - subscribed_events: - Optional. The events that the webhook is subscribed to. Available events: - - - batch.succeeded - - batch.expired - - batch.failed - - interaction.requires_action - - interaction.completed - - interaction.failed - - video.generated - + subscribed_events: Optional. The events that the webhook is subscribed + to. Available events: - batch.succeeded - batch.expired - + batch.failed - interaction.requires_action - interaction.completed - + interaction.failed - video.generated + update_mask: Optional. The list of fields to update. uri: Optional. The URI to which webhook events will be sent. - 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._patch( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"webhooks/{id}" + ), body=await async_maybe_transform( { "name": name, @@ -635,7 +649,10 @@ async def update( extra_body=extra_body, timeout=timeout, query=await async_maybe_transform( - {"update_mask": update_mask}, webhook_update_params.WebhookUpdateParams + { + "update_mask": update_mask, + }, + webhook_update_params.WebhookUpdateParams, ), ), cast_to=Webhook, @@ -657,29 +674,28 @@ async def list( """Lists all Webhooks. Args: - page_size: Optional. - - The maximum number of webhooks to return. The service may return fewer - than this value. If unspecified, at most 50 webhooks will be returned. The - maximum value is 1000. - - page_token: Optional. A page token, received from a previous `ListWebhooks` call. Provide - this to retrieve the subsequent page. - + page_size: Optional. The maximum number of webhooks to return. The + service may return fewer than this value. If unspecified, at most 50 + webhooks will be returned. The maximum value is 1000. + page_token: Optional. A page token, received from a previous + `ListWebhooks` call. Provide this to retrieve the subsequent page. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) return await self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path='webhooks'), + self._client._build_maybe_vertex_path( + api_version=api_version, path="webhooks" + ), options=make_request_options( extra_headers=extra_headers, extra_query=extra_query, @@ -708,28 +724,35 @@ async def delete( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> WebhookDeleteResponse: - """ - Deletes a Webhook. + """Deletes a Webhook. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._delete( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"webhooks/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=WebhookDeleteResponse, ) @@ -746,28 +769,35 @@ async def get( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> Webhook: - """ - Gets a specific Webhook. + """Gets a specific Webhook. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._get( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}'), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"webhooks/{id}" + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=Webhook, ) @@ -785,31 +815,38 @@ async def ping( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> WebhookPingResponse: - """ - Sends a ping event to a Webhook. + """Sends a ping event to a Webhook. Args: - body: Request message for WebhookService.PingWebhook. - 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}:ping'), - body=await async_maybe_transform(body, webhook_ping_params.WebhookPingParams), + self._client._build_maybe_vertex_path( + api_version=api_version, path=f"webhooks/{id}:ping" + ), + body=await async_maybe_transform( + body, webhook_ping_params.WebhookPingParams + ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=WebhookPingResponse, ) @@ -819,8 +856,13 @@ async def rotate_signing_secret( id: str, *, api_version: str | None = None, - revocation_behavior: Literal["revoke_previous_secrets_after_h24", "revoke_previous_secrets_immediately"] - | Omit = omit, + revocation_behavior: ( + Literal[ + "revoke_previous_secrets_after_h24", + "revoke_previous_secrets_immediately", + ] + | 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, @@ -828,40 +870,51 @@ async def rotate_signing_secret( extra_body: Body | None = None, timeout: float | httpx.Timeout | None | NotGiven = not_given, ) -> WebhookRotateSigningSecretResponse: - """ - Generates a new signing secret for a Webhook. + """Generates a new signing secret for a Webhook. Args: - revocation_behavior: Optional. The revocation behavior for previous signing secrets. - + revocation_behavior: Optional. The revocation behavior for previous + signing secrets. 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 + timeout: Override the client-level default timeout for this request, + in seconds """ if api_version is None: api_version = self._client._get_api_version_path_param() if not api_version: - raise ValueError(f"Expected a non-empty value for `api_version` but received {api_version!r}") + raise ValueError( + "Expected a non-empty value for `api_version` but received" + f" {api_version!r}" + ) if not id: - raise ValueError(f"Expected a non-empty value for `id` but received {id!r}") + raise ValueError( + f"Expected a non-empty value for `id` but received {id!r}" + ) return await self._post( - self._client._build_maybe_vertex_path(api_version=api_version, path=f'webhooks/{id}:rotateSigningSecret'), + self._client._build_maybe_vertex_path( + api_version=api_version, + path=f"webhooks/{id}:rotateSigningSecret", + ), body=await async_maybe_transform( - {"revocation_behavior": revocation_behavior}, + { + "revocation_behavior": revocation_behavior, + }, webhook_rotate_signing_secret_params.WebhookRotateSigningSecretParams, ), options=make_request_options( - extra_headers=extra_headers, extra_query=extra_query, extra_body=extra_body, timeout=timeout + extra_headers=extra_headers, + extra_query=extra_query, + extra_body=extra_body, + timeout=timeout, ), cast_to=WebhookRotateSigningSecretResponse, ) class WebhooksResourceWithRawResponse: + def __init__(self, webhooks: WebhooksResource) -> None: self._webhooks = webhooks @@ -889,6 +942,7 @@ def __init__(self, webhooks: WebhooksResource) -> None: class AsyncWebhooksResourceWithRawResponse: + def __init__(self, webhooks: AsyncWebhooksResource) -> None: self._webhooks = webhooks @@ -916,6 +970,7 @@ def __init__(self, webhooks: AsyncWebhooksResource) -> None: class WebhooksResourceWithStreamingResponse: + def __init__(self, webhooks: WebhooksResource) -> None: self._webhooks = webhooks @@ -943,6 +998,7 @@ def __init__(self, webhooks: WebhooksResource) -> None: class AsyncWebhooksResourceWithStreamingResponse: + def __init__(self, webhooks: AsyncWebhooksResource) -> None: self._webhooks = webhooks diff --git a/google/genai/tests/interactions/test_agents.py b/google/genai/tests/interactions/test_agents.py new file mode 100644 index 000000000..67ef3e8c9 --- /dev/null +++ b/google/genai/tests/interactions/test_agents.py @@ -0,0 +1,159 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +"""Tests for Agents API URL paths.""" + +from unittest import mock +import google.auth +from httpx import Client as HTTPClient +from httpx import Request, Response +import pytest +from ..._api_client import AsyncHttpxClient +from .. import pytest_helper + + +@mock.patch.object(google.auth, 'default', autospec=True) +def test_urls(mock_auth_default, client): + agent_id = 'test-agent-id' + + mock_creds = mock.Mock() + mock_creds.token = 'test-token' + mock_creds.expired = False + mock_creds.quota_project_id = 'test-quota-project' + mock_auth_default.return_value = (mock_creds, 'test-project') + + if client._api_client.vertexai: + if client._api_client.location == 'global': + expected_base_url = ( + f'https://aiplatform.googleapis.com/v1beta1' + f'/projects/{client._api_client.project}/locations/global' + ) + else: + expected_base_url = ( + f'https://{client._api_client.location}-aiplatform.googleapis.com' + f'/v1beta1/projects/{client._api_client.project}' + f'/locations/{client._api_client.location}' + ) + else: + expected_base_url = 'https://generativelanguage.googleapis.com/v1beta' + + with mock.patch.object(HTTPClient, 'send') as mock_send: + # 1. Create Agent + mock_send.return_value = Response(200, json={}, request=Request('POST', '')) + client.agents.create( + id=agent_id, + description='Test agent', + ) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/agents' + + # 2. Get Agent + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('GET', '')) + client.agents.get(id=agent_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/agents/{agent_id}' + + # 3. List Agents + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('GET', '')) + client.agents.list() + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/agents' + + # 4. Delete Agent + mock_send.reset_mock() + mock_send.return_value = Response( + 200, json={}, request=Request('DELETE', '') + ) + client.agents.delete(id=agent_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/agents/{agent_id}' + + +@pytest.mark.asyncio +@mock.patch.object(google.auth, 'default', autospec=True) +async def test_async_urls(mock_auth_default, client): + agent_id = 'test-agent-id' + + mock_creds = mock.Mock() + mock_creds.token = 'test-token' + mock_creds.expired = False + mock_creds.quota_project_id = 'test-quota-project' + mock_auth_default.return_value = (mock_creds, 'test-project') + + if client._api_client.vertexai: + if client._api_client.location == 'global': + expected_base_url = ( + f'https://aiplatform.googleapis.com/v1beta1' + f'/projects/{client._api_client.project}/locations/global' + ) + else: + expected_base_url = ( + f'https://{client._api_client.location}-aiplatform.googleapis.com' + f'/v1beta1/projects/{client._api_client.project}' + f'/locations/{client._api_client.location}' + ) + else: + expected_base_url = 'https://generativelanguage.googleapis.com/v1beta' + + with mock.patch.object(AsyncHttpxClient, 'send') as mock_send: + # 1. Create Agent + mock_send.return_value = Response(200, json={}, request=Request('POST', '')) + await client.aio.agents.create( + id=agent_id, + description='Test agent', + ) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/agents' + + # 2. Get Agent + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('GET', '')) + await client.aio.agents.get(id=agent_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/agents/{agent_id}' + + # 3. List Agents + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('GET', '')) + await client.aio.agents.list() + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/agents' + + # 4. Delete Agent + mock_send.reset_mock() + mock_send.return_value = Response( + 200, json={}, request=Request('DELETE', '') + ) + await client.aio.agents.delete(id=agent_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/agents/{agent_id}' + + +pytestmark = pytest_helper.setup( + file=__file__, + globals_for_file=globals(), + test_table=[], +) diff --git a/google/genai/tests/interactions/test_paths.py b/google/genai/tests/interactions/test_paths.py index 1e8f77000..a5c1fbf53 100644 --- a/google/genai/tests/interactions/test_paths.py +++ b/google/genai/tests/interactions/test_paths.py @@ -1,5 +1,4 @@ - -# Copyright 2025 Google LLC +# Copyright 2026 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -18,85 +17,120 @@ """Tests for Interactions API URL paths.""" from unittest import mock -import pytest +import google.auth +from httpx import Client as HTTPClient from httpx import Request, Response +import pytest from ..._api_client import AsyncHttpxClient -from httpx import Client as HTTPClient from .. import pytest_helper -import google.auth -@mock.patch.object(google.auth, "default", autospec=True) -def test_interactions_paths(mock_auth_default, client): - interaction_id = "test-interaction-id" +@mock.patch.object(google.auth, 'default', autospec=True) +def test_interactions_paths(mock_auth_default, client): + interaction_id = 'test-interaction-id' mock_creds = mock.Mock() - mock_creds.token = "test-token" + mock_creds.token = 'test-token' mock_creds.expired = False - mock_creds.quota_project_id = "test-quota-project" - mock_auth_default.return_value = (mock_creds, "test-project") + mock_creds.quota_project_id = 'test-quota-project' + mock_auth_default.return_value = (mock_creds, 'test-project') if client._api_client.vertexai: - expected_base_url = f'https://{client._api_client.location}-aiplatform.googleapis.com/v1beta1/projects/{client._api_client.project}/locations/{client._api_client.location}' + if client._api_client.location == 'global': + expected_base_url = ( + 'https://aiplatform.googleapis.com' + f'/v1beta1/projects/{client._api_client.project}' + '/locations/global' + ) + else: + expected_base_url = ( + f'https://{client._api_client.location}-aiplatform.googleapis.com' + f'/v1beta1/projects/{client._api_client.project}' + f'/locations/{client._api_client.location}' + ) else: - expected_base_url = "https://generativelanguage.googleapis.com/v1beta" + expected_base_url = 'https://generativelanguage.googleapis.com/v1beta' - with mock.patch.object(HTTPClient, "send") as mock_send: + with mock.patch.object(HTTPClient, 'send') as mock_send: mock_send.return_value = Response(200, request=Request('GET', '')) client.interactions.get(id=interaction_id) mock_send.assert_called_once() request = mock_send.call_args[0][0] - assert str(request.url) == f'{expected_base_url}/interactions/{interaction_id}' + assert str(request.url) == ( + f'{expected_base_url}/interactions/{interaction_id}' + ) mock_send.reset_mock() mock_send.return_value = Response(200, request=Request('POST', '')) client.interactions.cancel(id=interaction_id) mock_send.assert_called_once() request = mock_send.call_args[0][0] - assert str(request.url) == f'{expected_base_url}/interactions/{interaction_id}/cancel' + assert str(request.url) == ( + f'{expected_base_url}/interactions/{interaction_id}/cancel' + ) mock_send.reset_mock() mock_send.return_value = Response(200, request=Request('DELETE', '')) client.interactions.delete(id=interaction_id) mock_send.assert_called_once() request = mock_send.call_args[0][0] - assert str(request.url) == f'{expected_base_url}/interactions/{interaction_id}' + assert str(request.url) == ( + f'{expected_base_url}/interactions/{interaction_id}' + ) + @pytest.mark.asyncio -@mock.patch.object(google.auth, "default", autospec=True) +@mock.patch.object(google.auth, 'default', autospec=True) async def test_async_interactions_paths(mock_auth_default, client): - interaction_id = "test-interaction-id" - + interaction_id = 'test-interaction-id' mock_creds = mock.Mock() - mock_creds.token = "test-token" + mock_creds.token = 'test-token' mock_creds.expired = False - mock_creds.quota_project_id = "test-quota-project" - mock_auth_default.return_value = (mock_creds, "test-project") + mock_creds.quota_project_id = 'test-quota-project' + mock_auth_default.return_value = (mock_creds, 'test-project') if client._api_client.vertexai: - expected_base_url = f'https://{client._api_client.location}-aiplatform.googleapis.com/v1beta1/projects/{client._api_client.project}/locations/{client._api_client.location}' + if client._api_client.location == 'global': + expected_base_url = ( + 'https://aiplatform.googleapis.com' + f'/v1beta1/projects/{client._api_client.project}' + '/locations/global' + ) + else: + expected_base_url = ( + f'https://{client._api_client.location}-aiplatform.googleapis.com' + f'/v1beta1/projects/{client._api_client.project}' + f'/locations/{client._api_client.location}' + ) else: - expected_base_url = "https://generativelanguage.googleapis.com/v1beta" + expected_base_url = 'https://generativelanguage.googleapis.com/v1beta' - with mock.patch.object(AsyncHttpxClient, "send") as mock_send: + with mock.patch.object(AsyncHttpxClient, 'send') as mock_send: mock_send.return_value = Response(200, request=Request('GET', '')) await client.aio.interactions.get(id=interaction_id) mock_send.assert_called_once() request = mock_send.call_args[0][0] - assert str(request.url) == f'{expected_base_url}/interactions/{interaction_id}' + assert str(request.url) == ( + f'{expected_base_url}/interactions/{interaction_id}' + ) mock_send.reset_mock() mock_send.return_value = Response(200, request=Request('POST', '')) await client.aio.interactions.cancel(id=interaction_id) mock_send.assert_called_once() request = mock_send.call_args[0][0] - assert str(request.url) == f'{expected_base_url}/interactions/{interaction_id}/cancel' + assert str(request.url) == ( + f'{expected_base_url}/interactions/{interaction_id}/cancel' + ) mock_send.reset_mock() mock_send.return_value = Response(200, request=Request('DELETE', '')) await client.aio.interactions.delete(id=interaction_id) mock_send.assert_called_once() request = mock_send.call_args[0][0] - assert str(request.url) == f'{expected_base_url}/interactions/{interaction_id}' + assert str(request.url) == ( + f'{expected_base_url}/interactions/{interaction_id}' + ) + pytestmark = pytest_helper.setup( file=__file__, diff --git a/google/genai/tests/interactions/test_webhooks.py b/google/genai/tests/interactions/test_webhooks.py new file mode 100644 index 000000000..c32574ddc --- /dev/null +++ b/google/genai/tests/interactions/test_webhooks.py @@ -0,0 +1,211 @@ +# Copyright 2026 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + + +"""Tests for Webhooks API URL paths.""" + +from unittest import mock +import google.auth +from httpx import Client as HTTPClient +from httpx import Request, Response +import pytest +from ..._api_client import AsyncHttpxClient +from .. import pytest_helper + + +@mock.patch.object(google.auth, 'default', autospec=True) +def test_urls(mock_auth_default, client): + webhook_id = 'test-webhook-id' + + mock_creds = mock.Mock() + mock_creds.token = 'test-token' + mock_creds.expired = False + mock_creds.quota_project_id = 'test-quota-project' + mock_auth_default.return_value = (mock_creds, 'test-project') + + if client._api_client.vertexai: + if client._api_client.location == 'global': + expected_base_url = f'https://aiplatform.googleapis.com/v1beta1/projects/{client._api_client.project}/locations/global' + else: + expected_base_url = f'https://{client._api_client.location}-aiplatform.googleapis.com/v1beta1/projects/{client._api_client.project}/locations/{client._api_client.location}' + else: + expected_base_url = 'https://generativelanguage.googleapis.com/v1beta' + + with mock.patch.object(HTTPClient, 'send') as mock_send: + # 1. Create Webhook + mock_send.return_value = Response(200, json={}, request=Request('POST', '')) + client.webhooks.create( + subscribed_events=['batch.succeeded'], + uri='https://example.com/webhook', + name='test-webhook', + ) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks' + + # 2. Get Webhook + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('GET', '')) + client.webhooks.get(id=webhook_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks/{webhook_id}' + + # 3. List Webhooks + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('GET', '')) + client.webhooks.list() + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks' + + # 4. Update Webhook + mock_send.reset_mock() + mock_send.return_value = Response( + 200, json={}, request=Request('PATCH', '') + ) + client.webhooks.update( + id=webhook_id, + name='updated-webhook', + ) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks/{webhook_id}' + + # 5. Ping Webhook + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('POST', '')) + client.webhooks.ping(id=webhook_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks/{webhook_id}:ping' + + # 6. Rotate Signing Secret + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('POST', '')) + client.webhooks.rotate_signing_secret(id=webhook_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert ( + str(request.url) + == f'{expected_base_url}/webhooks/{webhook_id}:rotateSigningSecret' + ) + + # 7. Delete Webhook + mock_send.reset_mock() + mock_send.return_value = Response( + 200, json={}, request=Request('DELETE', '') + ) + client.webhooks.delete(id=webhook_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks/{webhook_id}' + + +@pytest.mark.asyncio +@mock.patch.object(google.auth, 'default', autospec=True) +async def test_async_urls(mock_auth_default, client): + webhook_id = 'test-webhook-id' + + mock_creds = mock.Mock() + mock_creds.token = 'test-token' + mock_creds.expired = False + mock_creds.quota_project_id = 'test-quota-project' + mock_auth_default.return_value = (mock_creds, 'test-project') + + if client._api_client.vertexai: + if client._api_client.location == 'global': + expected_base_url = f'https://aiplatform.googleapis.com/v1beta1/projects/{client._api_client.project}/locations/global' + else: + expected_base_url = f'https://{client._api_client.location}-aiplatform.googleapis.com/v1beta1/projects/{client._api_client.project}/locations/{client._api_client.location}' + else: + expected_base_url = 'https://generativelanguage.googleapis.com/v1beta' + + with mock.patch.object(AsyncHttpxClient, 'send') as mock_send: + # 1. Create Webhook + mock_send.return_value = Response(200, json={}, request=Request('POST', '')) + await client.aio.webhooks.create( + subscribed_events=['batch.succeeded'], + uri='https://example.com/webhook', + name='test-webhook', + ) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks' + + # 2. Get Webhook + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('GET', '')) + await client.aio.webhooks.get(id=webhook_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks/{webhook_id}' + + # 3. List Webhooks + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('GET', '')) + await client.aio.webhooks.list() + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks' + + # 4. Update Webhook + mock_send.reset_mock() + mock_send.return_value = Response( + 200, json={}, request=Request('PATCH', '') + ) + await client.aio.webhooks.update( + id=webhook_id, + name='updated-webhook', + ) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks/{webhook_id}' + + # 5. Ping Webhook + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('POST', '')) + await client.aio.webhooks.ping(id=webhook_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks/{webhook_id}:ping' + + # 6. Rotate Signing Secret + mock_send.reset_mock() + mock_send.return_value = Response(200, json={}, request=Request('POST', '')) + await client.aio.webhooks.rotate_signing_secret(id=webhook_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert ( + str(request.url) + == f'{expected_base_url}/webhooks/{webhook_id}:rotateSigningSecret' + ) + + # 7. Delete Webhook + mock_send.reset_mock() + mock_send.return_value = Response( + 200, json={}, request=Request('DELETE', '') + ) + await client.aio.webhooks.delete(id=webhook_id) + mock_send.assert_called_once() + request = mock_send.call_args[0][0] + assert str(request.url) == f'{expected_base_url}/webhooks/{webhook_id}' + + +pytestmark = pytest_helper.setup( + file=__file__, + globals_for_file=globals(), + test_table=[], +)