Getting Info for fetch Request

Tom Chant
InstructorTom Chant
Share this video with your friends

Social Share Links

Send Tweet

We take a step-by-step approach to using the OpenAI API. We start by obtaining an API key and then proceed to find the appropriate API endpoint through the OpenAI documentation. Specifically, we learn about the completions endpoint, which plays a central role in making requests to the API.

The concept of a "completion" is introduced, where we send a question or request to the API and receive a response in return. We then explore the completions endpoint section in the documentation, which provides code examples in different languages.

Finally, we save the URL for the completions endpoint in a constant and prepare to write a fetch request. This lesson provides essential knowledge for getting started with using the OpenAI API effectively.

[00:00] Now we've got our API key, we can start using the API. But before we can make our first fetch request, we need an API endpoint. Let's head back to the OpenAI website and click through to the docs. And this slide is a clickable link, of course, and it will take you straight there.

[00:17] Now the OpenAI docs are pretty comprehensive and right here on the first page, it tells us that the completions endpoint is at the center of our API. Okay, that sounds interesting. The completions endpoint. We're going to check it out, but before we do that, you might well be asking, what is a completion?

[00:36] And completion is a word used a lot in OpenAI. So let's say you want some information, like you want to know who the first person to walk on the moon was. Let's send that question to OpenAI via the API and it will think about it and send back a completion. And that completion is of course, Neil Armstrong.

[00:55] So in the world of OpenAI, a completion is a response from the API that fulfills your request. Okay, let's click through to the completions endpoint section in the docs. And here we get a ton of info and some code examples. And each example is given in Node.js, PHP and curl.

[01:15] But what I want to focus on is this. We have the completions API endpoint right here and it tells us we can use the post method. So now we've got that info, let's come back to index.js and I'm going to save it in a const called URL. And in the next scrim, let's start writing a fetch request.