简体   繁体   中英

What's the correct URL to test chatGPT API?

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).

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM