Making an authenticated request to the OpenAI API
It's time to make our first request directly to the OpenAI API. To do that, we'll need to include our API key as part of an HTTP header. The header name we'll be using is authorization and the value will be the word Bearer, followed by a space and then your API key. When an API key is used like this, it's often also referred to as a bearer token. This is a standard defined by an authorization protocol called OAuth 2.0. You can learn more about OAuth 2.0 by visiting https://oauth.net/2/.
Postman makes it really easy to use bearer tokens. But before we make an authenticated request, let's look at what happens if we try to make a request without our API key. The following screenshot shows a request to the List Engines endpoint URL, https://api.openai.com/v1/engines
, without any authorization header. You can see an error message was returned. You'll also notice that the HTTP response status code is 401 UNAUTHORIZED...