ChatGPT API Key: How to Get One, Use It and Keep It Secure
A ChatGPT API key — more accurately an OpenAI API key — allows an authorised application to make requests to the OpenAI API. If you're new to the developer platform, start with our ChatGPT API guide, or explore the wider ChatGPT knowledge hub.
What Is a ChatGPT API Key?
Think of an API key as a secret credential used by your software to authenticate API requests. It is fundamentally different from your normal ChatGPT login.
Authenticates Requests
The credential allows OpenAI's API infrastructure to associate an authorised request with the relevant project and account configuration.
Used by Software
API keys are intended for programmatic integrations such as applications, backend services, plugins and automated workflows.
Must Remain Secret
Anyone who obtains a usable secret key may potentially attempt requests against the associated API resources, so it needs careful protection.
Works With Projects
Project-based organisation helps separate applications, credentials, usage and access instead of relying on one credential everywhere.
How to Get a ChatGPT API Key
The exact interface can evolve, but the underlying process is straightforward: access the OpenAI developer platform, choose the appropriate project and create a credential for your integration.
Access the Developer Platform
Sign in to the OpenAI developer platform using the account associated with the API organisation or project you intend to use.
Select the Project
Choose or create the appropriate API project. Separating projects can make permissions, usage monitoring and application management cleaner.
Create the Secret Key
Create a new API credential and configure the available permissions according to what the application genuinely requires.
Store It Immediately
Move the credential into an appropriate secret-storage method rather than leaving it in notes, screenshots, messages or public source code.
Understanding API Key Permissions
A useful security principle is least privilege: give a credential the access its application needs, rather than automatically granting broader permissions.
Broader Access
A credential with broad project permissions can be convenient during development, but wider access also increases the potential impact if the credential is accidentally exposed.
Restricted Access
Where available and appropriate, restrict access according to the endpoints or capabilities the application actually needs. This reduces unnecessary privilege.
Disabled Access
If a particular capability is not required, removing or disabling access helps keep the application's security boundary narrower and easier to audit.
Where Should You Store an OpenAI API Key?
The goal is simple: the application should be able to use the credential, but ordinary visitors and unauthorised users should never be able to retrieve it.
Safer Places to Store the Key
The exact solution depends on your hosting environment and application architecture, but secret credentials belong on the protected side of the system.
- Server-side environment variables.
- A dedicated secret-management service.
- Protected server configuration.
- Secure platform-level environment settings.
- Backend application configuration with appropriate access controls.
- Separate credentials for unrelated applications where practical.
Where Not to Put Your API Key
If ordinary website visitors can inspect or download the location containing your secret, you should assume the credential can eventually be extracted.
- Public browser JavaScript.
- HTML source code.
- Public GitHub repositories.
- Client-side application bundles.
- Screenshots or public tutorials containing the real key.
- Shared documents accessible to unnecessary users.
Using an API Key With Environment Variables
Environment variables are a common way to keep configuration outside the application's source code, although production secrets still need appropriate platform-level protection.
Keep the Secret Out of Your Source Code
Instead of writing the real API key directly into application files, developers commonly assign it to an environment variable and let the server-side application read that value at runtime. This also makes it easier to use different credentials across local development, staging and production.
OPENAI_API_KEY=your_secret_key_here
Application → Environment Variable → OpenAI API
How to Use a ChatGPT API Key in WordPress
WordPress can connect to the OpenAI API, but the credential should remain on the server rather than being sent to every visitor's browser.
WordPress → Server → OpenAI API
A properly designed plugin or custom integration makes the OpenAI request from a protected server-side process. Your visitor interacts with the WordPress interface, while the secret credential stays behind the scenes.
What Should You Do If Your API Key Is Leaked?
Treat an exposed credential as compromised. Removing the public copy alone is not enough because someone may already have captured it.
Do Not Wait to See Whether Someone Uses It
Once a secret key has appeared publicly, the safer response is to invalidate the exposed credential, replace it and investigate usage rather than assuming nobody noticed.
Should You Use Multiple API Keys and Projects?
Separating credentials and workloads can make a growing API setup easier to secure, troubleshoot and monitor.
Separate Development
Keeping experimental or development workloads separate from a production application can reduce accidental interference and make usage easier to understand.
Separate Applications
Unrelated products do not necessarily need to share the same credential. Separation can make revocation and troubleshooting more targeted.
Control Team Access
Use project and organisational controls rather than casually sharing one secret key among every developer, service and application.
Does Creating an API Key Cost Money?
The important distinction is between possessing a credential and the usage generated when an application makes API requests.
The API Key Is Not a ChatGPT Subscription
Your API key authenticates API requests. API usage is then measured according to the applicable developer-platform pricing and the models or capabilities your application uses.
ChatGPT Plus or Pro should not be treated as prepaid API usage. For cost planning, see our dedicated ChatGPT API pricing guide.
≠
ChatGPT Subscription
Why Is My ChatGPT API Key Not Working?
Authentication errors are often caused by configuration problems rather than a need to generate keys repeatedly.
Invalid Authentication
Confirm that the application is actually sending the intended active credential and that the value has not been copied incorrectly or revoked.
Permission Problem
A restricted credential may not have access to the operation your application is attempting. Review project and key permissions.
Environment Variable Error
Check that the variable name is correct, the application can read it and the server was restarted or redeployed if the environment requires it.
Account or Usage Issue
Authentication may be valid while a request still fails because of billing, limits, model access or other API account configuration.
ChatGPT API Key vs ChatGPT Login
Both relate to OpenAI services, but they serve very different authentication purposes.
ChatGPT Login
Your ChatGPT login is for accessing the ChatGPT application as a user. It provides access to the features available under your ChatGPT account and plan. See our ChatGPT login guide for account-access help.
OpenAI API Key
An API key is a secret developer credential used by software when making authorised API requests. It is not something a normal ChatGPT user needs simply to have conversations in the ChatGPT app.
Common Questions About ChatGPT API Keys
Quick answers covering API-key creation, cost, security, WordPress, exposed credentials and the relationship between ChatGPT and API access.
01 What is a ChatGPT API key?
It is a secret credential used by software to authenticate requests to the OpenAI API. “ChatGPT API key” is a common search term, although the credential belongs to OpenAI's developer API platform.
02 How do I get a ChatGPT API key?
Access the OpenAI developer platform, select the appropriate project and create an API credential with suitable permissions. Store the new credential securely rather than publishing it in your source code.
03 Is a ChatGPT API key free?
Do not confuse creating a credential with API usage costs. Applications using the credential can generate separately billed API usage. See our API pricing guide.
04 Does ChatGPT Plus give me an API key?
ChatGPT subscriptions and developer API usage are separate. A Plus subscription should not be treated as API credit for your own application.
05 Can I share my OpenAI API key?
Avoid casually sharing secret credentials. For teams and applications, use appropriate project, account and access-management controls rather than passing one secret around unnecessarily.
06 Can I put my API key in JavaScript?
Do not expose a private secret key in public browser-side JavaScript. Use a protected server-side component to make authenticated API requests.
07 What happens if my API key is leaked?
Treat an exposed secret as compromised. Revoke it, create a replacement, update your application and review usage for unexpected activity.
08 Can I use one API key for several websites?
Technically an integration architecture may allow credentials to serve more than one workload, but separating unrelated applications or projects can improve security, monitoring and targeted credential rotation.
Continue Learning About the ChatGPT API
The API key is only one part of an integration. These supporting guides cover the wider API, costs, coding and ChatGPT ecosystem.
ChatGPT Hub
Explore our central ChatGPT knowledge hub covering features, plans, tools, workflows and supporting guides.
Explore ChatGPT → APIChatGPT API
Learn how the OpenAI API works, what developers can build and how models, tools and requests fit together.
API Guide → £ChatGPT API Pricing
Understand usage-based API pricing, cost drivers and how to estimate the budget for an AI application.
API Pricing → CODEChatGPT for Coding
Explore practical ways developers can use ChatGPT and OpenAI tools for coding, debugging and software-development workflows.
Coding Guide →Treat Your API Key Like a Production Credential
Getting an OpenAI API key is the easy part. The more important job is keeping it out of public code, limiting unnecessary access, separating important workloads and replacing credentials quickly when exposure is suspected. Secure key management gives you a much stronger foundation for building WordPress tools, SaaS features, SEO automations and other applications with the OpenAI API.