Skip to main content Skip to main content

API access guide

How to Get an OpenAI API Key

Sources checked November 18, 2026. An independent guide by Cue. Cue is made by Sophon LLC and is not affiliated with OpenAI or Anthropic. OpenAI sets the terms, prices and account decisions for its API.

Published · Cue editorial team

What this guide covers

This guide walks through creating or signing in to an OpenAI platform account, adding billing, creating a secret API key, making a first request, checking usage, and fixing common key errors. It is for people who want to call the OpenAI API from their own script or app. It does not cover ChatGPT subscriptions, which are billed separately.

Prerequisites

  • An account: an OpenAI sign-in method you control and can recover.
  • Billing: a payment method or prepaid option that OpenAI offers where you live. Availability varies, and I could not verify a full list (UNKNOWN).
  • Basic code familiarity: you should be able to open a terminal, set an environment variable, and run a short script. The examples use curl and JavaScript with Node.js.

Step 1: Create or sign in to your OpenAI platform account

Open the API keys page. Sign in, or create an account when prompted. Use an account you own.

If your organization already has an API account, ask the organization owner to invite you instead of sharing a key. OpenAI's member management guide covers this.

Step 2: Add billing and understand usage-based pricing

Open the billing settings page, which OpenAI links from its error reference. Add a payment method or credits as the page shows.

API usage is metered. The OpenAI API pricing page and the developer pricing reference list rates. The reference says prices are per 1M tokens unless noted, and it lists some built-in tools separately. Read the rates for the model you plan to use before you start. This guide does not quote prices, because they change and differ by model.

If your prepaid balance runs out, requests can fail with a credit_balance_exhausted error. See the troubleshooting section below.

Step 3: Create a secret key and copy it once

  1. Open the API keys page.
  2. Create a new secret key, and give it a name that matches the app or script that will use it.
  3. Copy the key right away and store it in a password manager. OpenAI's API key help article says a full secret key is shown only when you create it. If you lose it, create a new key and update your application. Deleted keys cannot be used.
  4. Never paste the key into a chat, a screenshot, or source code.

I could not read the text of the API keys page, so button labels may differ from these steps.

Step 4: Make your first API call

Store the key in an environment variable so your code never contains it. On macOS or Linux, run this in your terminal, replacing the placeholder with your key:

export OPENAI_API_KEY="your_api_key_here"

In Windows PowerShell, use the following, then open a new terminal window:

setx OPENAI_API_KEY "your_api_key_here"

Test with curl. Replace MODEL_ID with a model your account can use:

curl "https://api.openai.com/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "MODEL_ID",
    "input": "Say hello in one short sentence."
  }'

For JavaScript, install the official SDK with npm install openai, then save this as hello.mjs:

import OpenAI from "openai";

// The SDK reads OPENAI_API_KEY from the environment.
const client = new OpenAI();

const response = await client.responses.create({
  model: "MODEL_ID",
  input: "Say hello in one short sentence.",
});

console.log(response.output_text);

Run it with node hello.mjs. The developer quickstart uses this same pattern. If you get an error, go to the troubleshooting section.

Step 5: Verify usage

After a successful call, open the usage dashboard in your platform account and confirm the request appears. OpenAI's usage export article describes the API Usage Dashboard. There you can view monthly usage and export usage or cost data as CSV for a full calendar month or month to date. If the request does not appear yet, check again later. I could not verify how long it takes (UNKNOWN).

Can I use the API for free?

OpenAI's pricing pages describe usage-based rates. I could not verify from official pages whether new accounts receive free credits or a free tier for any model (UNKNOWN). Some items in the pricing reference are listed as free or include a free allowance, such as a 1 GB allowance for some file storage, and a free moderation model. Check the current pricing page for your model and tools before assuming any call is free.

How do I keep the key safe?

Follow OpenAI's best practices for API key safety. In practice:

  • Never commit a key to git. Keep it in an environment variable or a local secret store, and add .env files to .gitignore. Review staged changes before every push.
  • Rotate if exposed. If a key appears in a repository, log, screenshot, or chat, delete it on the API keys page, create a new key, and update your application. Deleted keys stop working.
  • Use one key per project. Give each app, script, and teammate its own key. OpenAI says sharing API keys goes against its Terms of Use, so invite teammates to their own accounts.
  • Set expiry dates. Project keys can expire on a set date. Create the replacement before it expires, and revoke the old key after the new one works.
  • Keep keys out of support requests. Do not send keys to any support team.

Why isn't my key working?

Read the status code and the error message, then match them to OpenAI's error reference.

Status and messageLikely causeWhat to do
401 Incorrect API key providedThe key is wrong, deleted, or from another accountCheck the key on the API keys page. Make sure one key is used throughout your code. See Incorrect API key provided.
401 You must be a member of an organizationYour account is not in the organization that owns the keyAsk your organization manager to invite you.
401 IP not authorizedThe request comes from an IP address outside the allowlistSend the request from an allowed IP, or update the allowlist.
429 Rate limit reached for requestsYou are sending too many requests or tokens in a short periodSlow down, and follow the Retry-After header when present. See the rate limit guide and 429 troubleshooting.
429 credit_balance_exhaustedYour prepaid credits are used upAdd credits in billing settings. Retrying alone won't fix it.
429 with insufficient_quota error typeA billing-related limit was reachedCheck billing and any usage limits, then follow the 429 troubleshooting article.
403 Country, region, or territory not supportedThe API is being accessed from an unsupported locationCheck the supported countries list, which the error reference links to.

For a message not listed here, search the error reference for the exact text. I could not verify the full meaning of every 403 message (UNKNOWN).

Does Cue need my own OpenAI API key?

UNKNOWN. I checked Cue's public pages at heycue.io, pricing, and FAQ. They list models, but none I read says whether Cue's own features need your OpenAI API key. Check your Cue settings and plan details before you rely on either path. Never send API keys to Cue support.

Unverified or unavailable items

  • platform.openai.com/docs/quickstart redirected across origins and was not followed. I used the Markdown version at developers.openai.com/api/docs/quickstart instead.
  • platform.openai.com/api-keys returned no readable page text. Key steps rely on OpenAI's help article, and button labels are unverified.
  • The OpenAI pricing page at openai.com/api/pricing/ was truncated in my fetch. Rates come from the developer pricing reference. No prices are quoted here.
  • Free credits or a free tier for new accounts: UNKNOWN.
  • Meaning of every 403 message: UNKNOWN beyond the country case.
  • Whether Cue requires your own OpenAI API key: UNKNOWN.

Cue is an independent desktop AI assistant from Sophon LLC. Use Cue to work with authorized documents, notes, and tasks, with Claude and GPT model options. Check Cue's plan details for what your account includes and which models it offers. API keys, billing, and usage for your OpenAI account stay with OpenAI.