Skip to main content

Adding Models

This section explains the steps to add Google Gemini models and configure the required access controls.
1

Select Google Gemini as the provider

From the TrueFoundry dashboard, go to AI Gateway > Models, click Add Model and choose To New Provider Account. Select Google Gemini from the provider list.
Add Provider Account page listing the supported model providers

Choose a provider in Add Provider Account

2

Add Google Gemini Account Details

Give a unique name to your Gemini account and complete the form with your Gemini authentication details (API Key).
Google Gemini Configure Account form in the provider account setup drawer

Configure Account for Google Gemini

3

Add Models

Select the model from the list. If you see the model you want to add in the list of checkboxes, we support public model cost for these models.
If the model you need is not listed, click Add Model Manually in the banner below the list and enter its display name, model ID and model types.
4

Save and grant access

Click Test Credentials to check the account against the selected models, or click Save without Testing. To keep the account in Git instead, click Apply using YAML and apply the generated spec with tfy apply.To let other users, teams or virtual accounts use or manage these models, open Manage Accounts, click ⋮ on the account and choose Access Control > Grant Access. See Access control.

Inference

After adding the models, you can perform inference using an OpenAI-compatible API via the Playground or by integrating with your own application. Code Snippet and Try in Playgroud Buttons for each model

Supported APIs

Once your Gemini model account is configured, the following API surfaces are available through the AI Gateway.
Legend:
  • ✅ Supported by provider and TrueFoundry
  • Supported by Provider, but not by TrueFoundry
  • Provider does not support this feature
Not supported for Gemini: Batch API, Files API, Messages API (Anthropic-only), Responses API, Speech-to-Text, Audio Translation, Moderation, Image Variation, and Realtime API. For Batch and Files workflows, use Google Vertex AI — same Gemini models, GCS-backed batch/files.
Gemini’s chat completions endpoint supports streaming, tools, multimodal input (images, audio, video, PDF), structured JSON outputs, extended thinking, and Google Search grounding. The AI Gateway translates OpenAI-compatible requests into Gemini’s native generateContent API. Full provider capability matrix: Chat Completions API.
Send service_tier as flex or priority on the Chat Completions body. The gateway maps it to Gemini’s serviceTier and bills the served traffic type (ON_DEMAND stays on base rates). ultrafast is not sent. See Service tiers.
Python
Set stream=True and iterate over delta chunks. Defensively check that chunk.choices is non-empty and delta.content is not None.
Python
Advertise a tool, hand the model’s tool_calls back as a tool role message, then request the final response.
Python
Gemini accepts images, audio, video, and PDFs via multimodal content parts. Images use the image_url content type; audio and video also use image_url with a mime_type hint; PDFs use the file content type with a base64 data URI.
Python
Gemini supports two structured-output modes via response_format:
  • JSON object — {"type": "json_object"} — guarantees valid JSON, no schema
  • JSON schema — {"type": "json_schema", "json_schema": {...}} — enforces a schema
Python
Gemini 2.5 Pro and 2.5 Flash support extended thinking, on by default. Use reasoning_effort (low/medium/high) — the AI Gateway translates it to Gemini’s native thinking-budget parameter.
Python
Gemini can augment responses with live Google Search results via a special google_search tool. The model decides when to invoke search during generation.
Python
Gemini’s TTS-preview models generate audio from text via the OpenAI-compatible /audio/speech endpoint. The AI Gateway routes this to Google Cloud Text-to-Speech upstream. Full docs: Text-to-Speech.
Python
The AI Gateway accepts OpenAI voice aliases (alloy, echo, fable, onyx, nova, shimmer) and translates them to default Cloud TTS voices. For specific Cloud TTS voices, pass the fully-qualified name (e.g. en-US-Chirp3-HD-Kore).
Gemini’s gemini-embedding-2 text embedding model via the OpenAI-compatible /embeddings endpoint. Accepts a task_type parameter via extra_body that tunes the vector for the downstream task (RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY, SEMANTIC_SIMILARITY, CLASSIFICATION, CLUSTERING). Full docs: Embed API.
Python
Gemini’s gemini-3.1-flash-image generates images from text via the OpenAI-compatible /images/generations endpoint. Full docs: Image Generation.
Python
Pricing varies by model family. Imagen models are billed per image at a flat rate. Gemini image models are billed per token, where higher-resolution / HD outputs consume more tokens.
Image edit uses the same gemini-3.1-flash-image model via the OpenAI-compatible /images/edits endpoint. Pass the source image and a mask.
Python
Gemini supports supervised fine-tuning of Gemini models. Upload JSONL via the Files API with purpose="fine-tune", then submit a tuning job through /fine_tuning/jobs. Lifecycle mirrors OpenAI fine-tuning. Full docs: Fine-tuning.
Fine-tuning incurs real GCP charges. See the Vertex tunable model list.
Python
Gemini Decision models such as gemini-decision-1 evaluate a piece of content against typed questions and return calibrated answers instead of generated text. The AI Gateway sends the request to Gemini’s Decisions API (/v1beta/decisions) with your Gemini API key.When you add the model:
  • Model ID: gemini-decision-1.
  • Model Types: Decision.
  • Cost: gemini-decision-1 is in the model list, so public cost is tracked. It bills input tokens only.
Call the model with the TrueFoundry model ID in the format your-gemini-account/your-model-display-name. Send the content in state and named questions in questions. Set GATEWAY_BASE_URL to your gateway base URL without a trailing slash and TFY_API_KEY to your TrueFoundry API key.
The AI Gateway maps the System One body onto Gemini’s format:
  • state is sent as Gemini’s input. A string, or a list of Gemini content blocks (text, or image, audio, video and document blocks with a uri, or with data and mime_type), is passed through as is. Any other value is sent as JSON text.
  • noul criteria true and false become true_description and false_description. A choice option without a rubric is sent as an empty string.
  • Gemini’s total_input_tokens and total_output_tokens are reported as input_tokens and output_tokens in usage, so cost tracking works.
The System One images field is a Cloudflare Clef extension and is rejected with a 400. To send media, put Gemini content blocks in state. Gemini responses do not include a model field.The same model also answers POST /v1/decisions in OpenAI’s format, and can be the Auto Routing classifier. Full request and response schemas, plus the other decision providers: Decisions API.