Quickstart: Google Gemini
Anonymize Google Gemini requests in under 10 lines
Prerequisites
rdakt-aiandgoogle-genaiinstalledGOOGLE_API_KEYenvironment variable set
Async Usage
import httpx
from google import genai
from rdakt_ai import RdaktMiddleware
client = genai.Client(
http_options={
"transport": RdaktMiddleware(inner=httpx.AsyncHTTPTransport()),
},
)
response = await client.aio.models.generate_content(
model="gemini-2.0-flash",
contents="Summarize the case for John Smith (SSN 123-45-6789)",
)
print(response.text)Streaming
stream = await client.aio.models.generate_content_stream(
model="gemini-2.0-flash",
contents="Write a report about Jane Doe, email jane@acme.com",
)
async for chunk in stream:
print(chunk.text, end="", flush=True)Gemini-Specific Notes
Google Gemini uses a different message format (contents[].parts[].text) compared to OpenAI/Anthropic (messages[].content). Rdakt AI detects the provider from the request URL and handles format differences automatically.
What Just Happened?
- Detection — PII detected in the
contentsfield - Anonymization — Real values replaced with tokens before reaching Gemini
- Deanonymization — Gemini's SSE stream deanonymized in real-time