How to Get OpenAI API Key

Create an OpenAI project key, add billing, set a hard spend limit, store it safely, and test one request. Includes errors and leaked-key recovery.

Published

How to Get OpenAI API Key

An OpenAI API key lets your app or automation send requests to OpenAI under your account. To get one, sign in to the OpenAI Platform, select a project, create a secret key, set up API billing, and test a request. Before connecting a tool, decide who owns that project and how much it may spend.

1. Sign In and Choose the Right Project

Open platform.openai.com and create an account or sign in. Complete the onboarding prompts shown to you. The OpenAI quickstart links directly to the API key dashboard.

Think of the account as your staff pass, the organization as the company, and the project as a room assigned to one application. The key is the credential your software uses to enter that room.

Choose the intended organization in the organization switcher. Select an existing project, or, as an organization owner, use the project menu's Create project option and complete its details. A named project such as website-test makes the purpose clearer. OpenAI's project guide documents these controls.

For company work, ask the owner to add you to the appropriate project. Avoid starting a client integration under a personal billing account simply because it is already open.

Architectural cutaway showing an account entering an organization, a project inside it, and an API key connecting the project to an app.
Select the organization and project before creating the credential your app will use.

2. Create a Project API Key

In organization settings, select your project, open API Keys, and choose + Create new secret key. This creates a key associated with the selected project. Project key instructions.

For your own first test, use a user-owned project key. Give it a recognizable name if prompted, such as local-test. Choose Restricted permissions and enable the operations your app needs. All grants full access and is the default; Read Only limits the key to read operations. API key permissions. For the test below, allow creating Responses, the permission OpenAI calls api.responses.write. Response-writing permission.

Copy the secret immediately into secure storage. OpenAI displays the complete value only at creation. If you lose it, create a replacement; you cannot reveal the original again. Finding and managing API keys.

Set an expiration date and record who will replace the key. Organization policy may require an expiry or restrict which key types you can create. If an option is unavailable, ask the administrator about the policy. OpenAI production guidance. Use the API key expiry and rotation plan before a test becomes a running service.

When a Service-Account Key Is Better

For a deployed app or scheduled team workflow, I would use a service account, an identity for software rather than a person. An organization or project owner creates it under the selected project's Members → + Service account. Save the generated key immediately. Use a dedicated project: service accounts cannot be added directly to the Default project. Service-account setup.

Review its access under the project's API Keys settings after creation. The service-account creation dialog does not offer the same permission controls as a user-owned key. Permission differences. The operational payoff is clear ownership of the application credential when team members change.

3. Add API Billing and Set a Spend Limit

ChatGPT billing and API billing are separate. Paying for ChatGPT does not complete the API payment setup. Open the intended organization's API billing overview; an organization owner can manage its billing. OpenAI billing guidance.

New API accounts use prepaid billing. Select Add payment details, complete payment setup, choose the initial credit purchase, and confirm. Review Use auto-reload before checkout: OpenAI says it is enabled by default. Turn it off for a manual top-up experiment, or deliberately configure its threshold and monthly reload limit. A purchase can take a few minutes to appear. Prepaid setup.

For current model rates, use OpenAI's pricing page, with the site's OpenAI API pricing guide for app-budget context.

Enable Enforcement if You Want Requests to Stop

In Project settings → Limits → Spend → Edit spend limit, enter the Monthly spend limit, enable Enforce a hard limit, then save. You need permission to manage that project's settings. Add a spend alert below the cap so someone can respond before service stops. Spend-limit instructions.

ControlWhat it does
Spend alertNotifies you while requests continue.
Enforced hard limitRejects affected requests when tracked spend reaches the cap.
Monthly reload limitRestricts automatic credit purchases, not use of existing credit.

Hard-limit enforcement has a delay, so recorded spend can slightly exceed the configured amount. An organization hard limit covers its projects together. A prepaid balance can also be exceeded during delayed cutoff, and manual purchases are outside the automatic reload limit. Hard-limit behavior, prepaid behavior.

Two architectural corridors compare a spend alert with continuing traffic and a hard limit with a closed barrier marked 429.
Alerts notify. Enforced limits reject affected requests, with a possible small enforcement delay.

For a production rollout, read the OpenAI API hard spend limits guide and choose who may raise the cap when it interrupts service.

4. Store the Key Where the App Can Use It Safely

Keep the key in a secret manager, a system designed to store credentials, or provide it to your server through an environment variable named OPENAI_API_KEY. An environment variable is a named setting the running program can read without embedding the secret in its source code. Production storage guidance.

