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 either route — 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 reaches 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'll call.

  1. Sign in to aistudio.google.com with a Google account.
  2. Open Get API key → Create API key. Keys have the format AIza....
  3. The free tier is limited and intended for prototypes. For production volume, you must attach the key to a Google Cloud project with a billing account enabled.

If you also use Claude, image, or video models, this option leaves you managing a separate key, SDK, and bill for each provider.

Option 2 — Kunavo (recommended for production)

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

  1. Sign up at kunavo.com.
  2. Add $10 — pay as you go, and your balance never expires.
  3. Create a key at /app/keys. It 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 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",  # a única linha que muda
)

resp = client.chat.completions.create(
    model="gemini-2-5-flash",
    messages=[{"role": "user", "content": "Explique RAG em duas frases."}],
)
print(resp.choices[0].message.content)

Key security

  • Never expose the key on the client. Browser and mobile bundles are public — always proxy through your own server. Store the key in environment variables, outside version-controlled code.
  • Use one key per project or environment, so a leak can be revoked without disrupting anything else.
  • Rotate keys regularly. Kunavo allows multiple active keys at once, so rotation is a clean overlap rather than a hard cutover.
  • Set spending limits per key in the dashboard and monitor /app/usage to spot 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, enough for prototyping. Production traffic moves to paid billing on Google Cloud. Kunavo is pay-as-you-go starting with a $10 minimum deposit, 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 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 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 extremely inexpensive. Move to gemini-3-1-pro when you need more demanding reasoning, vision, and long-context analysis.