← Blog

How to Get an OpenAI API Key: Full Setup Walkthrough

2026-09-06 · 5 min read · SubToAPI Team

Getting an OpenAI API key takes about five minutes: create an account on the OpenAI developer platform, generate a secret key from the API Keys page, attach a payment method, and set a usage limit so you don't get surprised by a bill. That's the whole process. The rest of this guide covers the details that actually trip people up — billing setup, key permissions, storage, and testing the key once you have it.

If you've searched for this, you're probably about to build something: a script, a chatbot, an internal tool, or a product feature. The steps below get you from zero to a working key you can paste into curl or a JavaScript file.

Before you start

You need three things:

Note that an OpenAI API key is not the same as a ChatGPT login. You can use ChatGPT for free or on a Plus plan without ever touching the API, and vice versa. The API is billed separately, based on the tokens you send and receive.

Step 1: Create a platform account

Go to platform.openai.com and sign up. If you already use ChatGPT with the same email, you can log in with that account — it just gives you access to the developer platform in addition to the chat interface.

You'll be asked to verify your phone number. This is mandatory for new accounts and is used to limit one free trial per person (OpenAI no longer offers free API credits to most new signups, so expect to add a card early).

Step 2: Add a payment method

Go to Settings → Billing and add a card. Without billing set up, your API key will authenticate but every request will fail with a quota error. This is the single most common issue people run into: they generate a key, try a request, and get rejected because there's no payment method on file yet.

You can set a monthly budget cap here too — more on that below.

Step 3: Generate the API key

  1. Open Settings → API Keys (sometimes listed under your organization name in the top-left dropdown)
  2. Click Create new secret key
  3. Give it a name that describes where it will be used, e.g. prod-backend or local-dev
  4. Choose a permission scope if prompted — restricted keys can be limited to specific endpoints, which is worth doing for anything shared with a teammate or deployed to a service you don't fully control
  5. Copy the key immediately

The key is shown once. If you close the dialog without copying it, you'll need to generate a new one — OpenAI does not let you view the full key again.

A key looks like:

sk-proj-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Step 4: Set usage limits

This step is easy to skip and it's the one that saves people money. In Settings → Limits, set a monthly budget. If a runaway loop or a bug in your retry logic starts hammering the API, the limit stops billing once it's hit instead of letting a mistake run for hours.

Set the limit lower than you think you need at first — you can always raise it once you understand your actual usage pattern.

Step 5: Store the key safely

Never hardcode the key in source code or commit it to a repository. Use an environment variable:

export OPENAI_API_KEY="sk-proj-your-key-here"

In a Node project, load it from a .env file with a library like dotenv, and make sure .env is in .gitignore. If a key does leak into a public repo, revoke it immediately from the API Keys page and generate a new one — OpenAI's abuse detection sometimes catches this automatically and disables the key for you, but don't rely on that.

Step 6: Test the key

A quick curl call confirms everything is wired up correctly:

curl https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o-mini",
    "messages": [{"role": "user", "content": "Say hello in one word"}]
  }'

A successful response returns a JSON object with a choices array containing the model's reply. If you get a 401, the key is wrong or wasn't copied fully. If you get a 429 or quota error, billing isn't set up or your limit is already exhausted.

What comes after the key

Once the key works, most people run into the same second problem: managing it across a team, tracking who used how many tokens, and rotating keys without breaking production. OpenAI's dashboard gives you basic usage graphs, but per-teammate API keys and seat-based access aren't part of the default flow.

If your stack also uses Claude — whether alongside OpenAI or as your primary model — SubToAPI turns an existing Claude subscription into a proper HTTPS API with its own scoped sub_live_... keys, streaming, tool use, and per-seat usage metadata, so you're not juggling shared credentials across a team. Setup follows the same shape as what's above: sign up, generate a key, drop it into a request. See the quickstart or messages docs if that's relevant to what you're building, or check pricing for the Solo, Team, and Scale plans.

questions

Do I need ChatGPT Plus to get an API key? No. ChatGPT Plus is a separate subscription for the chat interface. The API is billed independently, per token, and requires its own payment method on the developer platform even if you already pay for Plus.

Why does my API key return a quota error? This almost always means no payment method is on file, or your usage limit has been reached. Add a card under Settings → Billing and check your budget cap under Settings → Limits.

Can I have more than one API key? Yes, and you should. Create separate keys per environment (development, staging, production) or per teammate so you can revoke or restrict one without affecting the others.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →