How to Get Your ChatGPT (OpenAI) API Key

This step-by-step guide walks you through everything from creating your account to generating and securing your first API key, setting up billing, and testing your integration.

Kateryna PoryvayKateryna Poryvay

Kateryna Poryvay · Growth Marketer, Apideck

8 min readView as .md
How to Get Your ChatGPT (OpenAI) API Key

Step 1: Create an OpenAI Account

Navigate to platform.openai.com and click the "Sign up" button. You can register using your email address or sign up through your Google, Microsoft, or Apple account for faster access.

Screenshot 2025-08-29 at 17.34.41@2x

During registration, you'll need to verify your email address and provide a phone number for SMS verification. The phone check is OpenAI's anti-abuse measure, so use a real number you control.

Step 2: Access the API Dashboard

openai api key 2

Once your account is verified and you're logged in, you'll be directed to the OpenAI Platform dashboard. If you're not automatically redirected, go to platform.openai.com and sign in with your credentials. You will need to create an organization to generate API keys and start building.

openai api key 2

You will be prompted to invite your team, and then to make your first API call. After this step, you will be prompted to add some credits or billing details. You can always skip this step and click 'I'll do this later.'

openai api key 3

Step 3: Where to Find Your OpenAI API Key

openai api key 4

In the left sidebar of your dashboard, locate and click on "API keys". You can also access this directly at platform.openai.com/api-keys.

This section displays all your existing API keys (if any) and allows you to create new ones or revoke old ones.

Step 4: Create a New OpenAI API Key

openai api key 5

Click the "Create new secret key" button. A dialog box will appear where you can:

  • Name your key (optional but recommended): Use descriptive names like "Production App" or "Development Testing" to help you identify different keys for different purposes.
  • Set permissions: Choose whether this key should have full access or restricted permissions.
  • Configure project association: Link the key to specific projects if you're managing multiple applications.

Step 5: Copy and Save Your OpenAI API Key

Critical: Once generated, your API key will be displayed only once. Copy it immediately and store it securely. OpenAI cannot retrieve or display this key again for security reasons.

The key will start with sk- followed by a string of characters. The fastest way to use it is to set it as an environment variable in your shell:

export OPENAI_API_KEY="sk-..."

For longer-term storage:

  • Use environment variables in development (.env files, direnv, etc.)
  • Use a secrets manager in production (AWS Secrets Manager, Azure Key Vault, GCP Secret Manager, HashiCorp Vault)
  • Never commit API keys to Git, even in private repos
  • Never hardcode keys in source files that get shipped to clients

Step 6: Set Up Billing

Before you can use your API key, you need to add billing information:

  1. Click on "Settings" in the sidebar, then select "Billing"
  2. Click "Add payment method" and enter your credit card details
  3. Set up usage limits (recommended for new users):
    • Configure monthly budget limits to prevent unexpected charges
    • Set up email alerts for when you approach your limits
    • Review the pricing page to understand costs per model and token usage

Note: If you add credits to your account at the start, you'll be prompted to add your card details and set up billing in the same flow.

Step 7: Test Your OpenAI API Key

Once you have your key set as an environment variable, verify it works with a single curl request:

curl https://api.openai.com/v1/responses \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "gpt-5.5",
    "input": "Tell me a three sentence bedtime story about a unicorn."
  }'

If your key is valid, you'll get a JSON response containing the model's reply. The complete reference is in the OpenAI Responses API documentation.

If you're hardcoding the key for a one-off test (don't do this in production), replace $OPENAI_API_KEY with the literal sk-... string.

Is the OpenAI API Free?

No. The ChatGPT web app has a free tier, but the API does not. You pay per token in and per token out, with rates that depend on the model. As of May 2026, GPT-5.5 sits at the premium end of the price list, while smaller models like gpt-4.1-mini and gpt-4o-mini are an order of magnitude cheaper for the same token count.

OpenAI does occasionally hand out free credits to new accounts, and you can sometimes get free access through partner programs (Microsoft for Startups, Azure free tier, etc.), but the default API path is paid.

Key Comparisions between OpenAI, Gemini and Anthropic API key styles

