← Blog

What Is an OpenAI API Key and How Does It Work?

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

An OpenAI API key is a secret credential that lets your code make authenticated requests to OpenAI's models — GPT-4, GPT-3.5, embeddings, image generation, and more — without a human logging into a website. You generate it once from your OpenAI account, paste it into your application or environment variables, and every request your code sends includes it as proof that the request belongs to your account and should be billed to you.

It's not the same thing as a ChatGPT login. ChatGPT is the consumer chat interface you use in a browser; the API key is for developers building software that talks directly to OpenAI's models programmatically — a backend service, a CLI tool, a Slack bot, an internal automation script. You can have a ChatGPT Plus subscription and no API key at all, or an API key and never touch ChatGPT's web interface. They're billed separately and serve different purposes.

What an OpenAI API key actually looks like

An OpenAI API key is a long string that starts with sk- (secret key), followed by a random alphanumeric sequence. You'll typically see it once, at creation time, in your OpenAI dashboard. After that it's masked — you can't view the full value again, only regenerate a new one if you lose it.

A typical request using the key looks like this:

curl https://api.openai.com/v1/chat/completions \
  -H "Authorization: Bearer sk-your-key-here" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{"role": "user", "content": "Explain API keys in one sentence"}]
  }'

The Authorization: Bearer <key> header is the standard pattern most LLM APIs use, including OpenAI's. Whoever holds this string can make requests and generate charges on your account, which is why it's treated as a secret — same category as a database password or a private SSH key.

What the key controls

Once you have a valid API key, it governs several things:

If you're building a product on top of an LLM, the API key is effectively your product's connection to the model. Lose it, leak it, or hit your rate limit, and your app stops working until it's fixed.

Getting and using an OpenAI API key, briefly

Creating a key involves signing up for an OpenAI developer account, adding a payment method, and generating a key from the API keys section of the dashboard. From there, most people store it as an environment variable (OPENAI_API_KEY) rather than hardcoding it into source files, and load it at runtime in whatever language they're using.

const response = await fetch("https://api.openai.com/v1/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": `Bearer ${process.env.OPENAI_API_KEY}`,
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    model: "gpt-4o",
    messages: [{ role: "user", content: "Summarize this in 3 bullets" }]
  })
});

Security practices worth following

These practices aren't specific to OpenAI — they apply to any provider issuing a secret bearer token, including Anthropic's Claude API and third-party gateways.

If you're already paying for Claude access

Not everyone building on LLMs starts with OpenAI. If your team already has Claude access through a subscription and you want programmatic API access — streaming responses, tool use, per-application keys, usage tracking across a team — without separately managing OpenAI billing and keys, SubToAPI turns that existing Claude access into a standard HTTPS API. You get sub_live_... application keys, a dashboard for usage and seats, and the same Authorization: Bearer request pattern developers already know from working with OpenAI's API. Plans start at Solo €9, with Team and Scale tiers for multiple seats — see /pricing for details, or jump into the /docs/quickstart to see the request format side by side with what you'd write for OpenAI.

The core concept — a secret key authenticating requests, tied to usage and billing — is the same regardless of which model provider is behind it. Understanding how OpenAI's key works means you already understand how most LLM API keys work.

questions

Is an OpenAI API key the same as a ChatGPT Plus subscription? No. ChatGPT Plus is a consumer subscription for the chat web app and has a flat monthly price. An OpenAI API key is for developers calling models programmatically, billed separately based on token usage.

What happens if my OpenAI API key gets leaked? Anyone with the key can make requests billed to your account. Revoke it immediately in your OpenAI dashboard, generate a new one, update it everywhere it's used, and check your usage logs for unexpected activity.

Do I need a credit card to get an OpenAI API key? Yes — OpenAI requires a valid payment method on file before API requests will succeed, since usage is billed per token rather than through a flat subscription like ChatGPT Plus.

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 →