Getting Info for fetch Request

Tom Chant
InstructorTom Chant
Share this video with your friends

Social Share Links

Send Tweet
Published 8 months ago
Updated 8 months ago

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.

egghead
egghead
~ 16 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today