Using the Completions endpoint
When you're working with the OpenAI API, most of what you'll be doing will probably involve using the Completions endpoint. This is the endpoint you send prompts to. In addition to submitting your prompt, you can also include values to influence how the completion is generated, like the setting in the Playground.
Using the Completions endpoint is a little more involved than using the List Engines endpoint that we looked at in the last section, Introducing JSON. This is because the Completions endpoint uses the HTTP POST method and requires a JSON object as the body. Technically, the JSON body could just be an empty object (just a left and right curly brace, like {})
, but minimally, you'll want to include at least the prompt
element with the value set to your prompt
string, something like the following JSON example:
{"prompt": "Once upon a time"}
The preceding example is a simple one but here's how we&apos...