How to Get an OpenAI API Key (Step-by-Step)

Cover reading How to Get an OpenAI API Key
On this page

You create an OpenAI API key in the dashboard at platform.openai.com. OpenAI's own quickstart puts it in one line: "Before you begin, create an API key in the dashboard, which you'll use to securely access the API." Sign in, open the API keys area, create a key, and copy it somewhere safe. The part worth more of your attention is what comes next, because the key itself is free and the spend controls behind it are where the money is decided.

If you're doing this so a support tool runs on your own account rather than a vendor's, the bring your own AI key approach explains what that changes about your bill. The steps below are the OpenAI half. We wrote the Claude version separately, because the two consoles work differently enough to be worth their own walkthroughs.

What you need before you start

You need an OpenAI account, a payment method on it, and permission to create keys if you're joining a company organization rather than your own.

OpenAI splits billing across two levels, and this catches people out later. An organization sits at the top, and projects sit inside it. Every key belongs to a project, and you can set spend controls on either level. That matters as soon as more than one team shares the account.

Billing is genuinely required rather than optional. OpenAI's spend limits guide documents an error code, credit_balance_exhausted, for exactly this case, and its instruction is to add credits in the organization billing settings. A key with an empty balance behind it will authenticate and then fail on the first real call.

How to create the key

Four steps, and each has something you can check before you move on.

  1. Sign in at platform.openai.com. Use the account you want the usage billed to. You'll know you're in the right place when the developer dashboard loads rather than the ChatGPT chat interface, which is a different product on a different domain.

  2. Add a payment method and credits. Do this before creating the key, not after, so your first test call doesn't fail. Your balance shows in the organization billing settings, and it should read above zero before you continue.

  3. Create a key in the dashboard's API keys area. Click Create new secret key, give it a name that says what it's for, and pick the project it belongs to. The same dialog sets permissions, where All, Restricted and Read only decide what the key can reach. The new key appears in the key list afterwards, which is how you know it was created.

    The OpenAI API keys page, with API Keys highlighted in the sidebar and the Create new secret key button in the top right

    The Create new secret key dialog, with the name field, the project dropdown, the All, Restricted and Read only permission options, and the Create secret key button numbered

  4. Copy the key and store it. Paste it straight into your secrets manager or your support platform's settings field. Confirm it saved by reading it back from wherever you put it, because the full value is shown to you at creation and not again afterwards.

To use the key in your own code, exporting OPENAI_API_KEY is usually all it takes. OpenAI's quickstart says each of its SDKs "automatically reads your API key from the system environment". Direct HTTP calls send it as an Authorization: Bearer header instead.

Set the spend limits before you connect anything

OpenAI gives you two controls here, and they behave differently. Picking the wrong one is how teams either get surprised by a bill or take their own agent offline.

A spend alert notifies you and lets the traffic carry on. A hard limit stops it. Cross the number and requests come back as a 429 error instead of an answer. OpenAI's own guidance is direct about the risk: "Hard spend limits can interrupt production traffic."

For a support agent, that distinction decides whether a bad month costs you money or costs you customer replies. A hard limit set too tight means your agent stops answering mid-conversation, which is worse than an unexpected invoice. The documentation recommends adding alerts "at thresholds that allow time to adjust usage, raise the limit, or investigate unexpected traffic". That is the right shape for support. Alert early, and set the hard limit high enough that only a genuine runaway trips it.

The level you set it at matters too. A limit on the organization covers every project inside it. A limit on one project only touches that project's traffic. So give your support agent a project of its own, and a runaway experiment somewhere else cannot take your customer replies down with it.

Which OpenAI model should you pick for support?

Start at the cheap end, because support work is mostly reading your help content and writing a short reply. The published spread is wide enough that this choice moves your bill more than anything else on this page.

OpenAI model pricing per million tokens: GPT-5.6 Luna costs $0.20 in and $1.20 out, GPT-5.4 Mini $0.75 and $4.50, GPT-5.6 Terra $2 and $12, GPT-5.6 Sol $4 and $20 GPT-5.6 Luna GPT-5.4 Mini GPT-5.6 Terra GPT-5.6 Sol $0.20 $1.20 $0.75 $4.50 $2 $12 $4 $20 Input per million tokens Output per million tokens
OpenAI list pricing, retrieved 27 August 2026 from the OpenAI API pricing page. Batch processing is discounted 50% against these rates.

GPT-5.6 Luna costs a twenty-fifth of the flagship on input, which is why routing matters more than standardizing. Put the cheap model on "what are your opening hours" and save the expensive one for the questions that genuinely need reasoning. Optlo lets you connect your own OpenAI, Anthropic, or Gemini account and use a fast model for routing with a more capable one for replies. A rate per million tokens is hard to picture as a monthly bill, so price a model against your own conversation volume rather than working the token arithmetic out by hand.

Does prompt caching change what support traffic costs?

It does, and support is close to the ideal case for it. OpenAI bills a repeated prompt prefix at a tenth of the standard input rate, and support requests repeat almost everything except the customer's question.

Cached input costs a tenth of standard input at every tier: GPT-5.6 Luna $0.02 against $0.20 per million tokens, GPT-5.4 Mini $0.075 against $0.75, GPT-5.6 Terra $0.20 against $2, GPT-5.6 Sol $0.40 against $4. Plotted on a logarithmic scale. GPT-5.6 Luna GPT-5.4 Mini GPT-5.6 Terra GPT-5.6 Sol $0.02 $0.20 $0.075 $0.75 $0.20 $2 $0.40 $4 $0.02 $0.20 $2 Cached input per million tokens Standard input per million tokens
Cached and standard input rates, retrieved 27 August 2026 from OpenAI's published pricing. Cached input is billed at 90% off the standard rate on every model shown, so each pair sits one decade apart on this logarithmic scale.