Do not put a standard API secret in website JavaScript, a mobile app, a repository, a screenshot, or a support message. Browser and mobile code reaches users' devices; your server should hold the secret and make the request. Give teammates their own access instead of passing around one person's key. API key safety.

If a tool asks you to paste a key: use its documented credential field only after you are comfortable with the vendor receiving that credential. My recommendation is a dedicated project and restricted key for that integration, with a spend cap and an owner. A normal text box, chat message, or unfamiliar “key checker” is the wrong place to diagnose a connection. Ask the vendor which permissions it needs and where it stores the secret.

5. Test With One curl Request

Run this in Bash on your computer. curl is a command-line tool that sends a web request. The first lines prompt for the secret without displaying it or putting its literal value into the command you type; the environment variable lasts for that shell session.

Bash
read -r -s -p "OpenAI API key: " OPENAI_API_KEY
printf '\n'
export OPENAI_API_KEY

curl https://api.openai.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-6-astra",
    "input": "Reply with a short greeting."
  }'

This uses the request structure and model in OpenAI's text-generation example. The Responses API is the endpoint receiving your input and returning the model's output. The authorization header carries the secret; the JSON body chooses the model and supplies the instruction. This is an API usage request, so billing and model access must be ready.

A successful response contains an output array with a message containing output_text content. Look for the greeting there. Do not assume the text is always the first array item. If you get an error object, use its message and code below. Response structure.

After the test, run unset OPENAI_API_KEY to clear this shell's variable when you no longer need it. For deployment, configure the secret in your hosting environment rather than rerunning a terminal prompt.

Key Not Working? Check These First

Read the error before creating another key. Several failures have nothing to do with the secret itself.

CheckWhat to do
Wrong project or organizationUse the key created for the intended project and check the app's configuration. Switching the dashboard view does not replace the key stored in your app.
No billing or exhausted creditCheck API billing for that organization. credit_balance_exhausted requires adding credit.
Rate limitSlow requests and respect Retry-After when present. Repeated immediate retries make this worse.
Revoked, expired, or mistyped keyReplace the stored value, remove accidental whitespace, and restart or reload the app if it still holds the old credential.
Spend cap reachedInspect error.code: project_spend_limit_exceeded and organization_spend_limit_exceeded identify enforced caps.
Missing permission or model accessReview the key's allowed operations and the project's model access.

A 429 response can mean a spending or credit problem as well as a rate limit. Repeated retries cannot replenish credits or change a configured cap. OpenAI error codes, key permissions.

If Your API Key Leaks, Revoke It Immediately

Treat a secret pasted into a public repository, screenshot, or message as exposed. Deleting the visible copy cannot invalidate copies someone already obtained.

  1. Revoke the exposed key. Open the API keys page in the correct project and delete it. Applications using it may stop until you replace it. Key deletion.
  2. Create a replacement and update affected apps. Test the replacement, then check that deployed processes use it.
  3. Review usage and billing. Investigate unexpected requests and contact OpenAI Support about suspected misuse. OpenAI recommends immediate rotation when a leak is suspected. Leak response guidance.
  4. Fix the exposure. Remove the secret from code and logs, and correct the storage or sharing practice that leaked it. If the account itself may be compromised, change the password, sign out other sessions, and report unauthorized activity. Account recovery steps.
Four connected architectural stations show the leaked-key response: revoke, replace, review usage, and fix exposure.
Invalidate the exposed credential first. Removing a screenshot or code snippet alone does not revoke it.

Five Places This Setup Pays Off

The benefit is an integration with a known owner and budget. These are practical ways a team could apply the setup, ranked by immediate usefulness.

WhoWorkflow they could runWhy it helps
Founder validating an ideaConnect a server prototype and try a small set of representative prompts.Establish whether the integration works before building the surrounding product.
Operator connecting an approved toolAdd a dedicated credential, test one action, and assign a budget owner.Resolve the “paste a key” handoff without borrowing a teammate's secret.
Agency delivering a client appPut the project and billing under the client's organization and document ownership.Make access and spending responsibility explicit at handover.
Developer running a scheduled jobUse a service identity and document replacement and failure handling.Give the team a clear maintenance process for unattended work.
Team testing a live product changeUse a separate test project and spend control.Keep experiments easier to identify and manage alongside production.

A working key proves that a request can run. It does not prove that your prompts are reliable, that a vendor handles credentials well, or that an automation deserves access to customer data. Those remain product and operational decisions.

