Zero-Code AI App BuilderZero-Code AI App Builder
Builder Foundations

API keys

What they are and why they matter

When your app talks to the Claude API, Supabase, or Stripe, it has to prove who it is. It does that with an API key. Let's see what that means and how to handle one safely.

What is an API key?

An API key is a long, random password that lets your app use a service. It's like a house key and a credit card rolled into one.

  • Like a house key: whoever holds it can get in. The service doesn't know who is holding it.
  • Like a credit card: every request is charged to your account.

Here is roughly what one looks like (this one is fake):

text
sk-ant-api03-Xy7fake9Qm2fakeLp4KEYw8Rnot-real-0000

Many secret keys start with sk-, which stands for "secret key." When you see that, treat it like cash.

Creating a key

Every provider has a dashboard page for keys. The menus change often, but the steps are almost always the same.

Log in
provider console
→
API keys page
create new key
→
Copy once
shown only once
→
Store safely
.env.local
The life of an API key, from creation to safe storage.
  1. Log in to the provider's developer console (for example, the Anthropic Console for the Claude API).
  2. Look for a page called "API keys," usually in settings.
  3. Click "Create key" and give it a clear name, like my-app-local.
  4. Copy the key right away. Most providers show it only once.
  5. Paste it straight into your .env.local file. You'll learn how on the next page.
While you're in the dashboard, set a monthly spending limit. If a key ever leaks, the damage stays small.

Revoking a key

Revoking means switching a key off forever. It's like changing your locks. The old key stops working immediately.

Revoke a key when:

  • You accidentally pasted it into a public place, like GitHub, a screenshot, or a shared chat.
  • You stopped using a project.
  • You're not sure whether it was exposed. When in doubt, revoke and create a new one.

What happens if a key leaks?

Automated bots scan public code on GitHub around the clock. A leaked key can be found and used within minutes. People have woken up to large bills this way.

If it happens to you, don't panic. Follow these steps:

  1. Revoke the leaked key in the provider's dashboard right away.
  2. Create a new key and put it in your .env.local file and on your host.
  3. Check your usage and billing page for strange activity.
Deleting the file or the commit is not enough. Once a key has been public, assume someone copied it. Always revoke it.

Public keys vs secret keys

Some services give you two kinds of keys. Supabase and Stripe are good examples.

FeaturePublic keySecret key
Supabaseanon / publishable keyservice_role / secret key
Stripepk_test_...sk_test_...
AI APIs (Claude, OpenAI, Gemini)NoneYour API key
OK in the browser?YesNo
Public keys are made to be seen. Secret keys must never leave the server.

A public key is safe in the browser only because other protections do the real work. For Supabase, that protection is Row Level Security. Without it, the public key can expose your data.

Common mistakes

Pasting a key into a prompt

Prompt
Wrong: "Here's my key sk-ant-api03-..., please add it to my code."
Right: "Read the Claude API key from the ANTHROPIC_API_KEY environment variable. I'll add the value myself."
  • Using one key for every project. Create one key per project, so you can revoke one without breaking the others.
  • Sharing screenshots with keys visible. Blur or crop them first.
  • Using the Supabase service_role key in the frontend because "it fixed the error." It removes all your security.

Practice

Try these exercises to lock in what you just learned.

Quiz
Not started
You just noticed your Claude API key in a public GitHub repo. What should you do first?
Quiz
Not started
Which key is designed to be safe in the browser (with the right protections in place)?
Quiz
Not started
You want Claude Code to add the AI assistant feature. What's the safest way to handle the key?

What's next?

You know what keys are and why they matter. Next, let's learn where to keep them: in a .env file.