The reason this fits support is what your requests look like. The instructions that set the agent's tone, the rules about when to escalate, and the help content you paste in are identical on every ticket, and only the customer's message changes. OpenAI's prompt caching guide says the feature "works automatically for eligible requests, with no code changes required", so there is nothing to switch on.

Two conditions decide whether you actually get the discount. The first is length: caching applies to "prefixes containing at least 1,024 tokens", which a short prompt never reaches. The second is order. A hit needs an exact match on the opening text, so anything that changes from ticket to ticket has to come after the part that stays the same. A request that opens with the customer's name defeats the whole thing.

Volume matters too, because caches expire. On GPT-5.6 and later a cached prefix "remains eligible for reuse for at least 30 minutes", while earlier models hold theirs for five to ten minutes of inactivity. A busy queue keeps the cache warm and a quiet one pays full rate on the first ticket after a lull.

Is a ChatGPT API key the same thing?

There's no separate ChatGPT API key, and searching for one leads to the same place. ChatGPT is the consumer chat product at chatgpt.com, while the API lives at platform.openai.com, and the key you create in the developer dashboard is what programs use to reach the models. People search for a "ChatGPT API key" because ChatGPT is the name they know, but the credential is an OpenAI API key either way.

Two things follow from that distinction. A ChatGPT Plus or Pro subscription does not include API credit, so paying for the consumer product does not give you a working key. Azure OpenAI is a third thing again. It's Microsoft's hosted version with its own keys from the Azure portal, which is why a Microsoft support page ranks for this search and confuses people who don't use Azure.

What you want Where the key comes from What it bills to
OpenAI API The developer dashboard at platform.openai.com Your OpenAI organization, from prepaid credits
ChatGPT No key exists; it's the consumer app at chatgpt.com Your ChatGPT subscription, billed separately
Azure OpenAI The Azure portal Your Azure subscription

If a tool asks for an OpenAI API key, the first row is the one you want.

Before you walk away

Set a spend alert now, while you're still in the billing settings, and put your support agent in its own project so a limit elsewhere cannot silence it.

Then work out what the traffic will actually cost. The key is free and the credits are not. what a support conversation really costs to run compares tokens at cost against bundled per-resolution pricing, which is the comparison most teams are really making when they go looking for a key.

Common questions

How do I get an OpenAI API key?

Sign in at platform.openai.com, add a payment method and some credit, then create a key in the dashboard's API keys area and copy it somewhere safe before you navigate away. OpenAI's quickstart describes the first step as "create an API key in the dashboard, which you'll use to securely access the API". The full value is shown at creation, so store it immediately.

Is an OpenAI API key free?

Creating the key costs nothing, but using it does not. API credits are prepaid, and OpenAI's spend limits guide documents a credit_balance_exhausted error for accounts that run out, with instructions to add credits in the organization billing settings. Free keys shared publicly online belong to somebody else's account and should not be used.

How much does the ChatGPT API cost?

There's no separate ChatGPT API, so the question is really what the OpenAI API costs, and it's billed per million tokens rather than per message. On the rates published on 27 August 2026, GPT-5.6 Luna costs $0.20 for a million input tokens and $1.20 for a million output, while GPT-5.6 Sol costs $4 and $20. Cached input is billed at 90% off on every model shown, which matters for support because your agent instructions and help content repeat on every single ticket.

Is a ChatGPT API key different from an OpenAI API key?

They're the same credential under two names. ChatGPT is the consumer product at chatgpt.com and the API lives at platform.openai.com, so the key you create in the developer dashboard is what any program uses, whichever term you searched for. A ChatGPT Plus or Pro subscription is billed separately and does not include API credit.

What is the difference between an OpenAI key and an Azure OpenAI key?

They're issued by different companies for different services. An OpenAI API key comes from platform.openai.com and bills to your OpenAI organization. An Azure OpenAI key comes from the Azure portal, bills to your Azure subscription, and points at Microsoft's hosted deployment of the models. Keys are not interchangeable between them, so check which service your tool expects.

How do I stop an OpenAI API key running up a large bill?

Use spend alerts and hard limits together, but understand the difference. An alert sends a notification and lets traffic continue, while a hard limit makes affected requests return a 429 error. OpenAI warns that "hard spend limits can interrupt production traffic". For a customer-facing agent, set alerts at thresholds that give you time to react, and keep the hard limit high enough to catch only a genuine runaway.

Which OpenAI model is best for customer support?

Start with GPT-5.6 Luna at $0.20 per million input tokens and $1.20 per million output, since most support work is retrieving your help content and writing a short answer. Move up to GPT-5.4 Mini or GPT-5.6 Terra for questions that need real reasoning. Routing cheap questions to a cheap model and reserving the expensive one for hard cases costs far less than sending everything to the flagship.

Does prompt caching reduce what an OpenAI API key costs to run?

Yes, by 90% on the repeated part of the prompt. OpenAI bills cached input at a tenth of the standard rate, so GPT-5.6 Luna drops from $0.20 to $0.02 per million tokens and GPT-5.6 Sol from $4 to $0.40. It applies automatically to prefixes of at least 1,024 tokens that match exactly, which suits support because the agent instructions and help content repeat on every ticket. Keep whatever varies, like the customer's message, after the stable part of the prompt.

Build AI customer support on your terms

Bring your own AI, stay in control, and optimize as you scale.

Try free for 7 days

* No credit card required