How to set up an OpenAI API key

Create an OpenAI API key, set spending limits and alerts, connect your app, troubleshoot error codes, and replace keys safely.

A coral key connects a navy app tile to a teal doorway bearing OpenAI’s interwoven knot symbol.

To use OpenAI in an app that asks for your own API key, you’ll need to create one and connect it to the app. The key lets the app send requests through your OpenAI account, using your API access and billing.

This guide walks you through account setup, billing, spending limits, key creation, and connecting your app. Start by signing in to the OpenAI Platform. You can follow these steps without writing code. The exact labels may change as OpenAI updates its dashboard.

Start with an OpenAI Platform account

You create API keys in the OpenAI Platform. Sign in with your OpenAI account, or create an account if you don’t have one. Complete any setup prompts shown before continuing.

  1. Open the OpenAI Platform in your browser and sign in.
  2. Check which organization is selected if you belong to more than one. This is the account boundary for billing and access.
  3. Select the project you want the app to use. A project groups keys and resources for a particular piece of work. You can use an existing project or create a separate one if your account allows it.

A separate project for each app makes its access easier to manage later. If you’re using a team account and can’t access the project, ask its owner to add you with the permissions you need. OpenAI’s platform permissions guide explains how project access works.

Set up API billing separately from ChatGPT

A ChatGPT subscription does not pay for ordinary requests made with an OpenAI API key. API usage follows separate API pricing. You don’t need to buy ChatGPT Plus or Pro to follow this guide. OpenAI explains the distinction in its pricing documentation.

  1. Open the organization’s Billing settings.
  2. Follow the billing setup shown for your account. Add a payment method and purchase credits if your account uses prepaid billing. Check the amount and terms before confirming.
  3. Review any automatic recharge setting so you know whether more credits will be purchased automatically.

Creating a key and paying for requests are separate steps. Having a key doesn’t guarantee that the account has credits or access to every model. The cost of a request depends on the model and what the app sends and receives.

Set a monthly spending cap and alerts before you start

Choose an amount you’re comfortable spending while you try the app. For example, a $10 monthly cap with alerts at $5 and $8 gives you two chances to review usage before reaching it. These are example settings, not a minimum purchase or an estimate of what your app will cost.

  1. Open the app’s project in Project settings, then select Limits.
  2. Under Spend, choose Edit spend limit and enter your monthly amount.
  3. Turn on Enforce a hard limit if you want requests to stop when tracked spend reaches that amount. Save the change.
  4. Add spending alerts below the cap. Choose thresholds that leave you time to check what the app is doing.
  5. If several projects share your account, review Organization limits too. An organization cap applies across its projects; a project cap covers that project.

Review automatic recharge separately in Billing: it controls credit purchases, while spending limits control API use. After a few days, check the Usage dashboard before adjusting your cap. If costs rise unexpectedly, pause the app’s AI features and check the activity first.

Create a project API key and save it securely

With the right project selected, open the API keys page. This is the dashboard linked from OpenAI’s API quickstart.

  1. Choose Create new secret key, or the equivalent create-key action shown.
  2. Give the key a name you’ll recognize, such as Writing app — personal. Confirm the project if the dialog asks you to select one.
  3. Choose permissions that match the app’s instructions. Read-only access won’t allow text generation. If you restrict permissions, include the operations the app needs.
  4. Set an expiration date if that option is available, and plan to replace the key before it expires.
  5. Create the key, copy the full secret while it is displayed, and store it in a password manager or another secure secret store before closing the dialog.

Treat the full secret as something you need to save at creation. If you lose it, create a replacement key and remove the unused one. A recognizable name helps you find the right key later, but the name itself isn’t the credential you paste into an app.

Use a separate key for each app so you can revoke one connection without replacing them all. OpenAI’s API key guidance covers secure storage, expiration, and replacement.

Paste the API key into your app’s OpenAI settings

Return to the app that asked for the key. The settings location varies, but look for its AI provider or OpenAI connection settings.

  1. Select OpenAI as the provider if the app offers a choice.
  2. Paste the full secret into the API key field. Paste just the key, without quotation marks, extra spaces, or the word Bearer.
  3. Save the connection. If the app asks for a model, choose one it supports and your API project can access.
  4. Use the app’s connection test if it has one, or try one short request, such as asking for a one-sentence summary.

A successful generated response checks the connection for that feature and model. It also uses API usage, so start with a small request.

Check billing, permissions, and limits if the key fails

Read the app’s error details before creating another key. Look for the HTTP status and error.code; a 429 alone doesn’t tell you whether to add credits, adjust a limit, or wait. If the app hides these details, check its connection log or ask its support team for the full error, keeping your key out of the report.

Common setup problems and what to check first
What you seeWhat to check
401 — invalid key or authentication errorPaste the full secret again without extra spaces. Check whether it was revoked or expired.
429 — credit_balance_exhaustedThe organization’s prepaid credits are depleted. Add credits in Billing.
429 — project_spend_limit_exceededThe selected project reached its hard spend cap. Review usage, then raise the cap if appropriate or wait for the monthly reset.
429 — organization_spend_limit_exceededThe organization reached its hard spend cap across projects. Ask its owner to review spending and the cap, or wait for the monthly reset.
429 — organization_usage_limit_exceededThe organization reached its OpenAI-approved usage limit. Request a higher limit; adding credits won’t raise it.
429 — rate limit reachedReduce simultaneous requests. Follow Retry-After if present; otherwise retry with increasing delays. For rate_limit_error with code slow_down, also ramp up requests gradually.
Permission denied or model unavailableCheck the key’s permissions, your project access, and the model selected in the app.

OpenAI’s error guide lists these codes. Billing and quota errors can share the broader insufficient_quota type, so check the specific code. Repeated retries or a replacement key won’t restore credits or raise limits.

After your first successful request, open the Usage dashboard and select the matching organization, project, and date range to review activity and cost. Check it again after you’ve used the app for a while to understand your normal spending.

How to replace your OpenAI API key

For a routine replacement, update and test the app before revoking its current key. Do this before the key expires.

  1. Create a replacement. On the API keys page, create a new key in the same project with the permissions your app needs. Give it a distinct name and save the secret securely.
  2. Update the app. Replace the saved key in its OpenAI settings and save the connection. Update any other installation using the old key too.
  3. Verify it works. Send a short request with the model and feature you normally use. Confirm that you receive a generated response; saving the settings alone doesn’t verify access.
  4. Revoke the previous key. Once every connection works with the replacement, return to the API keys page and revoke or delete the old key. Remove its saved secret from your password manager.

If the old secret has been exposed, revoke it immediately, then create and connect a replacement. Review usage for unexpected activity. Keep a separate key for each app so future replacements are easier to manage.

Get more from our apps with API keys

Connect your OpenAI or Claude API key to use AI features in our apps. Here’s how each app puts your key to work.

  • Flux

    App Store tools

    Translate App Store reviews into your language, then translate your replies into the reviewer’s language before sending.

    Explore Flux

By Echo-O · Edited by Alexander Martirosov