Overview
Overview
Section titled “Overview”DeepintShield provides complete Google GenAI API compatibility through protocol adaptation. The integration handles request transformation, response normalization, and error mapping between Google’s GenAI API specification and DeepintShield’s internal processing pipeline.
This integration enables you to utilize DeepintShield’s features like governance, load balancing, semantic caching, multi-provider support, and more, all while preserving your existing Google GenAI SDK-based architecture.
Endpoint: /genai
Install with the GenAI extra:
pip install "deepintshield[genai]"from deepintshield import DeepintShield
shield = DeepintShield(virtual_key="sk-bf-your-virtual-key")client = shield.genai() # pre-wired google.genai.Client
response = client.models.generate_content( model="gemini-1.5-flash", contents="Hello!",)
print(response.text)from google import genaifrom google.genai.types import HttpOptions
client = genai.Client( api_key="sk-bf-your-virtual-key", http_options=HttpOptions( base_url="https://app.deepintshield.com/genai", headers={"x-bf-vk": "sk-bf-your-virtual-key"}, ),)
response = client.models.generate_content( model="gemini-1.5-flash", contents="Hello!",)
print(response.text)import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI("sk-bf-your-virtual-key", { baseUrl: "https://app.deepintshield.com/genai", customHeaders: { "x-bf-vk": "sk-bf-your-virtual-key" },});
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });const response = await model.generateContent("Hello!");
console.log(response.response.text());Provider/Model Usage Examples
Section titled “Provider/Model Usage Examples”Use multiple providers through the same GenAI SDK format by prefixing model names with the provider:
from google import genaifrom google.genai.types import HttpOptions
client = genai.Client( api_key="dummy-key", http_options=HttpOptions(base_url="http://localhost:8080/genai"))
# Google Vertex models (default)vertex_response = client.models.generate_content( model="gemini-1.5-flash", contents="Hello from Gemini!")
# OpenAI models via GenAI SDK formatopenai_response = client.models.generate_content( model="openai/gpt-4o-mini", contents="Hello from OpenAI!")
# Anthropic models via GenAI SDK formatanthropic_response = client.models.generate_content( model="anthropic/claude-3-sonnet-20240229", contents="Hello from Claude!")
# Azure modelsazure_response = client.models.generate_content( model="azure/gpt-4o", contents="Hello from Azure!")
# Local Ollama modelsollama_response = client.models.generate_content( model="ollama/llama3.1:8b", contents="Hello from Ollama!")import { GoogleGenerativeAI } from "@google/generative-ai";
const genAI = new GoogleGenerativeAI("dummy-key", { baseUrl: "http://localhost:8080/genai",});
// Google Vertex models (default)const geminiModel = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });const vertexResponse = await geminiModel.generateContent("Hello from Gemini!");
// OpenAI models via GenAI SDK formatconst openaiModel = genAI.getGenerativeModel({ model: "openai/gpt-4o-mini" });const openaiResponse = await openaiModel.generateContent("Hello from OpenAI!");
// Anthropic models via GenAI SDK formatconst anthropicModel = genAI.getGenerativeModel({ model: "anthropic/claude-3-sonnet-20240229" });const anthropicResponse = await anthropicModel.generateContent("Hello from Claude!");
// Azure modelsconst azureModel = genAI.getGenerativeModel({ model: "azure/gpt-4o" });const azureResponse = await azureModel.generateContent("Hello from Azure!");
// Local Ollama modelsconst ollamaModel = genAI.getGenerativeModel({ model: "ollama/llama3.1:8b" });const ollamaResponse = await ollamaModel.generateContent("Hello from Ollama!");Adding Custom Headers
Section titled “Adding Custom Headers”Pass custom headers required by DeepintShield plugins (like governance, telemetry, etc.):
from google import genaifrom google.genai.types import HttpOptions
# Configure client with custom headersclient = genai.Client( api_key="dummy-key", http_options=HttpOptions( base_url="http://localhost:8080/genai", headers={ "x-bf-vk": "vk_12345", # Virtual key for governance } ))
response = client.models.generate_content( model="gemini-1.5-flash", contents="Hello with custom headers!")import { GoogleGenerativeAI } from "@google/generative-ai";
// Configure client with custom headersconst genAI = new GoogleGenerativeAI("dummy-key", { baseUrl: "http://localhost:8080/genai", customHeaders: { "x-bf-vk": "vk_12345", // Virtual key for governance },});
const model = genAI.getGenerativeModel({ model: "gemini-1.5-flash" });const response = await model.generateContent("Hello with custom headers!");Using Direct Keys
Section titled “Using Direct Keys”Pass API keys directly in requests to bypass DeepintShield’s load balancing. You can pass any provider’s API key (OpenAI, Anthropic, Mistral, etc.) since DeepintShield only looks for Authorization, x-api-key and x-goog-api-key headers. This requires the Allow Direct API keys option to be enabled in DeepintShield configuration.
Learn more: See Key Management for enabling direct API key usage.
from google import genaifrom google.genai.types import HttpOptions
# Pass different provider keys per request using headersclient = genai.Client( api_key="gemini-key", http_options=HttpOptions(base_url="http://localhost:8080/genai"))
# Use Gemini key directlygemini_response = client.models.generate_content( model="gemini-1.5-flash", contents="Hello Gemini!")
# Use Anthropic key for Claude modelsanthropic_response = client.models.generate_content( model="anthropic/claude-3-sonnet-20240229", contents="Hello Claude!", request_options={ "headers": {"x-api-key": "your-anthropic-api-key"} })
# Use OpenAI key for GPT modelsopenai_response = client.models.generate_content( model="openai/gpt-4o-mini", contents="Hello GPT!", request_options={ "headers": {"Authorization": "Bearer sk-your-openai-key"} })import { GoogleGenerativeAI } from "@google/generative-ai";
// Pass different provider keys per request using headersconst genAI = new GoogleGenerativeAI("gemini-key", { baseUrl: "http://localhost:8080/genai",});
// Use Gemini key directlyconst geminiModel = genAI.getGenerativeModel({ model: "gemini-1.5-flash"});const geminiResponse = await geminiModel.generateContent("Hello Gemini!");
// Use Anthropic key for Claude modelsconst anthropicModel = genAI.getGenerativeModel({ model: "anthropic/claude-3-sonnet-20240229", requestOptions: { customHeaders: { "x-api-key": "your-anthropic-api-key" } }});const anthropicResponse = await anthropicModel.generateContent("Hello Claude!");
// Use OpenAI key for GPT modelsconst gptModel = genAI.getGenerativeModel({ model: "openai/gpt-4o-mini", requestOptions: { customHeaders: { "Authorization": "Bearer sk-your-openai-key" } }});const gptResponse = await gptModel.generateContent("Hello GPT!");Dynamic Thinking Budget
Section titled “Dynamic Thinking Budget”When thinkingConfig.thinkingBudget is set to -1, DeepintShield handles it differently per provider:
- Gemini: Preserves
-1for native dynamic thinking support - Anthropic, Bedrock, Cohere: Converts to minimum reasoning budget value (1024)
- OpenAI: Converts to medium reasoning effort
response = client.models.glenerate_content( model="gemini-2.5-flash", contents="Complex reasoning task", config={ "thinking_config": { "include_thoughts": true, "thinking_budget": -1 # Dynamic thinking } })Supported Features
Section titled “Supported Features”The Google GenAI integration supports all features that are available in both the Google GenAI SDK and DeepintShield core functionality. If the Google GenAI SDK supports a feature and DeepintShield supports it, the integration will work seamlessly.
Next Steps
Section titled “Next Steps”- OpenAI SDK - GPT integration patterns
- Configuration - DeepintShield setup and configuration
- Core Features - Advanced DeepintShield capabilities