GPT-3 API invalid_request_error: you must provide a model parameter
Asked Answered
S

4

17

I'm new to APIs and I'm trying to understand how to get a response from a prompt using OpenAI's GPT-3 API (using api.openai.com/v1/completions). I'm using Postman to do so. The documentation says that there is only one required parameter, which is the "model." However, I get an error saying that "you must provide a model parameter," even though I already provided it.

What am I doing wrong?

API error screenshot

Spica answered 21/9, 2022 at 8:49 Comment(2)
Having the same issue—did the solution below resolve your issue? I tried it, still having the same problem.Nuncle
DOH— POST, not GET. All good now!Nuncle
S
19

You can get this to work the following way in Postman with the POST setting:

  1. Leave all items in the Params tab empty

  2. In the Authorization tab, paste your OpenAI API token as the Type Bearer Token (as you likely already did)

  3. In the Headers tab, add key "Content-Type" with value "application/json"

  4. In the Body tab, switch to Raw, and add e.g.

     {  
         "model":"text-davinci-002",
         "prompt":"Albert Einstein was"
     }
    
  5. Hit Send. You'll get back the completions for your prompt.

Note alternatively, you can add the model into the Post URL, like https://api.openai.com/v1/engines/text-davinci-002/completions

While above works, it might not be using the Postman UI to its full potential -- after all, we're raw-editing JSON instead of utilizing nice key-value input boxes. If you find out how to do the latter, let us know.

enter image description here

Stele answered 26/9, 2022 at 11:6 Comment(2)
here length is fixed, can you tell me how to do?Neighbor
https://api.openai.com/v1/engines/ end-points are deprecated.Ashton
L
9

What solved it for me was adding the content-type header: "content-type:application/json"

postman-headers

Lauretta answered 26/1, 2023 at 22:16 Comment(0)
O
2

You need to pay attention to the request type of the interface. If POST uses GET to request, this error will also be reported.

Overmatch answered 11/5, 2023 at 8:16 Comment(1)
Thanks for the answer, yeah, this is the issue I got, the error message just confused me, it could simply to be a message like The GET method is not supportedAncelin
B
0

from

    response = openai.Completion.create(
    engine="text-davinci-003",
    prompt=prompt,
    max_tokens=100,
    n=1,
    stop=None,
    temperature=0.3,
    presence_penalty=2
    )
    answer = response.choices[0].text.strip()

to

    messages=dict(role="user", content=prompt)
    response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=[messages],
    max_tokens=100,
    n=1,
    stop=None,
    temperature=0.3,
    presence_penalty=2
    )
    answer = response['choices'][0]['message']['content']
Baram answered 3/3, 2023 at 9:31 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Ouzel

© 2022 - 2024 — McMap. All rights reserved.