Skip to content

What Is an API Key, and How Do You Get One?

Updated 26 October 2026.

In short: An API key is a long password that lets a program use a service on your behalf. For AI, it is what you paste into an app, a script or a coding tool so it can send your questions to a model - Gemini, Groq, OpenRouter and others - and count the usage against your account. You get one from the AI provider's website, usually free, in a minute.

What an API is

An API (application programming interface) is a way for one program to ask another for something. When an app sends a question to Gemini and gets an answer back, it does that through Gemini's API. You do not need to know how the AI works; the API takes a request and returns a result.

What an API key is

The provider needs to know who is asking, so it can apply your free limits and, on paid plans, your bill. The API key is how it knows. It is a long string of letters and numbers, such as gsk_... for Groq, sent with every request.

PasswordAPI key
Who uses itYou, to sign inA program, on your behalf
Where it goesA sign-in boxAn app's settings, a command or a code file
How manyUsually oneAs many as you like, one per app
If it leaksChange itDelete it and make a new one

What an API key is used for

  • Apps made for OpenAI: chat apps, writing tools and plugins that ask for an "OpenAI API key" accept keys from many other providers too. The settings for each free provider are on the free APIs page.
  • Coding apps: tools such as OpenCode use your key to run a model while you code.
  • Your own scripts: a few lines of Python or a command in PowerShell can send questions with your key.

How to get an API key for free

Each provider has its own page for keys, and several have a free tier:

ProviderFree allowanceStep-by-step
Google Gemini20 to 500 requests a day per modelGemini API key
Groq1,000 requests a dayGroq API key
OpenRouter50 requests a day on free modelsOpenRouter API key
Cloudflare Workers AI10,000 Neurons a dayCloudflare API token
Cohere1,000 calls a monthCohere API key

The full list, with every provider's limits and the ones that are not free, is on how to get AI API keys for free.

Is a ChatGPT or Claude subscription an API key?

No. A ChatGPT or Claude subscription is for the chat app. API keys are made separately, on the provider's developer site, and the subscription does not come with one. To use AI from a program for free, use a provider with a free API tier from the table above.

How to keep your API key safe

  • Treat it like a password. Anyone with your key can use your free allowance, or spend your money on a paid plan.
  • Never share it in a chat, a forum post, a screenshot or a public code repository such as GitHub.
  • Keep it out of your code. Store it in an environment variable (for example GEMINI_API_KEY) and let the code read it from there.
  • One key per app. If one app leaks its key, you delete only that one.
  • Delete a leaked key at once on the provider's API keys page, then create a new one.

What the common errors mean

What you seeWhat it means
401 or invalid API keyThe key is wrong, has a typo, or was deleted
403 or permission deniedThe key works but is not allowed to use that model or feature
429 or too many requestsYou reached a limit; wait a minute, or until the daily reset
402 or payment requiredThat model or plan needs a payment method or credits

Words to know

  • API: how one program asks another for something.
  • API key: the password that identifies your program to the API.
  • Free tier: the free allowance a provider gives each account.
  • Rate limit: how many requests you may send per minute or per day.
  • Environment variable: a named value stored on your computer, read by programs, so the key is not written inside the code.
  • Token: a piece of a word; the unit models read and write. See tokens and context windows.

Frequently asked questions

What is an API key in simple words?+

A long password that lets a program use a service on your behalf. The service uses it to know who is asking and to count usage against your account.

What is an API key used for?+

To connect apps, coding tools and your own scripts to a service. For AI, you paste it into an app or a command so it can send questions to a model such as Gemini or Groq.

How do I get an API key for free?+

From a provider with a free tier: Google AI Studio (Gemini), Groq, OpenRouter, Cloudflare Workers AI or Cohere. Each has a page in its dashboard where you create a key in a minute.

Is a ChatGPT subscription an API key?+

No. A ChatGPT subscription is for the chat app; API keys are made separately on the provider's developer site.

Is it safe to share my API key?+

No. Anyone with your key can use your allowance or spend money on a paid plan. If it leaks, delete it on the provider's API keys page and create a new one.

More free API key tutorials

Want to use these APIs in a desktop app? OpenCode is a free, open-source AI coding app for Windows, Mac and Linux. How to add free API keys to OpenCode and pick a model.