KhueApps
Home/AI Engineering/How to create a new OpenAI API key

How to create a new OpenAI API key

Last updated: January 25, 2025

OpenAI's API offers a powerful way to integrate advanced AI features into your applications. To start using the API, you’ll need an API key. This article provides a step-by-step guide to creating a new OpenAI API key.

Step 1: Log in to OpenAI

  1. Visit OpenAI’s platform website.
  2. Log in using your account credentials. If you don’t have an account yet, you’ll need to create one by signing up.

Step 2: Navigate to API Keys

  1. Once logged in, click on the Settings icon (the gear) in the top-right corner of the screen. Next, look at the left sidebar and select "API Keys" from the list. This will take you to the API key management page:
     

Step 3: Create a New Key

  1. On the API Keys page, look for the button labeled "Create new secret key" and click it.
     

     

  2. A popup will be displayed. Give your API key a name and select a project for it (if you haven't created any project, just choose “Default project”):
     


    Hit the “Create secret key” button to continue.

Step 4: Copy and Save the Key

  • Important: Copy the generated API key immediately. For security reasons, OpenAI does not store or display the key again after this point.
  • Store the key securely in a password manager or another safe location. If you do lose it, you'll need to generate a new one.

Step 5: Use Your API Key

Use your API key to authenticate requests to OpenAI’s API. Typically, you’ll include it in the Authorization header of your HTTP requests:

Authorization: Bearer YOUR_API_KEY

Here’s an example in Python using the openai library:

import openai

openai.api_key = "YOUR_API_KEY"

response = openai.Completion.create(
    engine="text-davinci-003",
    prompt="Hello, OpenAI!",
    max_tokens=5
)
print(response)

Additional Tips

  • Rotate Keys Regularly: If you’re working in a team or concerned about security, consider rotating your API keys periodically.
  • Manage Permissions: Depending on your account type, you can configure which services or applications have access to your API key.
  • Monitor Usage: Keep track of your API usage through the OpenAI dashboard to ensure efficient use and avoid unexpected charges.

Creating a new OpenAI API key is a quick and straightforward process, but it’s crucial to handle your key with care to maintain security. By following the steps above, you can generate an API key and begin integrating OpenAI’s capabilities into your applications. 

Next Article: Making Async API Calls with OpenAI Chat Completion API (Python)

Series: OpenAI API

AI Engineering