OpenAIAnthropicGeminiGrokPerplexity
Auth headerAuthorization: Bearerx-api-keyx-goog-api-keyAuthorization: BearerAuthorization: Bearer
Endpointapi.openai.com/v1/responsesapi.anthropic.com/v1/messagesgenerativelanguage.googleapis.com/v1beta/...api.x.ai/v1/chat/completionsapi.perplexity.ai/chat/completions
Request shapemessages arraymessages + systemcontents with partsmessages (OpenAI-compatible)messages (OpenAI-compatible)
Env varOPENAI_API_KEYANTHROPIC_API_KEYGEMINI_API_KEYXAI_API_KEYPERPLEXITY_API_KEY
Key formatsk-...sk-ant-...AIza...xai-...pplx-...
Built-in web search?nononooptional via toolsyes (Sonar)
Citations included?nononooptionalyes (Sonar)
OpenAI SDK works?

Azure OpenAI API Key (Different Flow)

If you're working in an enterprise that runs on Azure, you probably want an Azure OpenAI API key, not a direct OpenAI key. The two are not interchangeable.

To get an Azure OpenAI API key:

  1. You need an Azure subscription with access to the Azure OpenAI service (this used to require a request form, and depending on your region still might)
  2. Create an Azure OpenAI resource in the Azure Portal
  3. Once the resource is provisioned, go to the resource's "Keys and Endpoint" page
  4. Copy KEY 1 (or KEY 2) and the endpoint URL

The Azure key works against the Azure endpoint (https://YOUR-RESOURCE.openai.azure.com/), not against api.openai.com. The model names are also different (gpt-5.5 vs the Azure deployment name you assign).

Security Best Practices

A leaked API key on a public repo can drain a budget overnight. The basics:

  • Rotate keys on a schedule, not just when you suspect a leak. Quarterly is reasonable for most teams.
  • Use a different key per environment. Dev, staging, and prod should never share a key.
  • Monitor usage daily. A spike at 3am usually isn't legitimate traffic.
  • Add request rate limiting in your application, not just on OpenAI's side.
  • Restrict by IP if your platform supports it.

Troubleshooting Common Errors

incorrect api key provided — The key in your Authorization header is wrong, expired, or revoked. Regenerate at platform.openai.com/api-keys and update your env var.

insufficient_quota — Billing isn't set up, or you've hit your hard limit. Add a payment method and check your usage caps.

rate_limit_exceeded — You're sending requests faster than your tier allows. Implement exponential backoff and check your rate limits page.

invalid_request_error with model not found — You're calling a model your account doesn't have access to. New models often roll out to Tier 1+ accounts first. Check which models your account can access in the dashboard.

Authentication header malformed — The header must be exactly Authorization: Bearer sk-.... No quotes around the key, no extra whitespace.

FAQ

Where do I find my OpenAI API key? At platform.openai.com/api-keys. Existing keys are listed there, but the secret value is only shown at creation. If you've lost a key, generate a new one and revoke the old.

How do I create an OpenAI API key for the first time? Sign up at platform.openai.com, complete email and phone verification, create an organization, then go to API keys → Create new secret key. Copy the sk-... string immediately.

Is the OpenAI API key free? The key itself is free to generate. Using it is not. You need a payment method on file before requests will succeed.

How do I copy my OpenAI API key after creation? Click the copy icon in the dialog that appears when the key is generated. The full key is only visible at this moment. Once you close the dialog, OpenAI shows only the last four characters.

How do I set the OPENAI_API_KEY environment variable in Python? The OpenAI Python SDK reads the OPENAI_API_KEY env var automatically:

export OPENAI_API_KEY="sk-..."

Then in Python:

from openai import OpenAI
client = OpenAI()  # picks up the env var

What does an OpenAI API key look like? A string that starts with sk- followed by alphanumeric characters. Project keys start with sk-proj-. Don't share either.

How do I get a free OpenAI API key? You don't, in the ongoing sense. Some accounts get a small one-time credit allocation, and partner programs (Azure, Microsoft for Startups) can provide credits. There is no permanent free tier for API access.

Next Steps

With your key working, the OpenAI docs are the source of truth for what to build next:

If your use case involves generating text for end users, it's worth understanding how ChatGPT detection works to help prevent misuse of AI-generated content.

Ready to get started?

Scale your integration strategy and deliver the integrations your customers need in record time.

Ready to get started?
Talk to an expert

Trusted by fast-moving product & engineering teams

JobNimbus
Blue Zinc
Exact
Drata
Octa
Apideck Blog

Continue reading