Get Started with the OpenAI API
Learn how to sign up for an OpenAI account and retrieve the API key of the OpenAI API.
We'll cover the following
We need to complete a few steps before we can start using the OpenAI API.
Sign up
Visit the registration link and perform the following steps:
- Enter a valid “Email address” and click “Continue.” It will take you to the next page, where you create a “Password” and click the “Continue” button.
- You will receive a verification email in your provided email address inbox. Open the received email and click the “Verify email address” link. It will open a new tab.
- In the new tab, fill in the details under the heading “Tell us about you” and click “Continue.”
- Next, enter a valid “phone number” and click “Send code.”
- You will then receive a code on the “Phone number” given in the previous step. Enter the 6-digit code that you receive. Once that has been verified, you’ll be directed to the next page.
- Lastly, choose your use case.
You’ll be redirected to the welcome page once the account is created.
Fetch the API Key
- Visit this page and click your profile at the top right corner. From the drop-down menu, select the “Manage account” option. It will open a new page.
- In the new page, we can see the usage history of the API. Now, click on “API Keys” from the sidebar.
- You’ll see your secret key under the “SECRET KEY” section. Copy it and paste it into the widget below. If you wish to make a new key, you can do it by selecting the “Create new secret key” button.
Save the API Key
Let’s save the API Key to use throughout the course.
Follow the instructions below:
- Click the “Edit” button in the following widget.
- Enter your secret key in the
SECRET_KEY
field. - Click the “Save” button.
Once the SECRET_KEY
is saved, it can be used throughout the course. In order to verify that the provided API key is valid, press the “Run” button for the widget below. You should see a list of available engines if your key is valid, and an appropriate error message otherwise.
// Endpoint URLconst endpointUrl = "https://api.openai.com/v1/models";// Header Parametersconst headerParameters = {"Authorization": "Bearer {{SECRET_KEY}}"};// Setting API call optionsconst options = {method: "GET",headers: headerParameters};// Function to make API callasync function getModels() {try {const response = await fetch(endpointUrl, options);// Printing responseprintResponse(response);} catch (error) {// Printing error messageprintError(error);}}// Calling function to make API callgetModels();