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/candidates format 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 — :streamGenerateContent with 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/genai
import { 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-genai
from 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:

AspectValue
Endpointhttps://gateway.corevalue.dev/v1beta/models/{model}:generateContent
Auth headerx-goog-api-key: <your-cova-key>
Request bodycontents: [{role, parts}]
Streaming:streamGenerateContent?alt=sse
Response{candidates: [{content}]}

The gateway:

  1. Detects the native Gemini format from the URL path (:generateContent / :streamGenerateContent)
  2. Authenticates your Cova key
  3. Resolves the model to a provider and the Google key you added
  4. Forwards the request to Google's API in the same format
  5. Streams the response back unmodified
  6. 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.

On this page