Service Client: Google::Ai::Generativelanguage::V1alpha::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::V1alpha::GenerativeService - Compiled Protocol Buffers messages for google/ai/generativelanguage/v1alpha/generative_service.proto

SYNOPSIS

use Google::Ai::Generativelanguage::V1alpha::GenerativeService;

my $msg = Google::Ai::Generativelanguage::V1alpha::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::V1alpha::GenerativeService::GenerateContentRequest->parse($bytes);

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

DESCRIPTION

Auto-generated Protobuf message classes compiled from google/ai/generativelanguage/v1alpha/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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::GenerativeService::VoiceConfig

The configuration for the voice to use.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::GenerativeService::SpeechConfig

The speech generation config.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::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.

    Currently, this value can only be set to 1. If unset, this will default to 1.

  • $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->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::V1alpha::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->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.v1alpha.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 dificult 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.v1alpha.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.v1alpha.GenerationConfig.response_logprobs]. This sets the number of top logprobs to return at each decoding step in the [Candidate.logprobs_result][google.ai.generativelanguage.v1alpha.Candidate.logprobs_result].

  • $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::V1alpha::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::V1alpha::GenerativeService::SpeechConfig)

    Optional. The speech generation config.

Enum: GenerationConfig::Modality

  • MODALITY_UNSPECIFIED => 0

  • TEXT => 1

  • IMAGE => 2

  • AUDIO => 3

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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

Google::Ai::Generativelanguage::V1alpha::GenerativeService::LogprobsResult

Logprobs Result

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::GenerativeService::AttributionSourceId

Identifier for the source contributing to this attribution.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::GenerativeService::GroundingAttribution

Attribution for a source that contributed to an answer.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::GenerativeService::GroundingMetadata

Metadata returned to client when grounding is enabled.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::GenerativeService::GroundingChunk

Grounding chunk.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::GenerativeService::GroundingSupport

Grounding support.

Inherits from Protobuf::Message.

Accessors

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

    Type: Message (Google::Ai::Generativelanguage::V1alpha::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::V1alpha::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::V1alpha::Content::GroundingPassages)

    Passages provided inline with the request.

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

    Type: Message (Google::Ai::Generativelanguage::V1alpha::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::V1alpha::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::V1alpha::GenerateAnswerRequest::AnswerStyle)

    Required. Style in which answers should be returned.

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

    Type: Message (Google::Ai::Generativelanguage::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::TaskType)

    Optional. Optional task type for which the embeddings will be used. Can only be set for `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::V1alpha::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::V1alpha::GenerativeService::EmbedContentResponse

The response to an `EmbedContentRequest`.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::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::V1alpha::GenerativeService::BatchEmbedContentsResponse

The response to a `BatchEmbedContentsRequest`.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::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::V1alpha::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::V1alpha::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).

Google::Ai::Generativelanguage::V1alpha::GenerativeService::BidiGenerateContentSetup

Message to be sent in the first and only 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

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

    Type: String

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

    Format: `models/{model}`

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

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

    Optional. Generation config.

    The following fields are not supported:

    - `response_logprobs`
    - `response_mime_type`
    - `logprobs`
    - `response_schema`
    - `stop_sequence`
    - `routing_config`
    - `audio_timestamp`
  • $msg->system_instruction() / $msg->system_instruction($value)

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

    Optional. The user provided system instructions for the model.

    Note: Only text should be used in parts and content in each part will be in a separate paragraph.

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

    Type: Message (Google::Ai::Generativelanguage::V1alpha::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.

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::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::V1alpha::GenerativeService::BidiGenerateContentRealtimeInput

User input that is sent in real time.

This is different from [BidiGenerateContentClientContent][google.ai.generativelanguage.v1alpha.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.v1alpha.BidiGenerateContentClientContent]
  and the
  [BidiGenerateContentRealtimeInput][google.ai.generativelanguage.v1alpha.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.
- Is always direct user input that is sent in real time. Can be sent
  continuously without interruptions. The model automatically detects the
  beginning and the end of user speech and starts or terminates streaming
  the response accordingly. Data is processed incrementally as it arrives,
  minimizing latency.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::GenerativeService::BidiGenerateContentClientMessage

Messages sent by the client in the BidiGenerateContent call.

Inherits from Protobuf::Message.

Accessors

Google::Ai::Generativelanguage::V1alpha::GenerativeService::BidiGenerateContentSetupComplete

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

Inherits from Protobuf::Message.

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::Content::Content)

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

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

    Type: Bool

    Output only. If true, indicates that the model is done generating. Generation will only start in response to additional client messages. Can be set alongside `content`, indicating that the `content` is the last in the turn.

  • $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::V1alpha::GenerativeService::GroundingMetadata)

    Output only. Grounding metadata for the generated content.

Google::Ai::Generativelanguage::V1alpha::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::V1alpha::GenerativeService::BidiGenerateContentToolCallCancellation

Notification for the client that a previously issued `ToolCallMessage` with the specified `id`s should have been not 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::V1alpha::GenerativeService::BidiGenerateContentServerMessage

Response message for the BidiGenerateContent call.

Inherits from Protobuf::Message.

Accessors

SEE ALSO

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

LICENSE AND COPYRIGHT

Copyright (C) 2026 Google LLC

This program is released under the Apache 2.0 license.