Google Gemini API Integration: Gemini Pro, Ultra, Flash
Google Gemini is natively multimodal: processes text, images, audio, video and code in a single context. Gemini 1.5 Pro has a context window of 1 million tokens — a unique characteristic for working with large documents. Gemini Flash is fast and cheap for high-load tasks.
Basic Integration via Google AI SDK
import google.generativeai as genai
from google.generativeai.types import HarmCategory, HarmBlockThreshold
genai.configure(api_key="GOOGLE_API_KEY")
model = genai.GenerativeModel("gemini-1.5-pro")
# Simple call
response = model.generate_content("Explain quantum computing")
print(response.text)
# Generation configuration
response = model.generate_content(
"Data analysis",
generation_config=genai.GenerationConfig(
temperature=0.1,
max_output_tokens=2048,
response_mime_type="application/json", # Force JSON
),
)
# Multimodality: text + image
import PIL.Image
image = PIL.Image.open("diagram.png")
response = model.generate_content(["Describe the architecture in the diagram:", image])
# Video analysis (unique to Gemini)
video_file = genai.upload_file("presentation.mp4")
response = model.generate_content(["Make a summary of the video:", video_file])
Streaming and Async
# Streaming
for chunk in model.generate_content("Long text...", stream=True):
print(chunk.text, end="", flush=True)
# Async
import asyncio
async def async_generate(prompt: str) -> str:
async_model = genai.GenerativeModel("gemini-1.5-flash")
response = await async_model.generate_content_async(prompt)
return response.text
Chat with History
chat = model.start_chat(history=[])
response = chat.send_message("Hello! My name is John.")
response = chat.send_message("What is my name?")
# Model remembers context from history
Function Calling (Tool Use)
def get_stock_price(ticker: str) -> dict:
"""Returns stock price"""
return {"ticker": ticker, "price": 150.0, "currency": "USD"}
tools = [get_stock_price] # Gemini accepts Python functions directly!
model_with_tools = genai.GenerativeModel("gemini-1.5-pro", tools=tools)
response = model_with_tools.generate_content("What is the price of Apple (AAPL)?")
Vertex AI (Enterprise)
import vertexai
from vertexai.generative_models import GenerativeModel
vertexai.init(project="my-project", location="us-central1")
model = GenerativeModel("gemini-1.5-pro-preview-0514")
response = model.generate_content("Request")
Cost of Gemini (2025)
| Model | Input (1M) | Output (1M) |
|---|---|---|
| Gemini 1.5 Pro | $3.50 | $10.50 |
| Gemini 1.5 Flash | $0.075 | $0.30 |
| Gemini 1.5 Flash-8B | $0.0375 | $0.15 |
Timeline
- Basic integration: 0.5–1 day
- Multimodal scenarios: 2–3 days
- Vertex AI production: 1 week







