Bastio
Providers

Google Gemini Integration

Complete guide to using Google Gemini with Bastio for Gemini 3, 2.5, and 1.5 models.

Google Gemini Integration

Use Google's Gemini models through Google AI Studio or Vertex AI while maintaining Bastio's security protection.

Overview

Bastio offers full support for Google Gemini models, allowing you to:

  • Access latest models - Gemini 3 Pro, 2.5 Pro/Flash, and 1.5 series
  • Flexible integration - Support for both AI Studio (API Key) and Vertex AI (OAuth)
  • Full security coverage - All Bastio security features work with Gemini
  • Unified API - Use OpenAI-compatible endpoints for Gemini models

Supported Models

Bastio supports the latest Gemini models:

ModelIDContextInput/Output Price
Gemini 3 Progemini-3-pro2M$2.00/$12.00 per 1M tokens
Gemini 2.5 Progemini-2.5-pro2M$1.25/$5.00 per 1M tokens
Gemini 2.5 Flashgemini-2.5-flash1M$0.10/$0.40 per 1M tokens
Gemini 1.5 Progemini-1.5-pro2M$1.25/$5.00 per 1M tokens
Gemini 1.5 Flashgemini-1.5-flash1M$0.075/$0.30 per 1M tokens
Gemini 1.5 Flash-8Bgemini-1.5-flash-8b1M$0.0375/$0.15 per 1M tokens

Quick Start

Prerequisites

  1. Google Cloud Project or AI Studio account
  2. API Key (for AI Studio) or Service Account (for Vertex AI)
  3. Enabled Vertex AI API (if using Vertex AI)

Step 1: Get Credentials

  1. Go to Google AI Studio
  2. Click Get API key
  3. Create a key in a new or existing project
  1. Go to Google Cloud Console
  2. Create a Service Account with Vertex AI User role
  3. Generate a JSON key for the service account

Configuration

Via Dashboard

  1. Go to Dashboard → Proxies → Create New Proxy
  2. Select Google Gemini as provider
  3. Choose your authentication method:
    • API Key: Enter your AI Studio API key
    • Vertex AI: Upload your Service Account JSON

Via API

# Create Gemini proxy
curl -X POST https://api.bastio.ai/proxy \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Production Gemini",
    "provider": "google",
    "llm_mode": "byok",
    "model_behavior": "passthrough"
  }'

# Add API Key
curl -X POST https://api.bastio.ai/keys/provider \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "google",
    "key_name": "AI Studio Key",
    "api_key": "your-google-api-key"
  }'

Making Requests

Bastio provides an OpenAI-compatible interface for Gemini, so you can use standard OpenAI SDKs.

Python Example

from openai import OpenAI

client = OpenAI(
    base_url="https://api.bastio.ai/v1/guard/{PROXY_ID}/v1",
    api_key="your-bastio-api-key"
)

response = client.chat.completions.create(
    model="gemini-3-pro",
    messages=[
        {"role": "user", "content": "Explain quantum computing"}
    ]
)

print(response.choices[0].message.content)

JavaScript Example

import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: 'https://api.bastio.ai/v1/guard/{PROXY_ID}/v1',
  apiKey: process.env.BASTIO_API_KEY,
});

const response = await client.chat.completions.create({
  model: 'gemini-2.5-flash',
  messages: [
    { role: 'user', content: 'Hello from Gemini!' }
  ],
});

console.log(response.choices[0].message.content);

Streaming Example

stream = client.chat.completions.create(
    model="gemini-1.5-pro",
    messages=[{"role": "user", "content": "Write a poem"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="", flush=True)

Features & Limitations

Supported Features

  • Text Generation: Full support for chat completions
  • Streaming: Real-time token streaming
  • Function Calling: Support for tools and function calling
  • Vision: Multimodal support (image input)
  • System Instructions: Supported via system role messages

Vision Example

response = client.chat.completions.create(
    model="gemini-1.5-flash",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "What's in this image?"},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/image.jpg"
                    }
                }
            ]
        }
    ]
)

Troubleshooting

Invalid API Key

Error: 401 Unauthorized or Invalid API Key Solution: Check that your AI Studio key is active and has not been revoked.

Quota Exceeded

Error: 429 Too Many Requests Solution: Check your Google Cloud or AI Studio quota limits. Gemini models have different rate limits depending on your tier.

Model Not Found

Error: 404 Not Found Solution: Ensure the model ID is correct (e.g., gemini-1.5-pro not gemini-pro-1.5) and available in your region.

Additional Resources