How to get an OpenAI (ChatGPT) API key for n8n and Claude Code (2026)

Last updated: July 4, 2026 ~5 min Claude Code & n8n setup

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).

The short version
  1. Create an account at platform.openai.com
  2. Add a payment method or credits under Billing
  3. Go to API keysCreate new secret key, then copy it (shown once)
  4. Add it to a local .env file (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.

Treat the key like a password. Anyone with it can spend on your account. Never paste it into a chat, email, or screenshot. To send it to us, use the secure method we agreed on (a password-manager share link or our secure form), not a plain message.

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:

  1. In your project folder, create a file named .env (or open the one already there).
  2. Add a line with your key:
    OPENAI_API_KEY=sk-...
  3. Add .env to your .gitignore so the key is never committed to git.
  4. The OpenAI SDK and most tools read OPENAI_API_KEY from the environment automatically, so the key stays out of your code.
Tip. 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:

  1. Open your workflow and click the OpenAI Chat Model node (it sits under an AI Agent node), or add an OpenAI node.
  2. In the node's Credential dropdown, choose Create New Credential.
  3. Paste your key (sk-…) into the API Key field and save.
  4. Back on the node, pick a model from the dropdown (the model is set here, not on the credential).
  5. 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:

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.

Related guides

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

← Back to all guides