Service Client: Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerativeServiceClient

Client stub representing the remote GenerativeService gRPC service. Delegates call dispatching to Google::gRPC::Client.

target

The endpoint target address. Defaults to ai.googleapis.com:443.

credentials

The authentication credentials provider. Defaults to application default credentials via Google::Auth.

NAME

Google::Ai::Generativelanguage::V1beta::GenerativeService - Compiled Protocol Buffers messages for google/ai/generativelanguage/v1beta/generative_service.proto

SYNOPSIS

use Google::Ai::Generativelanguage::V1beta::GenerativeService;

my $msg = Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerateContentRequest->new({
    model => $model,
    system_instruction => $system_instruction,
    contents => $contents,
    tools => $tools,
});

# Read or update a field
my $val = $msg->model();

# Binary wire-format roundtrip
my $bytes   = $msg->serialize();
my $decoded = Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerateContentRequest->parse($bytes);

# Canonical ProtoJSON
my $json = $msg->to_json();

DESCRIPTION

Auto-generated Protobuf message classes compiled from google/ai/generativelanguage/v1beta/generative_service.proto. All message classes inherit from Protobuf::Message and support new(), serialize(), parse(), to_json(), from_json(), to_text(), and to_perl().

MESSAGES

Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerateContentRequest

Request to generate a completion from the model.

Inherits from Protobuf::Message.

