Getting Your OpenAI API Key in Three Easy Steps

Starting your OpenAI journey? Here’s a step-by-step guide to setting up your account, getting your API key and setting limits to your API usage.

Do you want to know how to get your OpenAI API Key? Yes, then this article is for you. Many developers want to start developing GPT-powered apps. But first, they need an API Key to get access to OpenAI’s advanced language models, such as GPT-3 or GPT-4. With this key, you can integrate LLM functionalities (code writing, translation and much more) into your apps, and that makes your apps smarter.

In this tutorial, we’ll guide you through three steps to get and manage your OpenAI API key. In addition, we’ll show you how to use this key in your apps.

We’ve no time to waste. Let’s start!


🎓 Our Online Courses and recommendations

Our Online Courses and recommendations


Benefits of an OpenAI API Key

You’re probably asking yourself what are the advantages of an API key. Here’s a list of four benefits:

  1. Up-to-date and advanced models: You have access to OpenAI’s latest and most advanced models. With these models, you can perform complex natural language tasks.

  2. Easy Integration: You can easily integrate the OpenAI API into your existing applications. For that, you can use frameworks like LangChain or LlamaIndex. The integration of the API makes your apps more intelligent and interactive.

  3. High Scalability: The API can handle large amounts of data, which makes it interesting for many companies.

  4. High Efficiency: You don’t have to train the models from scratch, which is costly and time-consuming. You can use the models directly via the API. That makes them cost, resource and time efficient in usage.

OpenAI’s API speeds up the development of new AI applications enormously, as you don’t have to worry about creating and deploying the models.

Obtaining and using your OpenAI API Key

#1 Create an OpenAI Account

First, you need to create an OpenAI account, if you don’t already have an account. Visit the OpenAI website and click the “Sign Up” button. Enter your details and create your account.

Next, you have to check your emails for a verification link. Click on it and confirm your OpenAI account. Then log in to the OpenAI website with your login details. After that, you see a page where you have to click on “API”.

Great, now you can see the OpenAI welcome page! You have successfully set up your OpenAI account.

#2 Setting up your API Key

Once you are on the main OpenAI website, you have to click on your account logo. Then, click on “View API keys”.

OpenAI API website (Image by authors)

OpenAI API website (Image by authors)

Now, you should see the API keys page. On this page, you click on “Create new secret key”.

OpenAI API website — API keys (Image by authors)

OpenAI API website — API keys (Image by authors)

Give the API key a name of your choice and click “Create secret key”.

OpenAI API website — Naming of the API key (Image by authors)

OpenAI API website — Naming of the API key (Image by authors)

The API name doesn’t matter. The name is only for you so that you know what you are using the key for.

Next, copy the key! You get free credit for API access. Save your key in a safe place because it will not display again. Later, you will need the API key to authenticate your applications with OpenAI.

You don’t necessarily have to enter a payment method. First, you can use your free credit. However, there may be rate limits. To avoid this, it is best to deposit a payment method. For that, navigate to the “Billing” page.

OpenAI API website — Go to Billing. (Image by authors)

OpenAI API website — Go to Billing. (Image by authors)

Then, you should see the option “Set up paid account”. Click on it!

OpenAI API website — Billing Overview (Image by authors)

OpenAI API website — Billing Overview (Image by authors)

Then, select whether you are an individual or an organization. Next, enter your credit card and billing details, then click “Set up payment method”.

You probably ask yourself how you can manage your usage. No worries, we show you these steps here as well.

The first thing you should do is limit the usage of the OpenAI API so that you don’t have any problems with expenses. To do this, go to the “Usage limits” section.

OpenAI API website — Go to Usage limits (Image by authors)

OpenAI API website — Go to Usage limits (Image by authors)

And then choose the limits you prefer.

OpenAI API website — Usage limits (Image by authors)

OpenAI API website — Usage limits (Image by authors)

The API is blocked when you reach the hard limit. You, therefore, pay at most the price that you enter in the hard limit item. So there are no nasty surprises!

Next, we’ll look at how you can use the API key in your apps and track your API usage.

#3 Use of the API Key

Now we have everything set up for the API. Let’s look at how to use the API key in your apps.

Set the API Key as an environment:

You can set your API key as an environment variable. In the following, you can see how you can do this:

# macOS and linux
$ export OPENAI_API_KEY=[Insert your API Key here.]

# windows
$ set OPENAI_API_KEY=[Insert your API Key here.]

Insert your API key at the marked point and delete the square brackets as well. Next, you can use frameworks like LangChain or LlamaIndex to build your own GPT-powered apps.

Great, but you probably want to know how to track the API usage of your apps.

Tracking API Usage:

As a final step, we show you how to track the API usage. For this, you need to go to the “Usage” section. There you can see your costs for every day.

OpenAI API website — Usage (Image by authors)

OpenAI API website — Usage (Image by authors)

Great, that’s it! Now, it’s your turn. Use the API and create amazing apps. Feel free to share your projects in the comments with us. If you need further help, we’re happy to help you.


👉🏽 Join our free weekly Magic AI newsletter for the latest AI updates!

👉🏽 Elevate your Python and ML skills with our top course recommendations!

Did you enjoy our content and find it helpful? If so, be sure to check out our premium offer! Don't forget to follow us on X. 🙏🏽🙏🏽

Thanks so much for reading. Have a great day!