Home > front end >  What's the correct URL to test OpenAI API?
What's the correct URL to test OpenAI API?

Time:01-25

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

CodePudding user response:

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.

  • Related