OpenAI API Key for Your First App: ChatGPT Credits and Setup
Create a project key, check whether your ChatGPT plan includes API credits, and send a first Python request. Find the right fix for 401 and 429 errors.
Published

If a tool asks for a “ChatGPT API key,” it wants an OpenAI API key so it can send requests on your project’s behalf. ChatGPT Plus doesn’t include API usage. Eligible paid Pro and Business subscribers can claim API credits for one linked API organization after at least 7 days on a qualifying subscription.
The first decision is whose bill the app should run on. If you’re connecting a client’s document tool, ask the client which API organization pays for it. A key you create in your personal project still sends the usage there, even when someone else clicks “Summarize.” OpenAI documents separate billing for ChatGPT and the API. The setup and credit rules below were checked on November 25, 2026. Billing settings for the two products.
Is an OpenAI API key free to use with your ChatGPT plan?
If you pay for Plus, budget separately for the API. If you own an eligible paid Pro subscription or Business workspace, check for an API credit grant before buying credit. The qualifying paid subscription must have been active for at least seven days. For Business, the benefit applies to eligible paid Standard or Premium seats. Plus plan details.
To claim, open Billing in your ChatGPT settings (workspace billing for Business), find the API credits benefit and select the receiving API organization. You must own that organization and the qualifying subscription or workspace. Confirm the link, then open the organization’s API billing page and look for the grant. The first grant can be smaller than the full allowance because it covers the remaining billing period. OpenAI’s eligibility and activation instructions.
That distinction matters if you belong to both a work organization and a personal one. A credit grant in your personal organization cannot fund the work project. Check the organization name before confirming the link and again before making the key.
Generate OpenAI API key credentials for the right project
Think of the key as a staff pass at a library. It lets the holder make a request at the counter. The project determines which resources the pass can reach, and the organization holds the balance that pays for the work.
Choose the organization and project
Sign in to the OpenAI Platform and open organization settings. Select the organization you intend to charge, then the project for your app. If this is company work and the project is missing, ask its owner for access.
Create and save the secret
In the project, open API Keys and select + Create new secret key. For your own local development, use a user-owned project key. Choose Restricted to grant only the operations the app needs, including permission to create a response for the example below. Copy the secret when it appears. That is the only time OpenAI displays its full value.
Check funds and set a stopping point
An organization owner can add a payment method in the API billing overview. For a prepaid account without a usable grant, the minimum initial credit purchase is $5. Review automatic recharge if this is a one-off experiment. Prepaid billing instructions.
For a prototype, set a project budget before connecting the tool. As a project or organization owner, select the project in organization settings, open Limits, set Monthly spend limit and an alert threshold, then turn on Enforce a hard limit if requests should stop. An alert alone lets traffic continue. Recorded spending can slightly exceed an enforced cap while it takes effect. Project keys, permissions and spend limits.
OpenAI API key use in your app or a connected tool
In your own app, keep the secret on the server. The visitor’s browser sends your server the document or question. Your server reads the key, makes the OpenAI request and sends the answer back. A key built into frontend JavaScript goes out to each visitor along with the app, even if the page never displays it. OpenAI’s key safety guidance.

In a third-party tool, look for its documented private credential setting and check how the service stores and uses the secret. Giving a service your key authorizes it to make billable requests within that key’s permissions. Give the integration its own restricted key so you can disconnect it independently. If the instructions put the secret in a chat message, shared document or public page script, stop there.
For the Python example, set the environment variable OPENAI_API_KEY in the terminal where Python will run. An environment variable passes a value to the program without putting it in the source file. In Bash, the following prompts for the key without displaying it or putting the pasted value in the command history. Paste it at the prompt and press Enter.
read -rsp 'OpenAI API key: ' OPENAI_API_KEY
printf '\n'
export OPENAI_API_KEYWhen you deploy, put the value in your host’s server-side secret settings. Give a deployed app a project service account so its access can survive a developer leaving. API keys and service accounts.
Test OpenAI API key authentication with one request
OpenAI’s Python quickstart asks GPT-6.2 Astra to write a one-sentence bedtime story. It’s a small enough task that you can tell whether authentication, billing and model access work before connecting a larger workflow. Install the official Python library with python -m pip install openai, then save the quickstart example as example.py. Developer quickstart.
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-6.2-astra",
input="Write a one-sentence bedtime story about a unicorn.",
)
print(response.output_text)Run python example.py in the same terminal. The client reads the key from the environment. A successful call prints the story text. If you see an error, keep its code and message for troubleshooting and leave the secret out of screenshots.
OpenAI API key usage and your first dollar
At GPT-6.2 Astra’s short-context Standard rates of $8 per million uncached input tokens and $40 per million output tokens, $1 covers 50 requests of 1,000 uncached input tokens and 300 billable output tokens each, assuming text only and no extra fees. OpenAI API pricing.
Tokens are the pieces of text the model processes. The 50-request estimate is illustrative. The actual bedtime story will have its own token count. Use your own project’s usage figures when you estimate the cost of summarizing longer documents. The usage report shows activity and cost, while the billing page shows credits available to pay for it. Reading API usage and costs.
Fix the first failed request
Read the error code before changing the key. A perfectly valid key can return a billing error on the very first call. For a 429 response, inspect error.code: the broader type insufficient_quota can conceal several different fixes. OpenAI’s error-code reference.

