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, you would be given a test to verify that the user is not a bot, click “Begin puzzle.”
You will be forwarded to a test, which. Go through these challenges and click “Submit.”
Alternatively, you can also sign up using your Google, Microsoft, or Apple accounts.
You’ll be redirected to the welcome page once the account is created.
API Key
An API key (Application programming interface key) is a unique identifier and authentication mechanism. It is a code that is used to connect with the API and utilize its services. Using this code, the API authenticates the user and tracks the usage of the API services.
We need an API key to use the OpenAI API. Therefore, before we can proceed, let’s generate and fetch the API key for OpenAI.
Fetch the API Key
Visit this page and move your cursor to the left side of the screen. This would open the sidebar.
From the sidebar, click “API keys.”
This new page is the API key dashboard. However, before we can generate the API key, we need to verify our phone number. Click “Start verification.”
A pop-up window will appear. On this window, select the country by clicking the flag icon and enter your phone number.
Next, you would be given a test to verify that the user is not a bot, click “Begin puzzle.”
After completing the verification challenges and clicking “Submit,” a text will be sent to your number.
Enter the code received on your phone in the “Enter code” pop-up window.
Click “Continue” on the “A note on credits” pop-up window.
Enter a name for your API key on the “Create new secret key” pop-up window and click “Create secret key.”
You’ll see your secret key under the “Save your key” pop-up window. Copy it and paste it into the widget below and click “Done.”
Note: If you wish to make a new key, you can do it by selecting the “Create new secret key” button.
Note: Please be reminded that in order to access the free quota, it is necessary to create a new account for the first time. Attempts to utilize existing accounts or create additional ones may result in encountering a “rate limit exceeded” message. Additionally, if we create a new account with a phone number that is already associated with an existing account, we will not receive additional free API credits.
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.
from openai import OpenAIclient = OpenAI(api_key="{{SECRET_KEY}}")response = client.chat.completions.create(model="gpt-3.5-turbo-0125",messages=[{"role": "system", "content": "You are a helpful assistant designed to output JSON."},{"role": "user", "content": "list all the OpenAI models available."}],temperature = 0.9)print(response.choices[0].message.content)