Accessors

  • $msg->model() / $msg->model($value)

    Type: String

    Required. The name of the `Model` to use for generating the completion.

    Format: `models/{model}`.

  • $msg->system_instruction() / $msg->system_instruction($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Content)

    Optional. Developer set [system instruction(s)](https://ai.google.dev/gemini-api/docs/system-instructions). Currently, text only.

  • $msg->contents() / $msg->contents($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Content)

    Required. The content of the current conversation with the model.

    For single-turn queries, this is a single instance. For multi-turn queries like [chat](https://ai.google.dev/gemini-api/docs/text-generation#chat), this is a repeated field that contains the conversation history and the latest request.

  • $msg->tools() / $msg->tools($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Tool)

    Optional. A list of `Tools` the `Model` may use to generate the next response.

    A `Tool` is a piece of code that enables the system to interact with external systems to perform an action, or set of actions, outside of knowledge and scope of the `Model`. Supported `Tool`s are `Function` and `code_execution`. Refer to the [Function calling](https://ai.google.dev/gemini-api/docs/function-calling) and the [Code execution](https://ai.google.dev/gemini-api/docs/code-execution) guides to learn more.

  • $msg->tool_config() / $msg->tool_config($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::ToolConfig)

    Optional. Tool configuration for any `Tool` specified in the request. Refer to the [Function calling guide](https://ai.google.dev/gemini-api/docs/function-calling#function_calling_mode) for a usage example.

  • $msg->safety_settings() / $msg->safety_settings($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Safety::SafetySetting)

    Optional. A list of unique `SafetySetting` instances for blocking unsafe content.

    This will be enforced on the `GenerateContentRequest.contents` and `GenerateContentResponse.candidates`. There should not be more than one setting for each `SafetyCategory` type. The API will block any contents and responses that fail to meet the thresholds set by these settings. This list overrides the default settings for each `SafetyCategory` specified in the safety_settings. If there is no `SafetySetting` for a given `SafetyCategory` provided in the list, the API will use the default safety setting for that category. Harm categories HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT, HARM_CATEGORY_HARASSMENT, HARM_CATEGORY_CIVIC_INTEGRITY are supported. Refer to the [guide](https://ai.google.dev/gemini-api/docs/safety-settings) for detailed information on available safety settings. Also refer to the [Safety guidance](https://ai.google.dev/gemini-api/docs/safety-guidance) to learn how to incorporate safety considerations in your AI applications.

  • $msg->generation_config() / $msg->generation_config($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerationConfig)

    Optional. Configuration options for model generation and outputs.

  • $msg->cached_content() / $msg->cached_content($value)

    Type: String

    Optional. The name of the content [cached](https://ai.google.dev/gemini-api/docs/caching) to use as context to serve the prediction. Format: `cachedContents/{cachedContent}`

Google::Ai::Generativelanguage::V1beta::GenerativeService::PrebuiltVoiceConfig

The configuration for the prebuilt speaker to use.

Inherits from Protobuf::Message.

Accessors

  • $msg->voice_name() / $msg->voice_name($value)

    Type: String

    The name of the preset voice to use.

Google::Ai::Generativelanguage::V1beta::GenerativeService::VoiceConfig

The configuration for the voice to use.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::SpeakerVoiceConfig

The configuration for a single speaker in a multi speaker setup.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::MultiSpeakerVoiceConfig

The configuration for the multi-speaker setup.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::SpeechConfig

The speech generation config.

Inherits from Protobuf::Message.

Accessors

  • $msg->voice_config() / $msg->voice_config($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::VoiceConfig)

    The configuration in case of single-voice output.

  • $msg->multi_speaker_voice_config() / $msg->multi_speaker_voice_config($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::MultiSpeakerVoiceConfig)

    Optional. The configuration for the multi-speaker setup. It is mutually exclusive with the voice_config field.

  • $msg->language_code() / $msg->language_code($value)

    Type: String

    Optional. Language code (in BCP 47 format, e.g. "en-US") for speech synthesis.

    Valid values are: de-DE, en-AU, en-GB, en-IN, en-US, es-US, fr-FR, hi-IN, pt-BR, ar-XA, es-ES, fr-CA, id-ID, it-IT, ja-JP, tr-TR, vi-VN, bn-IN, gu-IN, kn-IN, ml-IN, mr-IN, ta-IN, te-IN, nl-NL, ko-KR, cmn-CN, pl-PL, ru-RU, and th-TH.

Google::Ai::Generativelanguage::V1beta::GenerativeService::ThinkingConfig

Config for thinking features.

Inherits from Protobuf::Message.

Accessors

  • $msg->include_thoughts() / $msg->include_thoughts($value)

    Type: Bool

    Indicates whether to include thoughts in the response. If true, thoughts are returned only when available.

  • $msg->thinking_budget() / $msg->thinking_budget($value)

    Type: Int32

    The number of thoughts tokens that the model should generate.

Google::Ai::Generativelanguage::V1beta::GenerativeService::ImageConfig

Config for image generation features.

Inherits from Protobuf::Message.

Accessors

  • $msg->aspect_ratio() / $msg->aspect_ratio($value)

    Type: String

    Optional. The aspect ratio of the image to generate. Supported aspect ratios: 1:1, 2:3, 3:2, 3:4, 4:3, 9:16, 16:9, 21:9.

    If not specified, the model will choose a default aspect ratio based on any reference images provided.

Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerationConfig

Configuration options for model generation and outputs. Not all parameters are configurable for every model.

Inherits from Protobuf::Message.

Accessors

  • $msg->candidate_count() / $msg->candidate_count($value)

    Type: Int32

    Optional. Number of generated responses to return. If unset, this will default to 1. Please note that this doesn't work for previous generation models (Gemini 1.0 family)

  • $msg->stop_sequences() / $msg->stop_sequences($value)

    Type: String

    Optional. The set of character sequences (up to 5) that will stop output generation. If specified, the API will stop at the first appearance of a `stop_sequence`. The stop sequence will not be included as part of the response.

  • $msg->max_output_tokens() / $msg->max_output_tokens($value)

    Type: Int32

    Optional. The maximum number of tokens to include in a response candidate.

    Note: The default value varies by model, see the `Model.output_token_limit` attribute of the `Model` returned from the `getModel` function.

  • $msg->temperature() / $msg->temperature($value)

    Type: Float

    Optional. Controls the randomness of the output.

    Note: The default value varies by model, see the `Model.temperature` attribute of the `Model` returned from the `getModel` function.

    Values can range from [0.0, 2.0].

  • $msg->top_p() / $msg->top_p($value)

    Type: Float

    Optional. The maximum cumulative probability of tokens to consider when sampling.

    The model uses combined Top-k and Top-p (nucleus) sampling.

    Tokens are sorted based on their assigned probabilities so that only the most likely tokens are considered. Top-k sampling directly limits the maximum number of tokens to consider, while Nucleus sampling limits the number of tokens based on the cumulative probability.

    Note: The default value varies by `Model` and is specified by the`Model.top_p` attribute returned from the `getModel` function. An empty `top_k` attribute indicates that the model doesn't apply top-k sampling and doesn't allow setting `top_k` on requests.

  • $msg->top_k() / $msg->top_k($value)

    Type: Int32

    Optional. The maximum number of tokens to consider when sampling.

    Gemini models use Top-p (nucleus) sampling or a combination of Top-k and nucleus sampling. Top-k sampling considers the set of `top_k` most probable tokens. Models running with nucleus sampling don't allow top_k setting.

    Note: The default value varies by `Model` and is specified by the`Model.top_p` attribute returned from the `getModel` function. An empty `top_k` attribute indicates that the model doesn't apply top-k sampling and doesn't allow setting `top_k` on requests.

  • $msg->seed() / $msg->seed($value)

    Type: Int32

    Optional. Seed used in decoding. If not set, the request uses a randomly generated seed.

  • $msg->response_mime_type() / $msg->response_mime_type($value)

    Type: String

    Optional. MIME type of the generated candidate text. Supported MIME types are: `text/plain`: (default) Text output. `application/json`: JSON response in the response candidates. `text/x.enum`: ENUM as a string response in the response candidates. Refer to the [docs](https://ai.google.dev/gemini-api/docs/prompting_with_media#plain_text_formats) for a list of all supported text MIME types.

  • $msg->response_schema() / $msg->response_schema($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Schema)

    Optional. Output schema of the generated candidate text. Schemas must be a subset of the [OpenAPI schema](https://spec.openapis.org/oas/v3.0.3#schema) and can be objects, primitives or arrays.

    If set, a compatible `response_mime_type` must also be set. Compatible MIME types: `application/json`: Schema for JSON response. Refer to the [JSON text generation guide](https://ai.google.dev/gemini-api/docs/json-mode) for more details.

  • $msg->response_json_schema() / $msg->response_json_schema($value)

    Type: Message (Google::Protobuf::Struct::Value)

    Optional. Output schema of the generated response. This is an alternative to `response_schema` that accepts [JSON Schema](https://json-schema.org/).

    If set, `response_schema` must be omitted, but `response_mime_type` is required.

    While the full JSON Schema may be sent, not all features are supported. Specifically, only the following properties are supported:

    - `$id` - `$defs` - `$ref` - `$anchor` - `type` - `format` - `title` - `description` - `enum` (for strings and numbers) - `items` - `prefixItems` - `minItems` - `maxItems` - `minimum` - `maximum` - `anyOf` - `oneOf` (interpreted the same as `anyOf`) - `properties` - `additionalProperties` - `required`

    The non-standard `propertyOrdering` property may also be set.

    Cyclic references are unrolled to a limited degree and, as such, may only be used within non-required properties. (Nullable properties are not sufficient.) If `$ref` is set on a sub-schema, no other properties, except for than those starting as a `$`, may be set.

  • $msg->response_json_schema_ordered() / $msg->response_json_schema_ordered($value)

    Type: Message (Google::Protobuf::Struct::Value)

    Optional. An internal detail. Use `responseJsonSchema` rather than this field.

  • $msg->presence_penalty() / $msg->presence_penalty($value)

    Type: Float

    Optional. Presence penalty applied to the next token's logprobs if the token has already been seen in the response.

    This penalty is binary on/off and not dependant on the number of times the token is used (after the first). Use [frequency_penalty][google.ai.generativelanguage.v1beta.GenerationConfig.frequency_penalty] for a penalty that increases with each use.

    A positive penalty will discourage the use of tokens that have already been used in the response, increasing the vocabulary.

    A negative penalty will encourage the use of tokens that have already been used in the response, decreasing the vocabulary.

  • $msg->frequency_penalty() / $msg->frequency_penalty($value)

    Type: Float

    Optional. Frequency penalty applied to the next token's logprobs, multiplied by the number of times each token has been seen in the respponse so far.

    A positive penalty will discourage the use of tokens that have already been used, proportional to the number of times the token has been used: The more a token is used, the more difficult it is for the model to use that token again increasing the vocabulary of responses.

    Caution: A _negative_ penalty will encourage the model to reuse tokens proportional to the number of times the token has been used. Small negative values will reduce the vocabulary of a response. Larger negative values will cause the model to start repeating a common token until it hits the [max_output_tokens][google.ai.generativelanguage.v1beta.GenerationConfig.max_output_tokens] limit.

  • $msg->response_logprobs() / $msg->response_logprobs($value)

    Type: Bool

    Optional. If true, export the logprobs results in response.

  • $msg->logprobs() / $msg->logprobs($value)

    Type: Int32

    Optional. Only valid if [response_logprobs=True][google.ai.generativelanguage.v1beta.GenerationConfig.response_logprobs]. This sets the number of top logprobs to return at each decoding step in the [Candidate.logprobs_result][google.ai.generativelanguage.v1beta.Candidate.logprobs_result]. The number must be in the range of [0, 20].

  • $msg->enable_enhanced_civic_answers() / $msg->enable_enhanced_civic_answers($value)

    Type: Bool

    Optional. Enables enhanced civic answers. It may not be available for all models.

  • $msg->response_modalities() / $msg->response_modalities($value)

    Type: Enum (Google::Ai::Generativelanguage::V1beta::GenerationConfig::Modality)

    Optional. The requested modalities of the response. Represents the set of modalities that the model can return, and should be expected in the response. This is an exact match to the modalities of the response.

    A model may have multiple combinations of supported modalities. If the requested modalities do not match any of the supported combinations, an error will be returned.

    An empty list is equivalent to requesting only text.

  • $msg->speech_config() / $msg->speech_config($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::SpeechConfig)

    Optional. The speech generation config.

  • $msg->thinking_config() / $msg->thinking_config($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::ThinkingConfig)

    Optional. Config for thinking features. An error will be returned if this field is set for models that don't support thinking.

  • $msg->image_config() / $msg->image_config($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::ImageConfig)

    Optional. Config for image generation. An error will be returned if this field is set for models that don't support these config options.

  • $msg->media_resolution() / $msg->media_resolution($value)

    Type: Enum (Google::Ai::Generativelanguage::V1beta::GenerationConfig::MediaResolution)

    Optional. If specified, the media resolution specified will be used.

Enum: GenerationConfig::Modality

  • MODALITY_UNSPECIFIED => 0

  • TEXT => 1

  • IMAGE => 2

  • AUDIO => 3

Enum: GenerationConfig::MediaResolution

  • MEDIA_RESOLUTION_UNSPECIFIED => 0

  • MEDIA_RESOLUTION_LOW => 1

  • MEDIA_RESOLUTION_MEDIUM => 2

  • MEDIA_RESOLUTION_HIGH => 3

Google::Ai::Generativelanguage::V1beta::GenerativeService::SemanticRetrieverConfig

Configuration for retrieving grounding content from a `Corpus` or `Document` created using the Semantic Retriever API.

Inherits from Protobuf::Message.

Accessors

  • $msg->source() / $msg->source($value)

    Type: String

    Required. Name of the resource for retrieval. Example: `corpora/123` or `corpora/123/documents/abc`.

  • $msg->query() / $msg->query($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Content)

    Required. Query to use for matching `Chunk`s in the given resource by similarity.

  • $msg->metadata_filters() / $msg->metadata_filters($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Retriever::MetadataFilter)

    Optional. Filters for selecting `Document`s and/or `Chunk`s from the resource.

  • $msg->max_chunks_count() / $msg->max_chunks_count($value)

    Type: Int32

    Optional. Maximum number of relevant `Chunk`s to retrieve.

  • $msg->minimum_relevance_score() / $msg->minimum_relevance_score($value)

    Type: Float

    Optional. Minimum relevance score for retrieved relevant `Chunk`s.

Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerateContentResponse

Response from the model supporting multiple candidate responses.

Safety ratings and content filtering are reported for both prompt in `GenerateContentResponse.prompt_feedback` and for each candidate in `finish_reason` and in `safety_ratings`. The API: - Returns either all requested candidates or none of them - Returns no candidates at all only if there was something wrong with the prompt (check `prompt_feedback`) - Reports feedback on each candidate in `finish_reason` and `safety_ratings`.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::Candidate

A response candidate generated from the model.

Inherits from Protobuf::Message.

Accessors

Enum: Candidate::FinishReason

  • FINISH_REASON_UNSPECIFIED => 0

  • STOP => 1

  • MAX_TOKENS => 2

  • SAFETY => 3

  • RECITATION => 4

  • LANGUAGE => 6

  • OTHER => 5

  • BLOCKLIST => 7

  • PROHIBITED_CONTENT => 8

  • SPII => 9

  • MALFORMED_FUNCTION_CALL => 10

  • IMAGE_SAFETY => 11

  • IMAGE_PROHIBITED_CONTENT => 14

  • IMAGE_OTHER => 15

  • NO_IMAGE => 16

  • IMAGE_RECITATION => 17

  • UNEXPECTED_TOOL_CALL => 12

  • TOO_MANY_TOOL_CALLS => 13

Google::Ai::Generativelanguage::V1beta::GenerativeService::UrlContextMetadata

Metadata related to url context retrieval tool.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::UrlMetadata

Context of the a single url retrieval.

Inherits from Protobuf::Message.

Accessors

Enum: UrlMetadata::UrlRetrievalStatus

  • URL_RETRIEVAL_STATUS_UNSPECIFIED => 0

  • URL_RETRIEVAL_STATUS_SUCCESS => 1

  • URL_RETRIEVAL_STATUS_ERROR => 2

  • URL_RETRIEVAL_STATUS_PAYWALL => 3

  • URL_RETRIEVAL_STATUS_UNSAFE => 4

Google::Ai::Generativelanguage::V1beta::GenerativeService::LogprobsResult

Logprobs Result

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::AttributionSourceId

Identifier for the source contributing to this attribution.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::GroundingAttribution

Attribution for a source that contributed to an answer.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::RetrievalMetadata

Metadata related to retrieval in the grounding flow.

Inherits from Protobuf::Message.

Accessors

  • $msg->google_search_dynamic_retrieval_score() / $msg->google_search_dynamic_retrieval_score($value)

    Type: Float

    Optional. Score indicating how likely information from google search could help answer the prompt. The score is in the range [0, 1], where 0 is the least likely and 1 is the most likely. This score is only populated when google search grounding and dynamic retrieval is enabled. It will be compared to the threshold to determine whether to trigger google search.

Google::Ai::Generativelanguage::V1beta::GenerativeService::GroundingMetadata

Metadata returned to client when grounding is enabled.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::SearchEntryPoint

Google search entry point.

Inherits from Protobuf::Message.

Accessors

  • $msg->rendered_content() / $msg->rendered_content($value)

    Type: String

    Optional. Web content snippet that can be embedded in a web page or an app webview.

  • $msg->sdk_blob() / $msg->sdk_blob($value)

    Type: Bytes

    Optional. Base64 encoded JSON representing array of <search term, search url> tuple.

Google::Ai::Generativelanguage::V1beta::GenerativeService::GroundingChunk

Grounding chunk.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::Segment

Segment of the content.

Inherits from Protobuf::Message.

Accessors

  • $msg->part_index() / $msg->part_index($value)

    Type: Int32

    Output only. The index of a Part object within its parent Content object.

  • $msg->start_index() / $msg->start_index($value)

    Type: Int32

    Output only. Start index in the given Part, measured in bytes. Offset from the start of the Part, inclusive, starting at zero.

  • $msg->end_index() / $msg->end_index($value)

    Type: Int32

    Output only. End index in the given Part, measured in bytes. Offset from the start of the Part, exclusive, starting at zero.

  • $msg->text() / $msg->text($value)

    Type: String

    Output only. The text corresponding to the segment from the response.

Google::Ai::Generativelanguage::V1beta::GenerativeService::GroundingSupport

Grounding support.

Inherits from Protobuf::Message.

Accessors

  • $msg->segment() / $msg->segment($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::Segment)

    Segment of the content this support belongs to.

  • $msg->grounding_chunk_indices() / $msg->grounding_chunk_indices($value)

    Type: Int32

    A list of indices (into 'grounding_chunk') specifying the citations associated with the claim. For instance [1,3,4] means that grounding_chunk[1], grounding_chunk[3], grounding_chunk[4] are the retrieved content attributed to the claim.

  • $msg->confidence_scores() / $msg->confidence_scores($value)

    Type: Float

    Confidence score of the support references. Ranges from 0 to 1. 1 is the most confident. This list must have the same size as the grounding_chunk_indices.

Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerateAnswerRequest

Request to generate a grounded answer from the `Model`.

Inherits from Protobuf::Message.

Accessors

  • $msg->inline_passages() / $msg->inline_passages($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::GroundingPassages)

    Passages provided inline with the request.

  • $msg->semantic_retriever() / $msg->semantic_retriever($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::SemanticRetrieverConfig)

    Content retrieved from resources created via the Semantic Retriever API.

  • $msg->model() / $msg->model($value)

    Type: String

    Required. The name of the `Model` to use for generating the grounded response.

    Format: `model=models/{model}`.

  • $msg->contents() / $msg->contents($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Content)

    Required. The content of the current conversation with the `Model`. For single-turn queries, this is a single question to answer. For multi-turn queries, this is a repeated field that contains conversation history and the last `Content` in the list containing the question.

    Note: `GenerateAnswer` only supports queries in English.

  • $msg->answer_style() / $msg->answer_style($value)

    Type: Enum (Google::Ai::Generativelanguage::V1beta::GenerateAnswerRequest::AnswerStyle)

    Required. Style in which answers should be returned.

  • $msg->safety_settings() / $msg->safety_settings($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Safety::SafetySetting)

    Optional. A list of unique `SafetySetting` instances for blocking unsafe content.

    This will be enforced on the `GenerateAnswerRequest.contents` and `GenerateAnswerResponse.candidate`. There should not be more than one setting for each `SafetyCategory` type. The API will block any contents and responses that fail to meet the thresholds set by these settings. This list overrides the default settings for each `SafetyCategory` specified in the safety_settings. If there is no `SafetySetting` for a given `SafetyCategory` provided in the list, the API will use the default safety setting for that category. Harm categories HARM_CATEGORY_HATE_SPEECH, HARM_CATEGORY_SEXUALLY_EXPLICIT, HARM_CATEGORY_DANGEROUS_CONTENT, HARM_CATEGORY_HARASSMENT are supported. Refer to the [guide](https://ai.google.dev/gemini-api/docs/safety-settings) for detailed information on available safety settings. Also refer to the [Safety guidance](https://ai.google.dev/gemini-api/docs/safety-guidance) to learn how to incorporate safety considerations in your AI applications.

  • $msg->temperature() / $msg->temperature($value)

    Type: Float

    Optional. Controls the randomness of the output.

    Values can range from [0.0,1.0], inclusive. A value closer to 1.0 will produce responses that are more varied and creative, while a value closer to 0.0 will typically result in more straightforward responses from the model. A low temperature (~0.2) is usually recommended for Attributed-Question-Answering use cases.

Enum: GenerateAnswerRequest::AnswerStyle

  • ANSWER_STYLE_UNSPECIFIED => 0

  • ABSTRACTIVE => 1

  • EXTRACTIVE => 2

  • VERBOSE => 3

Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerateAnswerResponse

Response from the model for a grounded answer.

Inherits from Protobuf::Message.

Accessors

  • $msg->answer() / $msg->answer($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::Candidate)

    Candidate answer from the model.

    Note: The model *always* attempts to provide a grounded answer, even when the answer is unlikely to be answerable from the given passages. In that case, a low-quality or ungrounded answer may be provided, along with a low `answerable_probability`.

  • $msg->answerable_probability() / $msg->answerable_probability($value)

    Type: Float

    Output only. The model's estimate of the probability that its answer is correct and grounded in the input passages.

    A low `answerable_probability` indicates that the answer might not be grounded in the sources.

    When `answerable_probability` is low, you may want to:

    * Display a message to the effect of "We couldn’t answer that question" to the user. * Fall back to a general-purpose LLM that answers the question from world knowledge. The threshold and nature of such fallbacks will depend on individual use cases. `0.5` is a good starting threshold.

  • $msg->input_feedback() / $msg->input_feedback($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerateAnswerResponse::InputFeedback)

    Output only. Feedback related to the input data used to answer the question, as opposed to the model-generated response to the question.

    The input data can be one or more of the following:

    - Question specified by the last entry in `GenerateAnswerRequest.content` - Conversation history specified by the other entries in `GenerateAnswerRequest.content` - Grounding sources (`GenerateAnswerRequest.semantic_retriever` or `GenerateAnswerRequest.inline_passages`)

Google::Ai::Generativelanguage::V1beta::GenerativeService::EmbedContentRequest

Request containing the `Content` for the model to embed.

Inherits from Protobuf::Message.

Accessors

  • $msg->model() / $msg->model($value)

    Type: String

    Required. The model's resource name. This serves as an ID for the Model to use.

    This name should match a model name returned by the `ListModels` method.

    Format: `models/{model}`

  • $msg->content() / $msg->content($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Content)

    Required. The content to embed. Only the `parts.text` fields will be counted.

  • $msg->task_type() / $msg->task_type($value)

    Type: Enum (Google::Ai::Generativelanguage::V1beta::TaskType)

    Optional. Optional task type for which the embeddings will be used. Not supported on earlier models (`models/embedding-001`).

  • $msg->title() / $msg->title($value)

    Type: String

    Optional. An optional title for the text. Only applicable when TaskType is `RETRIEVAL_DOCUMENT`.

    Note: Specifying a `title` for `RETRIEVAL_DOCUMENT` provides better quality embeddings for retrieval.

  • $msg->output_dimensionality() / $msg->output_dimensionality($value)

    Type: Int32

    Optional. Optional reduced dimension for the output embedding. If set, excessive values in the output embedding are truncated from the end. Supported by newer models since 2024 only. You cannot set this value if using the earlier model (`models/embedding-001`).

Google::Ai::Generativelanguage::V1beta::GenerativeService::ContentEmbedding

A list of floats representing an embedding.

Inherits from Protobuf::Message.

Accessors

  • $msg->values() / $msg->values($value)

    Type: Float

    The embedding values.

Google::Ai::Generativelanguage::V1beta::GenerativeService::EmbedContentResponse

The response to an `EmbedContentRequest`.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::BatchEmbedContentsRequest

Batch request to get embeddings from the model for a list of prompts.

Inherits from Protobuf::Message.

Accessors

  • $msg->model() / $msg->model($value)

    Type: String

    Required. The model's resource name. This serves as an ID for the Model to use.

    This name should match a model name returned by the `ListModels` method.

    Format: `models/{model}`

  • $msg->requests() / $msg->requests($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::EmbedContentRequest)

    Required. Embed requests for the batch. The model in each of these requests must match the model specified `BatchEmbedContentsRequest.model`.

Google::Ai::Generativelanguage::V1beta::GenerativeService::BatchEmbedContentsResponse

The response to a `BatchEmbedContentsRequest`.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::CountTokensRequest

Counts the number of tokens in the `prompt` sent to a model.

Models may tokenize text differently, so each model may return a different `token_count`.

Inherits from Protobuf::Message.

Accessors

  • $msg->model() / $msg->model($value)

    Type: String

    Required. The model's resource name. This serves as an ID for the Model to use.

    This name should match a model name returned by the `ListModels` method.

    Format: `models/{model}`

  • $msg->contents() / $msg->contents($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Content)

    Optional. The input given to the model as a prompt. This field is ignored when `generate_content_request` is set.

  • $msg->generate_content_request() / $msg->generate_content_request($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::GenerateContentRequest)

    Optional. The overall input given to the `Model`. This includes the prompt as well as other model steering information like [system instructions](https://ai.google.dev/gemini-api/docs/system-instructions), and/or function declarations for [function calling](https://ai.google.dev/gemini-api/docs/function-calling). `Model`s/`Content`s and `generate_content_request`s are mutually exclusive. You can either send `Model` + `Content`s or a `generate_content_request`, but never both.

Google::Ai::Generativelanguage::V1beta::GenerativeService::CountTokensResponse

A response from `CountTokens`.

It returns the model's `token_count` for the `prompt`.

Inherits from Protobuf::Message.

Accessors

  • $msg->total_tokens() / $msg->total_tokens($value)

    Type: Int32

    The number of tokens that the `Model` tokenizes the `prompt` into. Always non-negative.

  • $msg->cached_content_token_count() / $msg->cached_content_token_count($value)

    Type: Int32

    Number of tokens in the cached part of the prompt (the cached content).

  • $msg->prompt_tokens_details() / $msg->prompt_tokens_details($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::ModalityTokenCount)

    Output only. List of modalities that were processed in the request input.

  • $msg->cache_tokens_details() / $msg->cache_tokens_details($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::ModalityTokenCount)

    Output only. List of modalities that were processed in the cached content.

Google::Ai::Generativelanguage::V1beta::GenerativeService::RealtimeInputConfig

Configures the realtime input behavior in `BidiGenerateContent`.

Inherits from Protobuf::Message.

Accessors

Enum: RealtimeInputConfig::ActivityHandling

  • ACTIVITY_HANDLING_UNSPECIFIED => 0

  • START_OF_ACTIVITY_INTERRUPTS => 1

  • NO_INTERRUPTION => 2

Enum: RealtimeInputConfig::TurnCoverage

  • TURN_COVERAGE_UNSPECIFIED => 0

  • TURN_INCLUDES_ONLY_ACTIVITY => 1

  • TURN_INCLUDES_ALL_INPUT => 2

Google::Ai::Generativelanguage::V1beta::GenerativeService::SessionResumptionConfig

Session resumption configuration.

This message is included in the session configuration as `BidiGenerateContentSetup.session_resumption`. If configured, the server will send `SessionResumptionUpdate` messages.

Inherits from Protobuf::Message.

Accessors

  • $msg->handle() / $msg->handle($value)

    Type: String

    The handle of a previous session. If not present then a new session is created.

    Session handles come from `SessionResumptionUpdate.token` values in previous connections.

Google::Ai::Generativelanguage::V1beta::GenerativeService::ContextWindowCompressionConfig

Enables context window compression — a mechanism for managing the model's context window so that it does not exceed a given length.

Inherits from Protobuf::Message.

Accessors

  • $msg->sliding_window() / $msg->sliding_window($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::ContextWindowCompressionConfig::SlidingWindow)

    A sliding-window mechanism.

  • $msg->trigger_tokens() / $msg->trigger_tokens($value)

    Type: Int64

    The number of tokens (before running a turn) required to trigger a context window compression.

    This can be used to balance quality against latency as shorter context windows may result in faster model responses. However, any compression operation will cause a temporary latency increase, so they should not be triggered frequently.

    If not set, the default is 80% of the model's context window limit. This leaves 20% for the next user request/model response.

Google::Ai::Generativelanguage::V1beta::GenerativeService::AudioTranscriptionConfig

The audio transcription configuration.

Inherits from Protobuf::Message.

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentSetup

Message to be sent in the first (and only in the first) `BidiGenerateContentClientMessage`. Contains configuration that will apply for the duration of the streaming RPC.

Clients should wait for a `BidiGenerateContentSetupComplete` message before sending any additional messages.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentClientContent

Incremental update of the current conversation delivered from the client. All of the content here is unconditionally appended to the conversation history and used as part of the prompt to the model to generate content.

A message here will interrupt any current model generation.

Inherits from Protobuf::Message.

Accessors

  • $msg->turns() / $msg->turns($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Content)

    Optional. The content appended to the current conversation with the model.

    For single-turn queries, this is a single instance. For multi-turn queries, this is a repeated field that contains conversation history and the latest request.

  • $msg->turn_complete() / $msg->turn_complete($value)

    Type: Bool

    Optional. If true, indicates that the server content generation should start with the currently accumulated prompt. Otherwise, the server awaits additional messages before starting generation.

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentRealtimeInput

User input that is sent in real time.

The different modalities (audio, video and text) are handled as concurrent streams. The ordering across these streams is not guaranteed.

This is different from [BidiGenerateContentClientContent][google.ai.generativelanguage.v1beta.BidiGenerateContentClientContent] in a few ways:

* Can be sent continuously without interruption to model generation. * If there is a need to mix data interleaved across the [BidiGenerateContentClientContent][google.ai.generativelanguage.v1beta.BidiGenerateContentClientContent] and the [BidiGenerateContentRealtimeInput][google.ai.generativelanguage.v1beta.BidiGenerateContentRealtimeInput], the server attempts to optimize for best response, but there are no guarantees. * End of turn is not explicitly specified, but is rather derived from user activity (for example, end of speech). * Even before the end of turn, the data is processed incrementally to optimize for a fast start of the response from the model.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentToolResponse

Client generated response to a `ToolCall` received from the server. Individual `FunctionResponse` objects are matched to the respective `FunctionCall` objects by the `id` field.

Note that in the unary and server-streaming GenerateContent APIs function calling happens by exchanging the `Content` parts, while in the bidi GenerateContent APIs function calling happens over these dedicated set of messages.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentClientMessage

Messages sent by the client in the BidiGenerateContent call.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentSetupComplete

Sent in response to a `BidiGenerateContentSetup` message from the client.

Inherits from Protobuf::Message.

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentServerContent

Incremental server update generated by the model in response to client messages.

Content is generated as quickly as possible, and not in real time. Clients may choose to buffer and play it out in real time.

Inherits from Protobuf::Message.

Accessors

  • $msg->model_turn() / $msg->model_turn($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::Content)

    Output only. The content that the model has generated as part of the current conversation with the user.

  • $msg->generation_complete() / $msg->generation_complete($value)

    Type: Bool

    Output only. If true, indicates that the model is done generating.

    When model is interrupted while generating there will be no 'generation_complete' message in interrupted turn, it will go through 'interrupted > turn_complete'.

    When model assumes realtime playback there will be delay between generation_complete and turn_complete that is caused by model waiting for playback to finish.

  • $msg->turn_complete() / $msg->turn_complete($value)

    Type: Bool

    Output only. If true, indicates that the model has completed its turn. Generation will only start in response to additional client messages.

  • $msg->interrupted() / $msg->interrupted($value)

    Type: Bool

    Output only. If true, indicates that a client message has interrupted current model generation. If the client is playing out the content in real time, this is a good signal to stop and empty the current playback queue.

  • $msg->grounding_metadata() / $msg->grounding_metadata($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::GroundingMetadata)

    Output only. Grounding metadata for the generated content.

  • $msg->input_transcription() / $msg->input_transcription($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentTranscription)

    Output only. Input audio transcription. The transcription is sent independently of the other server messages and there is no guaranteed ordering.

  • $msg->output_transcription() / $msg->output_transcription($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentTranscription)

    Output only. Output audio transcription. These transcriptions are part of the Generation output of the server. The last output transcription of this turn is sent before either `generation_complete` or `interrupted`, which in turn are followed by `turn_complete`. There is no guaranteed exact ordering between transcriptions and other `model_turn` output but the server tries to send the transcripts close to the corresponding audio output.

  • $msg->url_context_metadata() / $msg->url_context_metadata($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::GenerativeService::UrlContextMetadata)

  • $msg->waiting_for_input() / $msg->waiting_for_input($value)

    Type: Bool

    Output only. If true, indicates that the model is not generating content because it is waiting for more input from the user, e.g. because it expects the user to continue talking.

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentToolCall

Request for the client to execute the `function_calls` and return the responses with the matching `id`s.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentToolCallCancellation

Notification for the client that a previously issued `ToolCallMessage` with the specified `id`s should not have been executed and should be cancelled. If there were side-effects to those tool calls, clients may attempt to undo the tool calls. This message occurs only in cases where the clients interrupt server turns.

Inherits from Protobuf::Message.

Accessors

  • $msg->ids() / $msg->ids($value)

    Type: String

    Output only. The ids of the tool calls to be cancelled.

Google::Ai::Generativelanguage::V1beta::GenerativeService::GoAway

A notice that the server will soon disconnect.

Inherits from Protobuf::Message.

Accessors

  • $msg->time_left() / $msg->time_left($value)

    Type: Message (Google::Protobuf::Duration::Duration)

    The remaining time before the connection will be terminated as ABORTED.

    This duration will never be less than a model-specific minimum, which will be specified together with the rate limits for the model.

Google::Ai::Generativelanguage::V1beta::GenerativeService::SessionResumptionUpdate

Update of the session resumption state.

Only sent if `BidiGenerateContentSetup.session_resumption` was set.

Inherits from Protobuf::Message.

Accessors

  • $msg->new_handle() / $msg->new_handle($value)

    Type: String

    New handle that represents a state that can be resumed. Empty if `resumable`=false.

  • $msg->resumable() / $msg->resumable($value)

    Type: Bool

    True if the current session can be resumed at this point.

    Resumption is not possible at some points in the session. For example, when the model is executing function calls or generating. Resuming the session (using a previous session token) in such a state will result in some data loss. In these cases, `new_handle` will be empty and `resumable` will be false.

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentTranscription

Transcription of audio (input or output).

Inherits from Protobuf::Message.

Accessors

  • $msg->text() / $msg->text($value)

    Type: String

    Transcription text.

Google::Ai::Generativelanguage::V1beta::GenerativeService::BidiGenerateContentServerMessage

Response message for the BidiGenerateContent call.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1beta::GenerativeService::UsageMetadata

Usage metadata about response(s).

Inherits from Protobuf::Message.

Accessors

  • $msg->prompt_token_count() / $msg->prompt_token_count($value)

    Type: Int32

    Output only. Number of tokens in the prompt. When `cached_content` is set, this is still the total effective prompt size meaning this includes the number of tokens in the cached content.

  • $msg->cached_content_token_count() / $msg->cached_content_token_count($value)

    Type: Int32

    Number of tokens in the cached part of the prompt (the cached content)

  • $msg->response_token_count() / $msg->response_token_count($value)

    Type: Int32

    Output only. Total number of tokens across all the generated response candidates.

  • $msg->tool_use_prompt_token_count() / $msg->tool_use_prompt_token_count($value)

    Type: Int32

    Output only. Number of tokens present in tool-use prompt(s).

  • $msg->thoughts_token_count() / $msg->thoughts_token_count($value)

    Type: Int32

    Output only. Number of tokens of thoughts for thinking models.

  • $msg->total_token_count() / $msg->total_token_count($value)

    Type: Int32

    Output only. Total token count for the generation request (prompt + response candidates).

  • $msg->prompt_tokens_details() / $msg->prompt_tokens_details($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::ModalityTokenCount)

    Output only. List of modalities that were processed in the request input.

  • $msg->cache_tokens_details() / $msg->cache_tokens_details($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::ModalityTokenCount)

    Output only. List of modalities of the cached content in the request input.

  • $msg->response_tokens_details() / $msg->response_tokens_details($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::ModalityTokenCount)

    Output only. List of modalities that were returned in the response.

  • $msg->tool_use_prompt_tokens_details() / $msg->tool_use_prompt_tokens_details($value)

    Type: Message (Google::Ai::Generativelanguage::V1beta::Content::ModalityTokenCount)

    Output only. List of modalities that were processed for tool-use request inputs.

SEE ALSO

Protobuf, Protobuf::Message, Google::Ai::Generativelanguage::V1beta::GenerativeService::Types, https://protobuf.dev/

LICENSE AND COPYRIGHT

Copyright (C) 2026 Google LLC

This program is released under the Apache 2.0 license.