Skip to content

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:

Terminal window
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)

Use multiple providers through the same GenAI SDK format by prefixing model names with the provider:

from google import genai
from 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 format
openai_response = client.models.generate_content(
model="openai/gpt-4o-mini",
contents="Hello from OpenAI!"
)
# Anthropic models via GenAI SDK format
anthropic_response = client.models.generate_content(
model="anthropic/claude-3-sonnet-20240229",
contents="Hello from Claude!"
)
# Azure models
azure_response = client.models.generate_content(
model="azure/gpt-4o",
contents="Hello from Azure!"
)
# Local Ollama models
ollama_response = client.models.generate_content(
model="ollama/llama3.1:8b",
contents="Hello from Ollama!"
)

Pass custom headers required by DeepintShield plugins (like governance, telemetry, etc.):

from google import genai
from google.genai.types import HttpOptions
# Configure client with custom headers
client = 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!"
)

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 genai
from google.genai.types import HttpOptions
# Pass different provider keys per request using headers
client = genai.Client(
api_key="gemini-key",
http_options=HttpOptions(base_url="http://localhost:8080/genai")
)
# Use Gemini key directly
gemini_response = client.models.generate_content(
model="gemini-1.5-flash",
contents="Hello Gemini!"
)
# Use Anthropic key for Claude models
anthropic_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 models
openai_response = client.models.generate_content(
model="openai/gpt-4o-mini",
contents="Hello GPT!",
request_options={
"headers": {"Authorization": "Bearer sk-your-openai-key"}
}
)

When thinkingConfig.thinkingBudget is set to -1, DeepintShield handles it differently per provider:

  • Gemini: Preserves -1 for 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
}
}
)

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.