Back to guides
API Key·June 18, 2026·Updated September 24, 2026·7 min read

Gemini API key — how to obtain and use it with the OpenAI SDK

How to create a Gemini API key through both routes — Google AI Studio (official) or an OpenAI-compatible Kunavo key without a Google Cloud project — and make the first call.

A Gemini API key is a credential that authenticates your calls to Google's Gemini models: each request carries the key in the Authorization header, and usage is metered and billed by token. There are two ways to get a working key: Google AI Studio (official), which issues a key for Gemini only, or Kunavo, where a single OpenAI-compatible key reaches Gemini, Claude, GPT, and image, video, and audio models — without a Google Cloud project. This guide shows how to get a key through either method and make your first call.

Option 1 — Google AI Studio (official)

This is the right path if Gemini is the only model you plan to call.

  1. Sign in to aistudio.google.com with your Google account.
  2. Open Get API key → Create API key. The key is in the format AIza....
  3. The free tier is limited and suited to prototyping. For production volume, the key must be linked to a Google Cloud project with an active billing account.

If you also use Claude, image, or video models, this path means managing separate keys, SDKs, and bills for each provider.

Option 2 — Kunavo (recommended for production)

Kunavo puts Gemini behind an OpenAI-compatible API. One sk-kn- key calls Gemini and every other model, with a single wallet billed via Stripe and no Google Cloud project at all. Gemini costs around 70% below Google's official list prices — Flash, for example, costs $0.09 per 1 million input tokens and $0.75 per 1 million output tokens. It's pay-as-you-go starting with a minimum $10 top-up, and your balance never expires.

  1. Sign up at kunavo.com.
  2. Top up $10 — pay as you go; your balance never expires.
  3. Create a key at /app/keys. The key starts with sk-kn- and is shown only once; save it in an environment variable.
  4. Make a call by pointing the OpenAI SDK to https://api.kunavo.com/v1 and using a Gemini slug.

Quickstart

Keep using the official OpenAI SDK. Change 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",  # dòng duy nhất thay đổi
)

resp = client.chat.completions.create(
    model="gemini-2-5-flash",
    messages=[{"role": "user", "content": "Giải thích RAG trong hai câu."}],
)
print(resp.choices[0].message.content)

Key security

  • Never expose your key on the client side. Browser and mobile bundles are public — always proxy requests through your own server. Store the key in an environment variable, outside version-controlled code.
  • Use one key per project or environment, so a single leak can be revoked without taking everything else down.
  • Rotate keys regularly. Kunavo allows multiple active keys at once, so rotation is a smooth transition rather than a hard cutover.
  • Set a spending limit for each key in the dashboard and monitor /app/usage to flag unexpected traffic, broken down by key.

Frequently asked questions

Is the Gemini API free?

Google AI Studio issues a key on a free tier with low rate limits, enough for prototyping. Production traffic moves to paid billing on Google Cloud. Kunavo is pay-as-you-go starting with a minimum $10 top-up, requires no Google Cloud billing account, and the balance never expires.

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

Yes. With Kunavo, you create a single sk-kn- key and call Gemini through an OpenAI-compatible endpoint, with no need to create a Google Cloud project or enable billing. Google AI Studio also issues a free-tier key without a project, but Google requires a billing account for production.

What's the difference between a Google Gemini key and a Kunavo key?

A Google key calls only Gemini and is billed through a Google Cloud account. A Kunavo key calls Gemini along with Claude, GPT, image, video, and audio models through a single OpenAI-compatible API, with one wallet billed via Stripe. For model-by-model pricing and cost examples, see 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 extremely inexpensive. Switch to gemini-3-1-pro when you need harder reasoning, vision, and long-context analysis.