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

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

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

A Gemini API key is the credential that authenticates your calls to Google's Gemini models: each request carries the key in a Authorization header, and usage is measured and billed per token. There are two ways to get a working key: Google AI Studio (official), which provides a key for Gemini only, or Kunavo, where one OpenAI-compatible key works with Gemini, Claude, GPT, and image, video, and audio models — without needing a Google Cloud project. This guide shows how to get a key using either option and how to 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 1M input tokens and $0.75 per 1M 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",  # satu-satunya baris yang berubah
)

resp = client.chat.completions.create(
    model="gemini-2-5-flash",
    messages=[{"role": "user", "content": "Jelaskan RAG dalam dua kalimat."}],
)
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 free-tier key with low rate limits, sufficient for prototyping. Production traffic moves to paid billing on Google Cloud. Kunavo is pay-as-you-go starting with a $10 minimum top-up, with no Google Cloud billing account required, and balances never expire.

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 without needing to create a project or enable billing on Google Cloud. Google AI Studio also provides 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, and image, video, and audio models through one OpenAI-compatible API, using a single wallet billed via Stripe. For per-model rates 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 very inexpensive. Move up to gemini-3-1-pro when you need more demanding reasoning, vision, and long-context analysis.