Use the Google Gemini SDK
Use Google's official @google/genai SDK with Cova AI Gateway: your app sends only its Cova key, and the gateway uses the Google key stored in CoreValue.
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 your application sends only your Cova API key. Add your Google API key once under Gateway → Provider keys; the gateway uses it upstream and your application never sees it.
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 — Google bills you directly, on the Google key you add to CoreValue (BYOK)
- Observability — cost, tokens, latency tracked automatically
- Streaming —
:streamGenerateContentwith SSE passthrough
This uses Google's native SDK, so the full feature set (grounding, function calling, multimodal, etc.) is preserved 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; the Google key stays in CoreValue
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; the Google key stays in CoreValue
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 and the Google key you added
- 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 keys for BYOK.
Related
- Provider Routing — How the gateway routes to the best provider
- Error Handling — Fallback behavior and error codes