Two Useful Things to Build Around the Setup

The strongest opportunity is an embedded connection assistant for software that asks customers for an OpenAI key. DataForSEO estimates 1,000 monthly US searches for “how to get openai api key.” That is evidence of setup friction, not a forecast of paying customers. A tool vendor could buy or build a guided project checklist, secure credential field, explicit test button, and readable result. The smallest version should live inside the product that needs the connection. The catch: vendors can build it themselves, so the value must come from reducing their support burden and keeping instructions current.

An error explainer is a useful support feature, with weaker standalone demand. The same check estimates only 10 monthly US searches for “openai api key not working.” An automation vendor or implementation agency could offer a form accepting a redacted error code and message, then explain whether to fix credentials, credit, permissions, or traffic speed. Its first version needs a maintained decision table, not custody of the user's key. The catch is the small measured query volume and the fact that many tools already display these errors. I would attach it to onboarding rather than launch a separate paid product.

These are DataForSEO keyword-overview estimates for US English, checked for this guide. They measure searches, not unique users or purchase intent.

How do I get an API key?

Sign in to the OpenAI Platform, select the intended project, and open API Keys to create a secret. Save the value when it appears. Then complete API billing, permissions, and spend controls before connecting an app. OpenAI key guidance.

Is a ChatGPT API key free?

The credential for an API integration comes from the OpenAI Platform. OpenAI says new API accounts use prepaid billing and that any free credits an account has are used first. This does not establish a universal signup grant or a free tier for the model call above. Check your own API billing balance. OpenAI's prepaid policy.

How do I use an OpenAI API key in Python?

Set OPENAI_API_KEY in the environment where Python runs. OpenAI's Python SDK reads that variable, so your script does not need the literal secret in its source. Follow the Python example in the official quickstart.

Your Monday move: pick one integration, name its owner, create its project, set its spend control, and save one successful test result with the secret removed. That is a useful handoff to whoever maintains it next.

If you want help taking that integration into production, AI production systems covers the operational work around it.

Published
Category
Build
Related Articles
Deepgram Pricing: What Voice Agents and Transcripts Cost

Deepgram Pricing: What Voice Agents and Transcripts Cost

Deepgram plans, speech API rates, concurrency limits and worked monthly costs for support voice agents and meeting transcripts.Oct 20, 2026Build
LLM Quantization: GGUF, AWQ, GPTQ and FP8 Explained

LLM Quantization: GGUF, AWQ, GPTQ and FP8 Explained

Understand the memory, speed and quality tradeoffs of LLM quantization, with a worked estimate and format choices for local runtimes and APIs.Oct 20, 2026Build
What Is a Vector Database? How It Works and When You Need One

What Is a Vector Database? How It Works and When You Need One

Understand embeddings, similarity search, indexes and filters, then decide when pgvector is enough and when Pinecone or Qdrant fits.Oct 20, 2026Build
Vertex AI Pricing: Gemini Rates and Two Monthly Budgets

Vertex AI Pricing: Gemini Rates and Two Monthly Budgets

Current Gemini token rates on Google Cloud, batch and caching costs, Developer API differences, and two worked monthly budgets.Oct 20, 2026Build
Cheapest LLM API 2026: OpenAI, Anthropic, Google, DeepSeek, Mistral, xAI and Groq Compared

Cheapest LLM API 2026: OpenAI, Anthropic, Google, DeepSeek, Mistral, xAI and Groq Compared

Compare OpenAI, Anthropic, Google, DeepSeek, Mistral, xAI and Groq API prices, with caching, Batch and costs for three common jobs.Oct 20, 2026Build
Langflow: What It Is and When to Use It

Langflow: What It Is and When to Use It

What Langflow is, who owns it, how agents and RAG flows work, and when to choose it over Flowise or n8n. Includes current hosting options.Oct 19, 2026Build
Amazon Bedrock Pricing: Model Rates and a $1,270 App Budget

Amazon Bedrock Pricing: Model Rates and a $1,270 App Budget

Amazon Bedrock model rates, direct API comparisons, caching and add-ons, with a $1,270 monthly budget for 100,000 support answers.Oct 19, 2026Build
Claude Fast Mode

Claude Fast Mode

Claude fast mode for Opus 5.5: exact setup, subscription billing, standard-versus-fast costs, and when paying for speed makes sense.Oct 19, 2026Build
Newsletter

One letter, every Sunday.Working systems, not hot takes.

Weekly. No spam. Unsubscribe anytime.