Google Gemini SDK (Native)
Use Google's official @google/genai SDK with Cova AI Gateway — no Google API key required, just your Cova key.
Overview
Google's official @google/genai SDK (JavaScript) and google-genai SDK (Python) send requests in Google's native Gemini format — not OpenAI format. Cova AI Gateway supports this natively, so you can use the Google SDK with only your Cova API key. No Google API key needed.
The gateway handles:
- Auth translation — your Cova key authenticates with the gateway; the gateway injects the Google key upstream
- Native format passthrough —
contents/candidatesformat preserved, no lossy translation - Billing — pass-through billing (PTB) or bring your own keys (BYOK)
- Observability — cost, tokens, latency tracked automatically
- Streaming —
:streamGenerateContentwith SSE passthrough
This is different from the OpenAI-compatible integration, which wraps Gemini behind the OpenAI Chat Completions format. The native SDK approach preserves Google's full feature set (grounding, function calling, multimodal, etc.) without translation loss.
Quick Start
JavaScript / TypeScript
npm install @google/genaiimport { GoogleGenAI } from "@google/genai";
const genAI = new GoogleGenAI({
apiKey: process.env.COVA_API_KEY, // Your Cova key — no Google key needed
httpOptions: {
baseUrl: "https://gateway.corevalue.dev",
},
});
const response = await genAI.models.generateContent({
model: "gemini-2.5-flash",
contents: "What is the capital of France?",
});
console.log(response.text);Python
pip install google-genaifrom google import genai
client = genai.Client(
api_key=os.environ["COVA_API_KEY"], # Your Cova key — no Google key needed
http_options={"baseUrl": "https://gateway.corevalue.dev"},
)
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="What is the capital of France?",
)
print(response.text)How It Works
The Google SDK sends requests in Google's native format:
| Aspect | Value |
|---|---|
| Endpoint | https://gateway.corevalue.dev/v1beta/models/{model}:generateContent |
| Auth header | x-goog-api-key: <your-cova-key> |
| Request body | contents: [{role, parts}] |
| Streaming | :streamGenerateContent?alt=sse |
| Response | {candidates: [{content}]} |
The gateway:
- Detects the native Gemini format from the URL path (
:generateContent/:streamGenerateContent) - Authenticates your Cova key
- Resolves the model to a provider (BYOK first, then Cova managed keys)
- Forwards the request to Google's API in the same format
- Streams the response back unmodified
- Logs usage (tokens, cost, latency) asynchronously
Streaming
const response = await genAI.models.generateContentStream({
model: "gemini-2.5-flash",
contents: "Tell me a story",
});
for await (const chunk of response) {
process.stdout.write(chunk.text);
}The gateway passes SSE chunks through unmodified — no buffering, no format translation.
Function Calling
const response = await genAI.models.generateContent({
model: "gemini-2.5-flash",
contents: "What's the weather in Tokyo?",
config: {
tools: [{
functionDeclarations: [{
name: "get_weather",
parameters: {
type: "object",
properties: {
city: { type: "string" }
},
required: ["city"]
}
}]
}],
},
});Vertex AI
For Vertex AI (Google Cloud) models, use the same SDK with a different base URL:
const genAI = new GoogleGenAI({
apiKey: process.env.COVA_API_KEY,
httpOptions: {
baseUrl: "https://gateway.corevalue.dev",
apiVersion: "v1beta1",
headers: {
"Cova-Provider": "vertex",
},
},
});Vertex AI requires a Google Cloud project with Vertex AI API enabled. Configure your GCP service account key in Provider Settings for BYOK.
Related
- Provider Routing — How the gateway routes to the best provider
- Error Handling — Fallback behavior and error codes
- Gemini API (OpenAI-compatible) — Use Gemini through the OpenAI SDK format