Back to guides
API key·July 10, 2026·Updated September 24, 2026·7 min read

Gemini API Key — How to Get and Use It with the OpenAI SDK

Two ways to create a Gemini API key — Google AI Studio (official) or a single OpenAI-compatible Kunavo key, without a Google Cloud project — plus your first call in a few minutes.

A Gemini API key authenticates your calls to Google’s Gemini models: each request carries the key in the Authorization header, and the platform measures and bills usage through it. There are two ways to get a Gemini API key—directly through Google AI Studio (the official route), or through Kunavo: an OpenAI-compatible key that gives you access to Gemini, Claude, GPT, and image and video models without a Google Cloud project.

Option 1 — Google AI Studio (official)

If Gemini is the only model you’ll ever call, get a key directly from Google:

  1. Open aistudio.google.com and sign in with a Google account.
  2. Go to Get API key → Create API key. Keys start with AIza… and are shown only once.
  3. The free tier is rate-limited and suitable for prototyping. For production, link the key to a Google Cloud billing account.

This is the right approach as long as you only need Gemini. Once you also use Claude, GPT, or image and video models, you manage one key, SDK, and bill per provider.

Option 2 — Kunavo (recommended for production)

Kunavo puts Gemini behind an OpenAI-compatible API. One sk-kn- key reaches all models on the same endpoint — no Google Cloud project, Gemini at about 70% below Google's list price ($0.09 / $0.75 per 1M tokens), one Stripe balance, and pay-as-you-go starting with a $10 minimum top-up. The balance covers Gemini, Claude, GPT, image, and video models together, and never expires.

  1. Sign up. Create a Kunavo account at kunavo.com.
  2. Add $10. Pay as you go, starting with a $10 minimum top-up; the balance never expires.
  3. Create a key. Generate a key at /app/keys. It starts with sk-kn- and is shown only once—store it in an environment variable.
  4. Make a call. Point the OpenAI SDK to https://api.kunavo.com/v1 and call a Gemini slug.

Quickstart

Keep the official OpenAI SDK. Change only base_url and the model name—nothing else.

gemini_quickstart.py
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["KUNAVO_API_KEY"],
    base_url="https://api.kunavo.com/v1",  # la seule ligne qui change
)

resp = client.chat.completions.create(
    model="gemini-2-5-flash",
    messages=[{"role": "user", "content": "Résume l'intrigue de Dune en deux phrases."}],
)
print(resp.choices[0].message.content)

The same pattern works for Node.js and curl; per-model pricing and detailed examples are in the Gemini API pricing guide.

Keep your key secure

  • Use environment variables, not source code. Never commit the key to your repository; read it from an environment variable. Never expose it in a browser or mobile bundle—always route requests through your own server.
  • Use one key per project or environment. Then you can revoke a leaked key without breaking anything else.
  • Rotate keys regularly. Kunavo allows multiple active keys, so rotation is a clean overlap rather than a hard cutover.
  • Set spending limits per key. Set limits for each key in the dashboard and monitor unexpected traffic by key at /app/usage.

Frequently asked questions

Is the Gemini API key free?

Google AI Studio provides a free key with low rate limits, sufficient for prototyping. Production traffic requires paid billing. Kunavo offers pay-as-you-go starting with a $10 minimum top-up, with no Google Cloud billing account required—and your balance never expires.

Can I get a Gemini API key without a Google Cloud account?

Yes. A Google AI Studio key works for prototyping without a Google Cloud project, but it has rate limits; for production volume, Google requires a Google Cloud billing account. A Kunavo key doesn’t require a Google Cloud project. You can call Gemini through the OpenAI-compatible endpoint and pay through Stripe.

Gemini key vs. Kunavo key — what’s the difference?

A Google key calls Gemini only and is billed through a Google Cloud account. A Kunavo key calls Gemini, Claude, GPT, and image and video models through an OpenAI-compatible API, with a single Stripe balance and no Google Cloud project. Per-model pricing is in the Gemini API pricing guide.

Which Gemini model should I start with?

Start with gemini-2-5-flash for everyday chat, extraction, and summarization—it’s fast and very inexpensive. Switch to gemini-3-1-pro for difficult reasoning, vision, and long-context analysis.