Google Gemini
Use Google Gemini models as the LLM for your agents.
Get an API key
Get a free key at aistudio.google.com under Get API key.
Setup
pai create model-provider google \
--provider gemini \
--api-key AIzaSy...
This stores your API key securely and creates a ModelProvider that covers every Gemini model under your subscription.
Verify:
pai get model-providers
# NAME PROVIDER ENDPOINT MAX/DAY LAST USED AGE
# google gemini — 5s
Supported models
| Model | Reference | Best for |
|---|---|---|
| Gemini 2.5 Flash | google/gemini-2.5-flash | Best overall — fast, high token limits, cheap |
| Gemini 2.0 Flash | google/gemini-2.0-flash | Stable previous generation |
| Gemini 2.5 Pro | google/gemini-2.5-pro | Deep reasoning, complex tasks |
Use in an agent
spec:
models:
- google/gemini-2.5-flash
Multiple models — first is primary, rest are fallbacks:
spec:
models:
- google/gemini-2.5-flash # primary
- google/gemini-2.5-pro # fallback for hard questions
The Pai Gateway translates Anthropic-style /v1/messages requests to Gemini's format and back, so harness-backed agents using Claude Code / the Anthropic SDK work against Gemini without code changes.
Token budgets
Cap how many tokens this subscription burns per day across every agent — a hard safety net against runaway spend.
apiVersion: pai.io/v1
kind: ModelProvider
metadata:
name: google
spec:
provider: gemini
apiKeySecretRef:
name: google-key
key: api-key
maxTokensPerDay: 5000000 # daily cap shared across all agents
maxTokensPerRequest: 1000000 # Gemini supports a 1M-token context window
When the daily cap is hit, the gateway returns HTTP 429 until midnight UTC. Agents that list another provider in spec.models automatically fall over to it.
Expose via the LLM Gateway
Set externalAccess.enabled: true to let developers outside the cluster — laptops, CI, scripts — route their own LLM traffic through this provider. The Google API key stays inside Pai; clients authenticate with a Pai AccessKey instead.
spec:
externalAccess:
enabled: true
maxTokensPerDay: 2000000 # separate budget for external usage
Once enabled, developers connect with three commands:
pai login https://api.pairun.dev --access-key pak_...
eval $(pai gateway env)
claude # Claude Code routes through Pai → Gemini via on-the-fly translation
See LLM Gateway for the full onboarding flow, AccessKey management, and per-developer rate limits.
Access control
Narrow which models agents may call on this provider with allowedModels / deniedModels, or attach prompt-injection guards. See Security controls on the Model page for the full field list.