From 29df8a380fa2c7e233b31025657a5b4ae2320bc9 Mon Sep 17 00:00:00 2001 From: Google Team Member Date: Thu, 4 Jun 2026 10:54:59 -0700 Subject: [PATCH] feat(interaction-api): Add safety_settings and labels to interaction.proto PiperOrigin-RevId: 926775718 --- .../_interactions/resources/interactions.py | 130 +++++++++++++++++- .../genai/_interactions/types/interaction.py | 54 ++++++++ .../types/interaction_create_params.py | 75 +++++++++- 3 files changed, 257 insertions(+), 2 deletions(-) diff --git a/google/genai/_interactions/resources/interactions.py b/google/genai/_interactions/resources/interactions.py index 12846a423..65ff4b370 100644 --- a/google/genai/_interactions/resources/interactions.py +++ b/google/genai/_interactions/resources/interactions.py @@ -17,7 +17,7 @@ from __future__ import annotations -from typing import List, Union, Iterable +from typing import Dict, List, Union, Iterable from typing_extensions import Literal, overload import httpx @@ -83,10 +83,12 @@ def create( cached_content: str | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Omit = omit, @@ -121,6 +123,14 @@ def create( generation_config: Input only. Configuration parameters for the model interaction. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -130,6 +140,8 @@ def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -165,10 +177,12 @@ def create( cached_content: str | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -204,6 +218,14 @@ def create( generation_config: Input only. Configuration parameters for the model interaction. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -213,6 +235,8 @@ def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -252,10 +276,12 @@ def create( agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Omit = omit, @@ -284,6 +310,14 @@ def create( environment: The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -293,6 +327,8 @@ def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -335,10 +371,12 @@ def create( agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -368,6 +406,14 @@ def create( environment: The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -377,6 +423,8 @@ def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -410,10 +458,12 @@ def create( cached_content: str | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -449,6 +499,14 @@ def create( generation_config: Input only. Configuration parameters for the model interaction. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -458,6 +516,8 @@ def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -490,10 +550,12 @@ def create( cached_content: str | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Literal[True] | Omit = omit, @@ -551,10 +613,12 @@ def create( "cached_content": cached_content, "environment": environment, "generation_config": generation_config, + "labels": labels, "previous_interaction_id": previous_interaction_id, "response_format": response_format, "response_mime_type": response_mime_type, "response_modalities": response_modalities, + "safety_settings": safety_settings, "service_tier": service_tier, "store": store, "stream": stream, @@ -853,10 +917,12 @@ async def create( cached_content: str | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Omit = omit, @@ -891,6 +957,14 @@ async def create( generation_config: Input only. Configuration parameters for the model interaction. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -900,6 +974,8 @@ async def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -935,10 +1011,12 @@ async def create( cached_content: str | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -974,6 +1052,14 @@ async def create( generation_config: Input only. Configuration parameters for the model interaction. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -983,6 +1069,8 @@ async def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -1022,10 +1110,12 @@ async def create( agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Omit = omit, @@ -1054,6 +1144,14 @@ async def create( environment: The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -1063,6 +1161,8 @@ async def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -1105,10 +1205,12 @@ async def create( agent_config: interaction_create_params.AgentConfig | Omit = omit, background: bool | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -1138,6 +1240,14 @@ async def create( environment: The environment configuration for the interaction. Can be an object specifying remote environment sources or a string referencing an existing environment ID. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -1147,6 +1257,8 @@ async def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -1180,10 +1292,12 @@ async def create( cached_content: str | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, system_instruction: str | Omit = omit, @@ -1219,6 +1333,14 @@ async def create( generation_config: Input only. Configuration parameters for the model interaction. + labels: Optional. The labels with user-defined metadata for the request. It is used for + billing and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + 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 @@ -1228,6 +1350,8 @@ async def create( response_modalities: The requested modalities of the response (TEXT, IMAGE, AUDIO). + safety_settings: Safety settings for the interaction. + service_tier: The service tier for the interaction. store: Input only. Whether to store the response and request for later retrieval. @@ -1260,10 +1384,12 @@ async def create( cached_content: str | Omit = omit, environment: interaction_create_params.Environment | Omit = omit, generation_config: GenerationConfigParam | Omit = omit, + labels: Dict[str, str] | 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, + safety_settings: Iterable[interaction_create_params.SafetySetting] | Omit = omit, service_tier: Literal["flex", "standard", "priority"] | Omit = omit, store: bool | Omit = omit, stream: Literal[False] | Literal[True] | Omit = omit, @@ -1317,10 +1443,12 @@ async def create( "cached_content": cached_content, "environment": environment, "generation_config": generation_config, + "labels": labels, "previous_interaction_id": previous_interaction_id, "response_format": response_format, "response_mime_type": response_mime_type, "response_modalities": response_modalities, + "safety_settings": safety_settings, "service_tier": service_tier, "store": store, "stream": stream, diff --git a/google/genai/_interactions/types/interaction.py b/google/genai/_interactions/types/interaction.py index 41c241f2b..e737df782 100644 --- a/google/genai/_interactions/types/interaction.py +++ b/google/genai/_interactions/types/interaction.py @@ -55,6 +55,7 @@ "Input", "ResponseFormat", "ResponseFormatResponseFormatList", + "SafetySetting", ] @@ -217,6 +218,44 @@ class AgentConfigFixRequest(BaseModel): ] +class SafetySetting(BaseModel): + """A safety setting that affects the safety-blocking behavior. + + A SafetySetting consists of a + harm category and a + threshold for that + category. + """ + + category: Literal[ + "hate_speech", + "dangerous_content", + "harassment", + "sexually_explicit", + "civic_integrity", + "image_hate", + "image_dangerous_content", + "image_harassment", + "image_sexually_explicit", + "jailbreak", + ] + """Required. The harm category to be blocked.""" + + threshold: Literal["block_low_and_above", "block_medium_and_above", "block_only_high", "block_none", "off"] + """Required. + + The threshold for blocking content. If the harm probability exceeds this + threshold, the content will be blocked. + """ + + method: Optional[Literal["severity", "probability"]] = None + """Optional. + + The method for blocking content. If not specified, the default behavior is to + use the probability score. + """ + + class Interaction(BaseModel): """The Interaction resource.""" @@ -285,6 +324,18 @@ class Interaction(BaseModel): input: Optional[Input] = None """The input for the interaction.""" + labels: Optional[Dict[str, str]] = None + """Optional. + + The labels with user-defined metadata for the request. It is used for billing + and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + """ + model: Optional[Model] = None """The name of the `Model` used for generating the interaction.""" @@ -306,6 +357,9 @@ class Interaction(BaseModel): role: Optional[str] = None """Output only. The role of the interaction.""" + safety_settings: Optional[List[SafetySetting]] = None + """Safety settings for the interaction.""" + service_tier: Optional[Literal["flex", "standard", "priority"]] = None """The service tier for the interaction.""" diff --git a/google/genai/_interactions/types/interaction_create_params.py b/google/genai/_interactions/types/interaction_create_params.py index 12d35cc51..84f14eeb4 100644 --- a/google/genai/_interactions/types/interaction_create_params.py +++ b/google/genai/_interactions/types/interaction_create_params.py @@ -17,7 +17,7 @@ from __future__ import annotations -from typing import List, Union, Iterable +from typing import Dict, List, Union, Iterable from typing_extensions import Literal, Required, TypeAlias, TypedDict from .step_param import StepParam @@ -44,6 +44,7 @@ "Environment", "ResponseFormat", "ResponseFormatResponseFormatList", + "SafetySetting", "BaseCreateAgentInteractionParams", "AgentConfig", "AgentConfigFindRequest", @@ -89,6 +90,18 @@ class BaseCreateModelInteractionParams(TypedDict, total=False): generation_config: GenerationConfigParam """Input only. Configuration parameters for the model interaction.""" + labels: Dict[str, str] + """Optional. + + The labels with user-defined metadata for the request. It is used for billing + and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + """ + previous_interaction_id: str """The ID of the previous interaction, if any.""" @@ -104,6 +117,9 @@ class BaseCreateModelInteractionParams(TypedDict, total=False): response_modalities: List[Literal["text", "image", "audio", "video", "document"]] """The requested modalities of the response (TEXT, IMAGE, AUDIO).""" + safety_settings: Iterable[SafetySetting] + """Safety settings for the interaction.""" + service_tier: Literal["flex", "standard", "priority"] """The service tier for the interaction.""" @@ -150,6 +166,48 @@ class BaseCreateModelInteractionParams(TypedDict, total=False): ] +class SafetySetting(TypedDict, total=False): + """A safety setting that affects the safety-blocking behavior. + + A SafetySetting consists of a + harm category and a + threshold for that + category. + """ + + category: Required[ + Literal[ + "hate_speech", + "dangerous_content", + "harassment", + "sexually_explicit", + "civic_integrity", + "image_hate", + "image_dangerous_content", + "image_harassment", + "image_sexually_explicit", + "jailbreak", + ] + ] + """Required. The harm category to be blocked.""" + + threshold: Required[ + Literal["block_low_and_above", "block_medium_and_above", "block_only_high", "block_none", "off"] + ] + """Required. + + The threshold for blocking content. If the harm probability exceeds this + threshold, the content will be blocked. + """ + + method: Literal["severity", "probability"] + """Optional. + + The method for blocking content. If not specified, the default behavior is to + use the probability score. + """ + + class BaseCreateAgentInteractionParams(TypedDict, total=False): api_version: str @@ -182,6 +240,18 @@ class BaseCreateAgentInteractionParams(TypedDict, total=False): an existing environment ID. """ + labels: Dict[str, str] + """Optional. + + The labels with user-defined metadata for the request. It is used for billing + and reporting only. + + Label keys and values can be no longer than 63 characters (Unicode codepoints) + and can only contain lowercase letters, numeric characters, underscores, and + dashes. International characters are allowed. Label values are optional. Label + keys must start with a letter. + """ + previous_interaction_id: str """The ID of the previous interaction, if any.""" @@ -197,6 +267,9 @@ class BaseCreateAgentInteractionParams(TypedDict, total=False): response_modalities: List[Literal["text", "image", "audio", "video", "document"]] """The requested modalities of the response (TEXT, IMAGE, AUDIO).""" + safety_settings: Iterable[SafetySetting] + """Safety settings for the interaction.""" + service_tier: Literal["flex", "standard", "priority"] """The service tier for the interaction."""