AI GatewayIntegrations

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 passthroughcontents/candidates format preserved, no lossy translation
  • Billing — pass-through billing (PTB) or bring your own keys (BYOK)
  • Observability — cost, tokens, latency tracked automatically
  • Streaming:streamGenerateContent with 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/genai
import { 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-genai
from 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:

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 (BYOK first, then Cova managed keys)
  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 Settings for BYOK.

On this page