Obtaining an API key of GPT-3 is not a complicated process. We have to perform a few simple steps given below:
Open your internet browser, type openai.com in the browser’s address bar, and press “Enter.” We’ll see the following website. Click the "Log in" button at the top right corner.
We’ll see a Window containing the Sign-up form. Enter the email address for your OpenAI API. We can also sign up with our Google or Microsoft account or Apple ID.
Next, a pop “tell us about you” will appear. You have to enter your name and organization here.
Next, enter your phone number and verify your phone number.
We’ll see the following window on the screen. Click Personal
button at the top right corner and then click view API keys
.
Here, we’ll find the API key we need. Just click the + Create new secret key
button and create a new key.
Upon selecting the + Create new secret key
button, we will be directed to a new window. We can input the secret key’s name in this window, though it is not mandatory, and then click the Create secret key
button.
Upon selecting the Create secret key
button, a fresh secret key is generated. We can then obtain the key by clicking the copy
button and subsequently pressing done
.
Now, utilize this secret key in the necessary locations. This concludes the entire procedure for acquiring an API secret key, and we appreciate your attention.
Please add your API key in the api_key field. Click the "Run" button to test whether the API key is valid.
import requestsimport jsonimport osapi_key = os.environ["api_key"]headers = {"Authorization": f"Bearer {api_key}","Content-Type": "application/json"}# Assuming the updated endpoint expects a list of messagesdata = {"model": "gpt-3.5-turbo","messages": [{"role": "system", "content": "You are a helpful assistant."},{"role": "user", "content": "This is a test."}]}response = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, data=json.dumps(data))if response.status_code == 200:print("API Key is valid. Response received successfully.")else:print(f"Failed to validate API Key: HTTP {response.status_code} - {response.text}")