Skip to main content
Portkey provides a robust and secure gateway to facilitate the integration of various Large Language Models (LLMs) into your applications, including Google Gemini APIs. With Portkey, you can take advantage of features like fast AI gateway access, observability, prompt management, and more, all while ensuring the secure management of your LLM API keys through Model Catalog.

Quick Start


Add Provider in Model Catalog

1

Navigate to Model Catalog

Go to Model Catalog → Add Provider in your Portkey dashboard.
2

Select Google Gemini

Find and select Google from the provider list.
3

Enter API Key

Get your API key from Google AI Studio and enter it in Model Catalog.
4

Save and Use

Save your configuration. Your provider slug will be @google (or a custom name you specify).
Portkey supports the system_instructions parameter for Google Gemini 1.5 - allowing you to control the behavior and output of your Gemini-powered applications with ease.Simply include your Gemini system prompt as part of the {"role":"system"} message within the messages array of your request body. Portkey Gateway will automatically transform your message to ensure seamless compatibility with the Google Gemini API.

Gemini Capabilities

Function Calling

Portkey supports function calling mode on Google’s Gemini Models. Explore this cookbook for a deep dive and examples: Function Calling

Advanced Multimodal Capabilities with Gemini

Gemini models are inherently multimodal, capable of processing and understanding content from a wide array of file types. Portkey streamlines the integration of these powerful features by providing a unified, OpenAI-compatible API.
The Portkey Advantage: A Unified Format for All MediaTo simplify development, Portkey uses a consistent format for all multimodal requests. Whether you’re sending an image, audio, video, or document, you will use an object with type: 'image_url' within the user message’s content array.Portkey’s AI Gateway intelligently interprets your request—based on the URL or data URI you provide—and translates it into the precise format required by the Google Gemini API. This means you only need to learn one structure for all your media processing needs.

Image Processing

Gemini can analyze images to describe their content, answer visual questions, or identify objects.

Gemini Image Understanding Docs

Method 1: Sending an Image via Google Files URL Use the Google Files API to upload your image and get a URL. This is the recommended approach for larger files or when you need persistent storage.
To upload files and get Google Files URLs, use the Files API. The URL format will be similar to: https://generativelanguage.googleapis.com/v1beta/files/[FILE_ID]
Method 2: Sending a Local Image as Base64 Data Use this method for local image files. The file is encoded into a Base64 string and sent as a data URI. This is ideal for smaller files when you don’t want to use the Files API. The data URI format is: data:<MIME_TYPE>;base64,<YOUR_BASE64_DATA>
Supported Image MIME types: image/png, image/jpeg, image/webp, image/heic, image/heif

Audio Processing

Gemini can transcribe speech, summarize audio content, or answer questions about sounds.

Gemini Audio Understanding Docs

Method 1: Sending Audio via Google Files URL Upload your audio file using the Files API to get a Google Files URL.
Method 2: Sending Local Audio as Base64 Data This is the standard way to process local audio files directly through the API.
Supported Audio MIME types: audio/wav, audio/mp3, audio/aiff, audio/aac, audio/ogg, audio/flac, audio/pcm, audio/m4a, audio/mpeg, audio/mpga, audio/mp4, audio/webm

Video Processing

Gemini can summarize videos, answer questions about specific events, and describe scenes.

Gemini Video Understanding Docs

Method 1: Sending a Video via YouTube URL YouTube is the only supported public URL source for videos. Simply provide the YouTube video URL.
Method 2: Sending Local Video as Base64 Data For smaller video files, you can encode them as base64. Note that this method has size limitations.
Method 3: Sending Video via Google Files URL For larger video files, upload them using the Files API to get a Google Files URL.
Supported Video MIME types: video/mp4, video/mpeg, video/mov, video/avi, video/webm, video/wmv

Document Processing (PDF)

Gemini’s vision capabilities excel at understanding the content of PDF documents, including text, tables, and images.

Gemini Documents Understanding Docs

Method 1: Sending a Document via Google Files URL Upload your PDF using the Files API to get a Google Files URL.
Method 2: Sending a Local Document as Base64 Data This is suitable for smaller, local PDF files.
While you can send other document types like .txt or .html, they will be treated as plain text. Gemini’s native document vision capabilities are optimized for the application/pdf MIME type.
Important: For all file uploads (except YouTube videos), it’s recommended to use the Google Files API to upload your files first, then use the returned file URL in your requests. This approach provides better performance and reliability for larger files.

Media Resolution

The media_resolution parameter allows you to control token allocation for media inputs (images, videos, PDFs) when using Gemini models. This helps balance between processing detail and cost/speed.

Supported values

ValueDescription
MEDIA_RESOLUTION_LOWReduced tokens for faster, cheaper processing
MEDIA_RESOLUTION_MEDIUMBalanced approach between detail and cost
MEDIA_RESOLUTION_HIGHMaximum tokens for detailed analysis
MEDIA_RESOLUTION_ULTRA_HIGHHighest resolution (per-part only, for specialized tasks)

Top-level configuration

Apply media resolution globally to all media in the request:

Per-part configuration (Gemini 3 only)

For Gemini 3 models, you can specify media resolution on individual media parts. Per-part settings take precedence over global settings when both are specified.

Google Gemini Media Resolution Documentation


Code Execution Tool

Gemini can use a built-in code interpreter tool to solve complex computational problems, perform calculations, and generate code. To enable this, simply include the code_execution tool in your request. The model will automatically decide when to invoke it.

Thought Signatures (Tool Calling Verification)

Set x-portkey-strict-open-ai-compliance to false to receive the thought_signature in the response. This header must be included in all requests when using thought signatures.
Google’s Gemini 3 Pro model requires passing a thought_signature parameter in tool calling conversations for verifying the payload. This signature is returned by the model in the assistant’s tool call response and must be included when continuing multi-turn conversations.

Google Gemini Thought Signatures Documentation

Single turn conversation

In a single-turn conversation, you make a request with tools defined, and the model returns tool calls with thought signatures.

Multi turn conversation

In multi-turn conversations, you must include the thought_signature field in the assistant’s tool call when continuing the conversation.
The thought_signature is automatically generated by the model and returned in the tool call response. You must preserve this signature when including the assistant’s message in subsequent requests.

Computer Use (Browser Automation) (Preview)

Set strict_open_ai_compliance to false to use the Computer Use tool.

Single turn conversation

Multi turn conversation

Vertex AI supports grounding with Google Search. This is a feature that allows you to ground your LLM responses with real-time search results. Grounding is invoked by passing the google_search tool (for newer models like gemini-2.0-flash-001), and google_search_retrieval (for older models like gemini-1.5-flash) in the tools array.
If you mix regular tools with grounding tools, vertex might throw an error saying only one tool can be used at a time.

Extended Thinking (Reasoning Models) (Beta)

The assistants thinking response is returned in the response_chunk.choices[0].delta.content_blocks array, not the response.choices[0].message.content string.
Models like gemini-2.5-flash-preview-04-17 gemini-2.5-flash-preview-04-17 support extended thinking. This is similar to openai thinking, but you get the model’s reasoning as it processes the request as well. Note that you will have to set strict_open_ai_compliance=False in the headers to use this feature.

Single turn conversation

To disable thinking for gemini models like gemini-2.5-flash-preview-04-17, you are required to explicitly set budget_tokens to 0.
Gemini grounding mode may not work via Portkey SDK. Contact support@portkey.ai for assistance.

Image Generation (nano banana 🍌)

Gemini models like gemini-3-pro-image-preview support native image generation capabilities. You can generate images by setting modalities to include "image" in your request.
You must set strict_open_ai_compliance=False in the headers to use image generation, as the response format includes non-standard fields like content_parts.
The generated image data is returned in the content_parts field of the response and can be used in multi-turn conversations for iterative image editing.

Image Generation with Text Response

You can also generate images along with text explanations by including both "text" and "image" in the modalities array:

Image Editing (Multi-turn)

You can edit generated images by continuing the conversation. Pass the image data from the previous response back in the messages:

Next Steps

SDK Reference

Complete SDK documentation and API reference

Add Metadata

Add metadata to your Gemini requests

Gateway Configs

Configure advanced gateway features

Request Tracing

Trace and monitor your Gemini requests

Setup Fallbacks

Create fallback configurations between providers
Last modified on April 8, 2026