sodcalculator

10 Tech How-To

How to Get a ChatGPT API Key

Guide 10-39241 · Updated · Step by step

A ChatGPT API key lets an app or program authenticate with OpenAI’s API and request model responses. You’ll create the key in the OpenAI developer platform; you need an account, and API use may require a separately configured payment method or available credits. An API key is secret, so store it securely and do not paste it into public code or messages.

What You’ll Need

  • An OpenAI account you can sign in to.
  • Access to the OpenAI developer platform and the organization or project where the API should be used.
  • A secure place to save the key, such as a password manager or a local environment variable. Avoid documents or repositories that other people can access.
  • If you plan to make API requests, an API billing setup or other available API quota. ChatGPT subscriptions and API billing are separate.

Step-by-Step

  1. Open the developer platform. Go to platform.openai.com and sign in with your OpenAI account. If you have not used the platform before, follow the prompts to set up your developer account and accept any applicable terms.
  2. Choose the right project. In the platform, select the project that will use the key. Projects help separate applications and control access. If you have no suitable project, create one using the available project controls, then give it a clear name so you can identify its purpose later. The platform’s layout can change, so look for the project selector and the project’s settings or API key area.
  3. Open the API keys page. Find the API keys section for the selected project. You may reach it through the project settings or the platform’s navigation. Make sure you are viewing keys for the intended project, especially if you belong to more than one organization or project.
  4. Create a new secret key. Choose the option to create a secret key. If the form offers a key name, add a descriptive label such as “website staging” or “local testing.” Use the narrowest permissions the task supports if permission settings are offered. Avoid granting broader access than the integration needs.
  5. Copy the key as soon as it appears. The full secret is typically shown only when it is created. Copy it directly into your password manager or another approved secret store. Do not send it to anyone, put it in a screenshot, or leave it in a browser tab, chat, or shared note. If you close the display without saving it, create a replacement key rather than expecting to reveal the old secret again.
  6. Configure your application safely. For local development, put the key in an environment variable or a local configuration file that is excluded from version control. Many OpenAI API examples use an environment variable named OPENAI_API_KEY; check your chosen library’s current setup instructions. In a hosted app, use the hosting provider’s secret or environment-variable settings. Keep API calls on a server you control: do not embed a secret key in browser code or a mobile app, where users may be able to extract it.
  7. Check API access and billing. A key is an identifier and credential, not a grant of unlimited or free use. In the platform, review the project’s available API features, usage limits, and billing setup. Add a payment method or configure billing only if required and appropriate for your use. API charges and usage are handled separately from a ChatGPT plan.
  8. Make a small test request. Use an official example or a trusted library’s current documentation, with the key supplied through the secure configuration you created. Start with a simple request and check the response and usage in the platform. Do not put the key directly into a command that will be saved in shell history or shared logs; use an environment variable or a safer method supported by your tools.
  9. Revoke keys you no longer need. Return to the project’s API keys page and revoke an unused or exposed key. Update the application with a replacement key through its secret settings. Do not assume deleting a local copy invalidates a key that has already been shared.

Common Mistakes

  • Looking for the key in ChatGPT settings. ChatGPT and the API platform are different products. A ChatGPT plan does not automatically provide an API key; create and manage API keys in the developer platform.
  • Confusing a key with billing. Creating a key does not necessarily enable API usage. If a request fails for quota or billing reasons, check API billing and project limits rather than repeatedly creating keys.
  • Using the wrong project. A key belongs to a particular project. Select the project that your application is configured to use and check its permissions and usage settings.
  • Expecting to see the full key later. Save it at creation time. If it is lost, create a new key and update your app.
  • Publishing the secret. Never commit a key to a public repository, include it in front-end JavaScript, or share it in a support post. If exposed, revoke it promptly and replace it.

Tips

  • Create separate keys or projects for distinct applications or environments when that helps you limit access and identify usage.
  • Use descriptive key names, but do not include the secret itself in the name.
  • Set usage notifications or limits where available, and review activity periodically. These controls help you notice unexpected use, but they do not replace protecting the key.
  • Keep secrets out of source control. If you use a local .env file, ensure it is excluded from version control and follow the instructions for your programming language or framework.
  • When troubleshooting, check the platform’s current API documentation and service status. Interface labels and available models or permissions can change.

Troubleshooting

  • You cannot find API keys: Confirm you are on the developer platform, not the ChatGPT app, and that you have selected the correct organization and project. If the page is unavailable, try the platform’s navigation or project settings.
  • You cannot create a key: Check that your account has access to the selected project and that your organization permits key creation. Ask the project or organization administrator to review your access if needed.
  • The key is rejected: Check for missing characters, extra spaces, an outdated key, or a key copied from a different project. Update the secret in the application and restart or redeploy it if the app only reads environment variables at startup.
  • The request reports a quota or billing problem: Review the project’s billing status, available quota, spending controls, and usage. A ChatGPT subscription does not pay API charges.
  • The key may have leaked: Revoke it immediately in the platform, create a replacement, and update every service that used the old key. Review API usage for activity you do not recognize.
  • The API call still fails: Check the exact error message, request format, project access, and the current API documentation. Avoid posting the full request if it contains a key or other private information.

Frequently Asked Questions

Is a ChatGPT API key free?
Creating a key does not necessarily cost anything, but API requests may be billed. Check the platform’s current pricing, billing status, and any available credits before use.

Does ChatGPT Plus include API access or credits?
ChatGPT subscriptions and API usage are billed separately. A subscription does not automatically include API credits.

Can I use one key for several apps?
You may be able to, but separate keys or projects make it easier to manage access, investigate usage, and revoke access for one app without disrupting others.

Can I show the key in a website’s JavaScript?
No. Browser code is visible to users. Keep the key on a server or in another trusted backend environment, and have that service make API requests.

What if I forgot to copy the key?
Check your secure store first. If you did not save it, create a new key and use that one; do not rely on being able to reveal the original secret again.

How do I change or delete an API key?
Create a replacement key, update the apps that need it, then revoke the old key from the project’s API keys page. Revoke a key immediately if it may be exposed.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →