-1

I'm trying to test the GPT-3 API with a request using curl in Windows CMD:

curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer MY_KEY" -d "{\"text\": \"is this working\"}" https://api.openai.com/v1/conversations/text-davinci-003/messages

Given that I did change "MY_KEY" for my key.

But I got:

{
  "error": {
    "message": "Invalid URL (POST /v1/conversations/text-davinci-003/messages)",
    "type": "invalid_request_error",
    "param": null,
    "code": null
  }
}

I also tried the model name as text-davinci-002 and text-davinci-001, but get the same invalid URL error. What's the correct URL here? I can't find it on the docs (or in chatGPT itself).

Rubén
  • 34,714
  • 9
  • 70
  • 166
The Student
  • 27,520
  • 68
  • 161
  • 264

2 Answers2

8

Sending a POST request to /v1/conversations/text-davinci-003/messages will not return the result you want, because this URL is not used by the OpenAI API.

Here's an example of a cURL request which completes the message Say this is a test

curl https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"model": "text-davinci-003", "prompt": "Say this is a test", "temperature": 0, "max_tokens": 7}'

And this is an example of what the API will respond with:

{
    "id": "cmpl-GERzeJQ4lvqPk8SkZu4XMIuR",
    "object": "text_completion",
    "created": 1586839808,
    "model": "text-davinci:003",
    "choices": [
        {
            "text": "This is indeed a test",
            "index": 0,
            "logprobs": null,
            "finish_reason": "length"
        }
    ],
    "usage": {
        "prompt_tokens": 5,
        "completion_tokens": 7,
        "total_tokens": 12
    }
}

This is the full list of API paths:

Instead, you can use the URLs listed in the OpenAI documentation:

  • List models

    GET https://api.openai.com/v1/models
  • Retrieve model

    GET https://api.openai.com/v1/models/{model}
  • Create completion

    POST https://api.openai.com/v1/completions
  • Create edit

    POST https://api.openai.com/v1/edits
  • Create image

    POST https://api.openai.com/v1/images/generations
  • Create image edit

    POST https://api.openai.com/v1/images/edits
  • Create image variation

    POST https://api.openai.com/v1/images/variations
  • Create embeddings

    POST https://api.openai.com/v1/embeddings

More found in the OpenAI documentation.

joeymalvinni
  • 343
  • 9
0

An example request for Chat Completions in case it helps anyone else (note you can adjust the model to different model names:

curl -XPOST -H 'Authorization: Bearer sk-YOUR-API-KEY' -H "Content-type: application/json" -d '{
  "model": "gpt-3.5-turbo",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant."
    },
    {
      "role": "user",
      "content": "Who won the world series in 2020?"
    },
    {
      "role": "assistant",
      "content": "The Los Angeles Dodgers won the World Series in 2020."
    },
    {
      "role": "user",
      "content": "Where was it played?"
    }
  ]
}' 'https://api.openai.com/v1/chat/completions'
Chris Klingler
  • 5,258
  • 2
  • 37
  • 43