How to set up the OpenAI API with credit and a spend limit

Day 1, 25 minutes · beginner

Goal of this lessonCreate an OpenAI API project, buy the smallest amount of credit, set a hard monthly spend limit and make a project key that stays out of your code.

Why it matters

Before you write code with the OpenAI API in Python, set up a project, prepaid credit, a hard spend limit and a safe API key. ChatGPT is an app you chat with. The OpenAI API is the door for your own code: your Python script sends a question and receives the answer as data it can use. That opens up small tools of your own, but it also means a bill. API use is paid per use, and it is billed apart from any ChatGPT plan.

Across this course you write a small helper for Hedda, who runs the front desk at Otterbrook Community Pool (a made-up pool). Hedda answers the same questions every day: lesson times, free places, prices. Today you set up the account side before you write any code. You finish with a project, a small amount of credit, a hard spend limit and a key that is stored safely, out of your code.

What you build in this course

The course grows one Python project, one lesson at a time:

  1. Today: an API project, credit, a spend limit and a key.
  2. A first call, and how the reply is built up.
  3. Function calling: the model asks, your code answers.
  4. A remote MCP server, with approvals.
  5. A small agent with the Agents SDK.
  6. Cost, logging and a hand-check of ten answers.

You need basic Python and a payment card. If you did the Claude API for Beginners course, much of this will look familiar: the same habits work for both.

Old tutorials are wrong now

OpenAI's deprecations page lists the Assistants API as shut down on 26 August 2026. Its replacement is the Responses API, with the Conversations API for stored conversations. So any blog post or video that creates "assistants", "threads" or "runs" will not work. This course uses only the Responses API. The same page lists the Evals API and Agent Builder as shut down on 30 November 2026; this course does not use them.

What it costs (read on 4 December 2026)

These facts come from OpenAI's help centre and pricing page on that day. They change, so check the pages yourself.

  • Billing is separate. The help centre says ChatGPT and the API platform have separate billing systems, and API usage is billed apart from your ChatGPT subscription. A ChatGPT plan does not pay for API calls, and Plus does not qualify for any API credit. One exception exists: eligible ChatGPT Pro and Business subscribers can claim promotional API credits for one linked API organization. Read "API credits benefit for eligible ChatGPT subscriptions" in the help centre if that is you; it also depends on country and cohort, so do not count on it.
  • New accounts prepay. You buy credit first and each call takes a little off. The minimum purchase is 5 US dollars, the default is 10. Purchased credit expires after one year and is not refundable except in the cases the help centre lists.
  • Auto-reload is on by default. During setup, a setting called Use auto-reload buys new credit when your balance gets low. Turn it off while you learn.
  • Prices are per million tokens. Tokens are the chunks of text the model reads and writes; one is roughly three quarters of a word. This course uses gpt-6-luna, which OpenAI's models page calls its most efficient model. On 4 December 2026 the pricing page listed it at 0.10 US dollars per million input tokens and 0.50 per million output tokens. Bigger models cost much more.
  • Do not plan on free use. Some pages mention free credits or a free test request, but no page says what a new account gets. Assume every call costs money.

Three ways to keep the bill small

  1. A hard spend limit. You can set a monthly limit on the organization, a project or a single key. With Enforce a hard limit on, requests fail with error 429 once the limit is reached. OpenAI warns this is not instant: spend can go slightly over.
  2. Small credit, no auto-reload. When the balance is used up, requests fail with credit_balance_exhausted. That is not instant either: a small negative balance comes off your next purchase.
  3. Small models and short answers. Lesson 2 sets max_output_tokens, a cap on how much the model may write per call.

Projects and keys

Your organization is the account-level home of your projects, members and billing. A project is a box inside it, for keys, limits and usage. One project per app keeps the bill of each app apart. The key is a secret: whoever holds it can use your credit. OpenAI's key safety article says: one key per person, set an expiry date, never commit it to git, never put it in a browser or phone app, and use an environment variable named OPENAI_API_KEY.

Where you can use it, and your data

OpenAI's supported countries page lists the Netherlands. The data controls page says that data sent to the API is not used to train OpenAI models unless you opt in, and that abuse monitoring logs may be kept for up to 30 days. Use made-up data while you learn; everything in this course is invented.

The steps

  1. Sign in to the API platform and check your organization.
  2. Create a project for the desk helper.
  3. Buy the smallest credit amount with auto-reload off.
  4. Set a hard monthly spend limit on the project.
  5. Create a project key with an expiry date and keep it only in your password manager.

Pick your tool below and follow the steps.

Common mistakes

  • Thinking a ChatGPT Plus subscription pays for API calls. It does not.
  • Leaving Use auto-reload on, and forgetting about it.
  • Pasting the key into a chat to ask for help with an error.
  • Following a 2024 tutorial that still uses threads and runs.

Today's actions

Ticks are not saved without an account

Do it in OpenAI API

OpenAI API

  1. Go to platform.openai.com and sign in, or sign up. Check the organization name at the top: your project and credit belong to that organization.
  2. Open the project selector and select Create project. Name it otterbrook-desk, leave Data and Inference Residency on Global if it is shown, and select Create. You need the organization owner role to create a project.
  3. Open the API billing overview in your platform settings (the Billing page of your organization) and select Add payment details. Complete the payment step.
  4. Choose the credit amount. The minimum is 5 US dollars and the default is 10. Before you confirm, turn off Use auto-reload: it is on by default and would buy more credit by itself. Then confirm the purchase.
  5. Open platform.openai.com/settings/, pick the otterbrook-desk project and select Limits. In Spend, select Edit spend limit, enter 5 as the Monthly spend limit, turn on Enforce a hard limit and select Save.
  6. Open organization settings, select the otterbrook-desk project and open API Keys. Select + Create new secret key, give it the name otterbrook-laptop, and set an expiry date and a monthly hard limit if the dialog offers them.
  7. Copy the key straight into your password manager. Keep it out of chats, emails, screenshots and code files. Lesson 2 puts it in a file that git ignores.
  8. Make a text file setup-notes.txt with the project name, the spend limit, the credit you bought and today's date. Never write the key in it.

Note: Prepaid credit expires after one year and is not refundable except in the cases the help centre lists. Neither the balance nor a hard limit stops use instantly: a small overrun is possible and a negative balance comes off your next purchase. If a step or button looks different, follow the project and spend limit help pages.

Paid planNeeds prepaid API credit. The OpenAI API is billed per use, separately from any ChatGPT plan.

Checked on 4 December 2026 · Source: OpenAI Help Center: Managing projects in the API platform (opens in a new tab)

Create a free account to save your progress. Sign in or sign up