For routine rotation, create a replacement key, change the server or integration’s secret, confirm a request succeeds with the replacement, then delete the old key using the trash icon on the API keys page. For a leak, revoke the exposed key immediately and review usage. Removing it from a file cannot invalidate copies someone already has. OpenAI’s guide to finding and deleting keys.
Do you need an OpenAI Codex API key?
If your goal is to use Codex with an eligible ChatGPT account, choose Sign in with ChatGPT. That session draws on your workspace allowance. Codex also supports API-key authentication for local workflows, which uses API billing. The ChatGPT-linked promotional credit benefit excludes Codex usage through API keys. Codex authentication options and Codex CLI setup for a team.
Questions about ChatGPT and API keys
Is ChatGPT an API?
ChatGPT is OpenAI’s chat app. “ChatGPT API” is a common name for the OpenAI API, the service software calls to use OpenAI models.
Can I get a free OpenAI API key?
You can create the credential without buying a key. Model usage draws on API credits or your API billing account.
Is ChatGPT API free now?
Eligible paid Pro and Business subscribers can claim credits. There is no unlimited API allowance attached to a ChatGPT login.
How much does a ChatGPT API key cost?
The bill comes from what your application sends and generates. Model choice, input length and billable output determine the text charge.
Can I get an API key for free?
For OpenAI, create your own key in the project dashboard. Check the organization’s available credit before running it.
Can I get API for free?
A claimed promotional grant can cover eligible requests until it expires or runs out. Check its balance in API Platform billing.
Can I get AI API for free?
It depends on the provider and the offer. For OpenAI, check your eligibility for a linked subscription grant before purchasing prepaid credit.
How to create an API key?
Choose the project in OpenAI Platform, open API Keys and select Create new secret key. The key setup walkthrough covers the process in detail.
Where can I find my OpenAI API key?
The project’s API Keys page lists its keys. For the full value of an existing one, use the private secret store where you saved it.
Where can I see my API key?
OpenAI displays the full secret when you create it. If that window is closed and you lost the saved copy, make a replacement.
How do I find my API token?
If the integration means an OpenAI secret key, check its private configuration or your secret manager. Avoid printing the value into logs to see whether it is set.
How do I download the ChatGPT app for Android?
Use the Google Play listing published by OpenAI. You can sign in to the app without creating a developer key. OpenAI’s official mobile download instructions.
Is there a better AI than ChatGPT?
For a document app, compare models on the same document and judge the accuracy, response time and cost you need. For the models in this example, start with the GPT-6.2 overview.
What are the 5 things you shouldn't tell ChatGPT?
Keep passwords, API keys, account recovery codes, payment card details and confidential client records out of a setup chat. A support helper can usually work from a redacted error message.
What are some things I should never ask ChatGPT?
For API setup, avoid asking it to inspect a live credential. Give it the code with the secret removed and the exact error message.
How private is ChatGPT?
Personal ChatGPT accounts have training controls under Data Controls. API data has separate rules: model training is opt-in and retention varies by endpoint. ChatGPT data controls and API data controls.
Is talking to ChatGPT healthy?
How it fits into your life matters. OpenAI identifies use that displaces relationships or obligations as a concerning pattern. OpenAI’s guidance on emotional reliance.
After the first response
For a Python app, use the GPT-6.2 API guide to choose between Astra and Sol for your own task. For a JavaScript app, the Vercel AI SDK guide covers the application code. If you also need to route requests between providers, see the Vercel AI Gateway guide. Once you know your typical input and output lengths, compare API costs for that workload.
- Published
- Category
- Build








