How to Get an OpenAI API Key: 6 Steps in the 2026 Platform Dashboard
You create an OpenAI API key in OpenAI's developer platform (Platform), not in ChatGPT settings. Sign in to a Platform account, set up a project, then generate a key on the API keys page. The API is billed separately by usage, and it is not connected to your ChatGPT subscription. This article walks through the flow and the few things to do right after you get your first key.
Labels and menu locations change whenever OpenAI redesigns the dashboard, so this article describes the process and how to judge each step. For exact menu names, whether prepaid credit is required, and which regions and payment methods are supported, rely on OpenAI's official documentation and the Platform pages.
How are a ChatGPT subscription and the API platform different?
Many beginners assume that buying ChatGPT Plus gives them an API key. It doesn't.
| ChatGPT (web/app) | OpenAI API platform | |
|---|---|---|
| Purpose | A person chats in an interface | A program calls models through an API |
| Billing | By subscription tier | By actual usage |
| Entry point | chatgpt.com | platform.openai.com |
| Credential | Account login | API key |
Credits on one side can't be applied to the other. If you only want to chat in the browser, you don't need a key. You need one when you connect Cursor, Cline, or a script you wrote yourself. For a closer comparison, see ChatGPT Plus vs. the OpenAI API: separate accounts, billing, and quotas.
How do you get an OpenAI API key? The 6-step flow
- Open the platform and sign in. Go to OpenAI's official Platform site and sign in or sign up. Confirm that your region and payment method are within the officially supported range; defer to the official statement on this.
- Check your organization. A Platform account contains organizations, and billing, members, and usage all attach to the organization. Personal use usually means a single default organization.
- Create a project. One project per purpose works well, for example "blog scripts" or "local coding assistant". A project can have its own keys, limits, and allowed models, which makes problems easier to trace later. See How to use OpenAI project API keys.
- Set up billing. The API usually needs payment set up or credit added on the billing page before calls work. The exact rules are in OpenAI's billing documentation.
- Create the key. On the project's API keys page, choose to create a new secret key, give it a name that shows what it's for, and pick a permission scope if you need one.
- Save it immediately. The full key is normally shown only once, at creation. After you close the window you can't see it again. Put it in a password manager or an environment variable, and don't paste a screenshot into a group chat.
What three things should you do right after creating a key?
Set a limit. Configure a budget and usage alerts for the project or organization so a runaway loop in a script can't burn through your balance. Steps are in How to set a spending limit and usage alerts for the OpenAI API.
Narrow the permissions. If you only call the chat endpoint, don't grant more. The names and granularity of the permission options follow the official documentation.
Verify with a minimal request. Put the key in an environment variable and send one simple request. Here is an example; replace the model name with one that is actually available on your account:
export OPENAI_API_KEY="your key"
curl https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"<a model available on your account>","messages":[{"role":"user","content":"Hello"}]}'
If the response contains reply text, the key works. Common failures: a 401 usually means the key was mistyped or has been revoked; a 429 may mean you hit a rate or quota limit. The exact meanings are in OpenAI's error-code documentation. For the complete first-call walkthrough, see How to use an LLM API: from getting a key to your first reply.
How should you store the key?
- Don't put it in frontend code, public repositories, or chat logs.
- Use environment variables for local development. On a team, give each person their own key rather than sharing one.
- Use one key per project so you can revoke it on its own.
- Check the usage page regularly, and revoke the key right away if you see calls you don't recognize.
If a key does leak, follow the order in Your OpenAI API key leaked: revoke first, then check usage, and finally track down the source of the leak.
What if the official API won't connect?
From mainland China, latency and connectivity to the official endpoints are often unstable. Start with cdnping's OpenAI status page. It probes the official entry point from Cloudflare's edge, which helps you tell "OpenAI is having an outage" apart from "my own network has a problem". Note that this is an edge probe and is not the same as the network on your own machine. You can also measure connection time to each vendor's API directly in your browser from the cdnping home page; for background, see How to read AI API latency from China.
What if you don't have an overseas payment method?
Whether the official platform can be activated for you depends on your region and payment method. Don't take a third party's word for it; check the official statement directly. If your main goal is to use models inside coding tools such as Claude Code or Codex, an aggregation gateway is another option worth knowing about.
AGI Plan is a multi-vendor LLM aggregation gateway. It is sold as a monthly subscription, paid in RMB, with no overseas credit card needed. Tools like Claude Code and Codex only need one endpoint address changed, and a single quota can then be switched across several capability groups. It is compatible with both the OpenAI and Anthropic API formats. Keep in mind that AGI Plan is not an officially authorized channel, and some models are marked as available only outside China; check the models page for specifics. AGI Plan is a commercial partner of cdnping. It can't get you around OpenAI's regional restrictions, and you should follow the terms of service of any service you use, as well as local law. To learn how to connect, see the AGI Plan getting-started page.
The two paths don't conflict: an official key suits cases where you need to integrate directly with OpenAI, and a gateway suits cases where you'd rather skip the payment and setup hassle.
What to do next
- To understand the concepts first, read What is an API key?.
- If you already have a key, set a usage limit first, then run one minimal request.
- If you can't get an official key, or only want to use models in coding tools, see the three-step setup on the AGI Plan getting-started page.
One last reminder: the console layout, payment requirements, permission options, and regional policies all change. OpenAI's official documentation is the authority.