How to get an OpenAI (ChatGPT) API key for n8n and Claude Code (2026)
If you're using OpenAI / ChatGPT for the AI steps, whether in a coding setup like Claude Code or an n8n automation we built, you'll need your own OpenAI API key. This walkthrough takes you from zero to a working key, then shows both ways to use it: pasted into a local .env file or connected in n8n.
Important up front: the OpenAI API is separate from a ChatGPT Plus subscription. Paying for ChatGPT does not give you API access. You set up API billing separately, and it's pay-as-you-go (you only pay for what your automation uses).
- Create an account at platform.openai.com
- Add a payment method or credits under Billing
- Go to API keys → Create new secret key, then copy it (shown once)
- Add it to a local
.envfile (Claude Code / your code), or paste it into an n8n credential
1. Create your OpenAI Platform account
Go to platform.openai.com and sign up (or log in). This is the developer platform, a different place from chatgpt.com. If you already use ChatGPT, you can sign in with the same account, but you'll still set up API access and billing here.
2. Add billing (a payment method or credits)
Open Settings → Billing and add a payment method, or buy a small batch of prepaid credits ($5 is plenty to test an automation). Without billing set up, every request fails with an insufficient_quota error. This is the single most common snag.
Cost is per token (input + output) and depends on the model. For current rates, see OpenAI's API pricing page. Most lead-gen and admin automations cost cents per run.
3. Create the API key
Go to API keys (under Settings, or via your profile menu) and click Create new secret key. Give it a recognizable name, e.g. claude-code or n8n-production. If you're asked to pick a project, the Default project is fine.
OpenAI shows you the full key exactly once. It starts with sk- (newer project keys start with sk-proj-). Copy it immediately and store it somewhere safe, like a password manager. If you close the dialog without copying, you'll have to delete it and create a new one.
4. Add the key to your local environment (Claude Code / coding)
If you're working in a coding environment like Claude Code, the key lives in your project's environment, not in a UI. The standard place is a .env file:
- In your project folder, create a file named
.env(or open the one already there). - Add a line with your key:
OPENAI_API_KEY=sk-... - Add
.envto your.gitignoreso the key is never committed to git. - The OpenAI SDK and most tools read
OPENAI_API_KEYfrom the environment automatically, so the key stays out of your code.
OPENAI_API_KEY is the variable name nearly every OpenAI tool and library looks for by default, so sticking to it means most code finds your key with zero extra config.
5. Or connect the key in n8n
Prefer n8n? The same key goes on an OpenAI credential, which the AI nodes then reuse:
- Open your workflow and click the OpenAI Chat Model node (it sits under an AI Agent node), or add an OpenAI node.
- In the node's Credential dropdown, choose Create New Credential.
- Paste your key (
sk-…) into the API Key field and save. - Back on the node, pick a model from the dropdown (the model is set here, not on the credential).
- Click Execute / Test step. If it returns a response, you're connected.
That's it. Whether in your code or in n8n, every OpenAI step now uses your key and your account's billing.
Fix the OpenAI insufficient_quota error
If your first call returns insufficient_quota or "You exceeded your current quota," the key itself is fine. The account just has no usable credit yet. This is the most common first-run error, and it's a billing setup issue, not a key problem:
- Add a payment method or prepaid credits under Settings → Billing on the OpenAI Platform. Pay-as-you-go needs a card on file; prepaid needs a positive credit balance.
- Check you're using the right project. A key created under one project can't spend another project's credits. Use the project selector at the top left to confirm.
- After adding credit, wait a minute and retry with the same key. You don't need to generate a new one.
- Remember the API is billed separately from ChatGPT Plus. A Plus or Team subscription adds no API credit.
Official reference
OpenAI's dashboard changes from time to time. If a screen looks different from this guide, their own docs are the source of truth: the OpenAI Platform API keys and OpenAI API docs. For the n8n side, see n8n's OpenAI credential docs.
FAQ
Does my ChatGPT Plus subscription include API access?
No, the API is billed separately. Set up API billing on platform.openai.com and pay per token, independent of any ChatGPT subscription.
Where do I put the key in Claude Code or my code?
Store it as the OPENAI_API_KEY environment variable, typically in a .env file that you add to .gitignore. The OpenAI SDK and most tools read it automatically.
I get insufficient_quota / "exceeded your current quota."
No usable credit or billing is set up. Add a payment method or prepaid credits under Settings → Billing. With billing in place, the same key starts working.
I lost my key. Where do I find it again?
You can't. OpenAI shows the full secret key only once. Delete the old one under API keys and create a new key.
Want us to set it up for you?
We build AI lead generation and CRM automations, and handle the wiring, keys, and billing so you don't have to.
Book a Free Strategy Call