Skip to main content
API Key Setup8 min readPublished: 2026-07-29Updated: 2026-07-29

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

OpenAI's API powers GPT-4o, o-series reasoning models, and more. Here's exactly how to create your OpenAI API key, set up billing, configure usage limits, and make your first request.

Why Use the OpenAI API?

OpenAI remains the most widely adopted AI API provider in 2026, offering access to the GPT-4o multimodal model family, the o-series reasoning models (o1, o3, o4-mini), and specialized models for embeddings, text-to-speech, and image generation.

The OpenAI API has the largest ecosystem of SDKs, community libraries, and third-party integrations. If you're building an AI-powered application, the OpenAI API is often the default choice due to its mature tooling, comprehensive documentation, and broad model coverage.

Step 1: Create an OpenAI Account

Go to platform.openai.com and click 'Sign Up.' You can register with an email address, or use a Google or Microsoft account for single sign-on. Email verification is required.

You'll also need to verify a phone number. OpenAI requires phone verification to prevent API abuse — this applies to all accounts regardless of billing tier. Both landline and mobile numbers work in most regions.

Step 2: Set Up Billing

OpenAI's API billing is completely separate from ChatGPT Plus subscriptions. Even if you pay for ChatGPT Plus, you still need to add a payment method and fund your API account separately.

Navigate to Settings > Billing in the dashboard. Add a credit card — OpenAI accepts Visa, Mastercard, and American Express. After adding your card, you can choose to auto-recharge when your balance drops below a threshold, or manually top up.

New accounts may receive a small amount of free trial credits (typically $5), but these expire after a few months. Check the Billing page to see if your account has any remaining trial credits.

Step 3: Create Your API Key

Navigate to the 'API Keys' page from the dashboard sidebar. Click 'Create new secret key.' You'll be prompted to give the key a name and optionally assign it to a project.

OpenAI introduced project-scoped keys, which allow you to organize keys by project and set per-project spending limits. This is recommended for teams managing multiple applications.

After creating the key, copy it immediately. The full key string is only shown once — after you close the dialog, you will never see it again. Store it in a secure location such as a .env file, a secret manager, or your CI/CD secrets.

Step 4: Set Usage Limits

OpenAI allows you to set spending limits to prevent unexpected charges. Go to Settings > Limits, where you can configure a hard limit (the maximum your account can spend per month) and a soft limit (triggers an email notification when reached).

If you're using project-scoped keys, you can also set per-project monthly limits. This is especially useful if you have separate development, staging, and production environments — set a low limit for dev/staging to catch bugs that cause excessive API calls.

Step 5: Make Your First API Request

Install the official OpenAI Python SDK and make your first call. The example below uses GPT-4o-mini, which is the most cost-effective model for general tasks.

python
from openai import OpenAI

client = OpenAI(
    api_key="sk-your-openai-api-key"
)

response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Hello, what can you do?"}
    ]
)

print(response.choices[0].message.content)

Minimal OpenAI API call using the official Python SDK

API Key Security Best Practices

Never expose your API key in client-side code, public repositories, or screenshots. If a key is compromised, delete it immediately in the API Keys dashboard and create a new one.

Use environment variables or a secrets manager to inject the key at runtime. In Next.js, use server-side environment variables (without the NEXT_PUBLIC_ prefix) so the key never reaches the browser.

Rotate your keys periodically — create a new key, update your application, then delete the old one. This limits the damage if a key is accidentally leaked.

FAQ

Does ChatGPT Plus include API access?

No. ChatGPT Plus ($20/month) only covers the ChatGPT web and mobile app. The API is billed separately — you need to add a payment method and fund your API account independently. Having ChatGPT Plus does not give you any API credits or discounts.

Is the OpenAI API free?

The OpenAI API is not free, but new accounts may receive approximately $5 in trial credits that expire after a few months. After the trial credits are exhausted, you must add funds to continue using the API. There is no permanent free tier.

Do I need a credit card to use the OpenAI API?

You need to add a payment method to make API calls beyond the free trial credits. OpenAI accepts Visa, Mastercard, and American Express. If you still have trial credits, you can make limited API calls without adding a card, but you'll need one once those credits run out.

What is the difference between an OpenAI API key and a ChatGPT session token?

An API key (starting with 'sk-') is an official credential for programmatic access to the OpenAI API, obtained from platform.openai.com. A session token is an internal authentication cookie used by the ChatGPT web interface — using it for automated access violates OpenAI's terms of service and can get your account banned. Always use the official API key.

How many API keys can I create?

There is no strict limit on the number of API keys you can create. You can create separate keys for different projects, environments, or team members. Each key can be independently revoked, which makes key rotation and access management straightforward.

Can I use the OpenAI API from China?

OpenAI does not officially support API access from China. Developers in unsupported regions may face registration or billing difficulties. Consider using alternative providers like DeepSeek, which offers OpenAI-compatible APIs and supports Chinese payment methods.

Related Providers

Sources