Skip to main content

Overview

GoogleLLMService provides integration with Google’s Gemini models, supporting streaming responses, function calling, and multimodal inputs. It includes specialized context handling for Google’s message format while maintaining compatibility with OpenAI-style contexts.

Gemini LLM API Reference

Pipecat’s API methods for Google Gemini integration

Example Implementation

Complete example with function calling

Gemini Documentation

Official Google Gemini API documentation and features

Google AI Studio

Access Gemini models and manage API keys

Installation

To use Google Gemini services, install the required dependencies:

Prerequisites

Google Gemini Setup

Before using Google Gemini LLM services, you need:
  1. Google Account: Sign up at Google AI Studio
  2. API Key: Generate a Gemini API key from AI Studio
  3. Model Selection: Choose from available Gemini models

Required Environment Variables

  • GOOGLE_API_KEY: Your Google Gemini API key for authentication

Configuration

str
required
Google AI API key for authentication.
str
default:"None"
deprecated
Deprecated since 0.0.105, removed in 2.0.0. Use settings=GoogleLLMService.Settings(...) instead.
GoogleLLMService.Settings
default:"None"
Runtime-configurable model settings. See Settings below.
InputParams
default:"None"
deprecated
Deprecated since 0.0.105, removed in 2.0.0. Use settings=GoogleLLMService.Settings(...) instead.
str
default:"None"
deprecated
Deprecated since 0.0.105, removed in 2.0.0. Use settings=GoogleLLMService.Settings(system_instruction=...) instead.
List[Dict[str, Any]]
default:"None"
List of available tools/functions for the model to call. Used only when the context carries no tools, and ignored by run_inference().
Dict[str, Any]
default:"None"
Configuration for tool usage behavior. Ignored by run_inference().
HttpOptions
default:"None"
HTTP options for the Google API client.
float | None
default:"20.0"
How long to wait for the next chunk of a streamed response before giving up on it. Bounds the wait when the API accepts a request and then stops producing without closing the stream. This is a gap between chunks, not a limit on how long a response may take overall. The first chunk is the slowest, since its wait spans the whole round trip including any thinking the model does before it emits anything; raise this for models configured to think at length. Set to None to wait indefinitely.
float | None
default:"5.0"
How long to wait for the first chunk before giving up on the request and re-issuing it, when retry_on_timeout is set. Like the first-chunk wait above, this window spans the whole round trip including any thinking, so it is only a good fit for models that start emitting quickly.
bool | None
default:"False"
Whether to re-issue the request once if the first chunk doesn’t arrive within retry_timeout_secs. Only the first chunk is retried: once a chunk has been pushed downstream, re-issuing would duplicate the response.

Settings

Runtime-configurable settings passed via the settings constructor argument using GoogleLLMService.Settings(...). These can be updated mid-conversation with LLMUpdateSettingsFrame. See Service Settings for details.
None values are omitted from the API request, letting the Gemini API use its own defaults. If thinking is not provided, Pipecat sends the lowest thinking setting Google documents for the model and logs what it sent: thinking_budget=0 on Gemini 2.5 Flash and Flash-Lite (128 on 2.5 Pro), and a thinking_level on later models ("low" for Gemini 3.1 Pro, 3.7 Flash, 3.8 Flash and 4 Argon, which reject "minimal"; "minimal" for the rest). A model that can think but isn’t listed runs at Google’s default and logs a warning.

GoogleThinkingConfig

Configuration for controlling the model’s internal thinking process. Gemini 2.5 and 3 series models support this feature.
Gemini 2.5 series models use thinking_budget, while Gemini 3 models use thinking_level. Set either one or the other, never both. When thinking_budget is set on a Gemini 3 model, the service emits a warning because the behavior varies by model and backend (it may be honored, ignored, or rejected).

Usage

Basic Setup

With Custom Settings

With Thinking Configuration

With Safety Settings

Updating Settings at Runtime

Model settings can be changed mid-conversation using LLMUpdateSettingsFrame:

Notes

  • System instruction priority: The system_instruction set via the constructor or GoogleLLMSettings takes priority over any system message in the context. If both are set, a warning is logged and the constructor/settings value is used.
  • Thinking defaults: By default, Pipecat sends each listed model its lowest thinking setting to reduce latency (see the note under Settings for the values). Aliases such as gemini-flash-latest aren’t listed, so they run at Google’s default. The same defaults apply on the run_inference() path as in the pipeline. To override this behavior, explicitly pass a GoogleThinkingConfig via settings.
  • Response schema: run_inference() accepts an optional response_schema parameter (a JSON schema) that asks Gemini to enforce the reply’s structure. Gemini 2.5 and later models support this. When the schema is provided, the reply is JSON text matching it. Older models (Gemini 2.0 and earlier) ignore the schema with a warning.
  • Thinking budget warning: When thinking_budget is set on a Gemini 3 model, the service emits a warning because Gemini 3 models take thinking_level instead. Whether a thinking_budget set alongside one is honored, ignored, or rejected varies by model and backend. Use thinking_level with Gemini 3 models.
  • Incomplete responses: When a response ends for a notable reason — withheld for safety, recitation, or prohibited content, a rejected tool call, or the output hitting the token limit — the service logs a warning naming Gemini’s finish_reason, for both streamed responses and run_inference(). Whatever text did arrive is still pushed downstream or returned, so a turn that comes back short has an explanation in the logs rather than only in the transcript.
  • Safety settings: Categories left unspecified in safety_settings keep the Gemini API defaults. The setting accepts SafetySetting objects or plain dicts, and is runtime-updatable via LLMUpdateSettingsFrame.
  • Seed parameter: Gemini treats the seed parameter as best effort. Identical seeds usually but not always produce identical responses.
  • Multimodal support: Gemini models natively support image and audio inputs through Google’s Content/Part format. Images and audio are automatically converted from OpenAI-style contexts. An image_url content part holding a data: URI is inlined; any other URL is passed to Gemini as an external reference, so an image already hosted somewhere doesn’t have to be fetched and re-encoded into the context.
  • Grounding with Google Search: When grounding metadata is present in the response (e.g., from Google Search tool), the service emits LLMSearchResponseFrame with search results and source attributions.
  • Context format: The service automatically converts OpenAI-style messages to Google’s native Content/Part format. To add a message already in Google’s format, wrap it with llm.create_llm_specific_message(...); a bare Google-format dict in the context is dropped.

Event Handlers

GoogleLLMService supports the following event handlers, inherited from LLMService: