
#  Your first API request!

```
Exercise ID 1559472
```

##  Assignment 

Throughout the course, you'll write Python code to interact with the OpenAI API. As a first step, you'll need to create your own API key. **API keys used in this course's exercises will not be stored in any way.**

To create a key, you'll first need to create an OpenAI account by visiting their [signup page](https://platform.openai.com/signup). Next, navigate to the [API keys page](https://platform.openai.com/account/api-keys) to create your secret key.

<img src="https://assets.datacamp.com/production/repositories/6309/datasets/842da12a5b68c9f3240978dcfb08726b57ee2a18/api-key-page.png" alt="The button to create a new secret key." width="100%">

OpenAI sometimes provides free credits for the API, but this can differ depending on geography. You may also need to add debit/credit card details. **You'll need less than $1 credit to complete this course.**

**Warning**: if you send many requests or use lots of tokens in a short period, you may see an `openai.error.RateLimitError`. If you see this error, please wait a minute for your quota to reset and you should be able to begin sending more requests. Please see [OpenAI's rate limit error support article](https://help.openai.com/en/articles/6897202-ratelimiterror) for more information.

##  Instructions 

- Import the `openai` library.
- Create your API key and assign it to `openai.api_key`.
- Create a request to the Completion endpoint.
- Specify that the request should use the `gpt-3.5-turbo-instruct` model.



```
# Import openai
____

# Set your API key
openai.api_key = "____"

# Create a request to the Completion endpoint
response = openai.____.____(
  # Specify the correct model
  model="____",
  prompt="Who developed ChatGPT?"
)

print(response)
```

##  Hints 

- To create a request to the Completion endpoint using the `openai` package, use the `Completion.create()` function.



##  Solution 

```
# Import openai
import openai

# Set your API key
openai.api_key = "<OPENAI_API_TOKEN>"

# Create a request to the Completion endpoint
response = openai.Completion.create(
  # Specify the correct model
  model="gpt-3.5-turbo-instruct",
  prompt="Who developed ChatGPT?"
)

print(response)
```


