---
title: "How to Get Your ChatGPT (OpenAI) API Key"
description: "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."
author: "Kateryna Poryvay"
published: "2025-08-29T00:00+03:00"
updated: "2026-05-06T07:57:01.515Z"
url: "https://www.apideck.com/blog/how-to-get-your-chatgpt-openai-api-key"
tags: ["AI", "Guides & Tutorials"]
---

# How to Get Your ChatGPT (OpenAI) API Key

## Step 1: Create an OpenAI Account

Navigate to [platform.openai.com](https://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](//images.ctfassets.net/d6o5ai4eeewt/4FBK3PKin1PseeBWeeYhBP/fb91d9c3e6e86f7ea54dc24123de2676/Screenshot_2025-08-29_at_17.34.41_2x.png)

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](//images.ctfassets.net/d6o5ai4eeewt/37Iz8cj1AM2j6bi47SyXm5/605853e6737055b2bc0aa43b8a520f7b/Screenshot_2025-08-29_at_17.36.59_2x.png)

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](https://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](//images.ctfassets.net/d6o5ai4eeewt/4fWS7qOY3x2cju0A392EbR/06eb3e75d63382c8feab70a3147038fa/Screenshot_2025-08-29_at_17.38.39_2x.png)

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](//images.ctfassets.net/d6o5ai4eeewt/4Z6TCgY0BDX3ltQ7jDM8be/d8cc4363434b453910da41b06216997f/Screenshot_2025-08-29_at_17.39.13_2x.png)

## Step 3: Where to Find Your OpenAI API Key

![openai api key 4](//images.ctfassets.net/d6o5ai4eeewt/4YZNkMzJpD6MygAyRxq0U6/e91b0f334068a0b4edbaca02d552b2d5/Screenshot_2025-08-29_at_17.45.20_2x.png)

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](https://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](//images.ctfassets.net/d6o5ai4eeewt/441vMaNMKfPVEzL011nZgZ/b9b13d930cca85e40114a9862c77f008/Screenshot_2025-08-29_at_17.46.01_2x.png)

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](https://openai.com/api/pricing/) 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](https://platform.openai.com/docs/api-reference/introduction).

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

| | OpenAI | Anthropic | Gemini | Grok | Perplexity |
|---|---|---|---|---|---|
| Auth header | `Authorization: Bearer` | `x-api-key` | `x-goog-api-key` | `Authorization: Bearer` | `Authorization: Bearer` |
| Endpoint | `api.openai.com/v1/responses` | `api.anthropic.com/v1/messages` | `generativelanguage.googleapis.com/v1beta/...` | `api.x.ai/v1/chat/completions` | `api.perplexity.ai/chat/completions` |
| Request shape | `messages` array | `messages` + system | `contents` with `parts` | `messages` (OpenAI-compatible) | `messages` (OpenAI-compatible) |
| Env var | `OPENAI_API_KEY` | `ANTHROPIC_API_KEY` | `GEMINI_API_KEY` | `XAI_API_KEY` | `PERPLEXITY_API_KEY` |
| Key format | `sk-...` | `sk-ant-...` | `AIza...` | `xai-...` | `pplx-...` |
| Built-in web search? | no | no | no | optional via tools | yes (Sonar) |
| Citations included? | no | no | no | optional | yes (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](https://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](https://platform.openai.com/account/limits).

**`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](https://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:
- [API reference](https://platform.openai.com/docs/api-reference)
- [Model list and capabilities](https://platform.openai.com/docs/models)
- [Pricing](https://openai.com/api/pricing/)

If your use case involves generating text for end users, it's worth understanding how [ChatGPT detection](https://gptzero.me/news/how-chatgpt-detection-works/) works to help prevent misuse of AI-generated content.
