Example from Vision API returns

Hey there,
Trying to run an example from the Vision API and getting 400 with “server_error” in the response.
I checked the OpenAI status page, everything is green including the API.

Looks like nobody has reported it so maybe I am doing something wrong? :thinking:

I tried to run a request to gpt-4-vision-preview with text only without specifying an image, and it does return a valid response with generated text.

Here’s the CURL command that fails (see the response below):

curl https://api.openai.com/v1/chat/completions \
  -D - \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $myAPIKey \
  -d '{
    "model": "gpt-4-vision-preview",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What’s in this image?"
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg"
            }
          }
        ]
      }
    ],
    "max_tokens": 300
  }'

Response:

HTTP/2 400
{
  "error": {
    "message": "",
    "type": "server_error",
    "param": null,
    "code": null
  }
}

It’s missing the closing "

remove this line from your code

yeah I accidentally removed it when stripping out my API key.
The curl command goes through w/o error and I do get a response from the server.

1 Like

Sure, I added it to see the header with the HTTP error.
W/o this line, I still get the same response from the server:

 % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   640  100   103  100   537    307   1602 --:--:-- --:--:-- --:--:--  1916{
  "error": {
    "message": "",
    "type": "server_error",
    "param": null,
    "code": null
  }
}

Does the call work for you?

Yes, it will work for me. base on the server_error, it might be because in certain locations, OpenAI’s servers are not available, which is why you are getting this error. (not sure) Do you have a balance on your account? Do other services, like the chat completions API, work for you?

Thanks for your suggestions, Kevin!
I do have balance on my account (it refuses to do anything w/o it).
I sent a pure text call to gpt-4-vision-preview and it gave a valid response (see below). So, the model is available to me.
I searched the forum for the related topics and it looks like the majority sends images as base64 and not URL. Maybe I should try that…

Call:

 curl https://api.openai.com/v1/chat/completions   -H "Content-Type: application/json"   -H "Authorization: Bearer $APIKey"   -d '{
    "model": "gpt-4-vision-preview",
    "messages": [
      {
        "role": "system",
        "content": "You are a poetic assistant, skilled in explaining complex programming concepts with creative flair."
      },
      {
        "role": "user",
        "content": "Compose a poem that explains the concept of recursion in programming."
      }
    ]
  }'

Resposne:

% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1939  100  1578  100   361     99     22  0:00:16  0:00:15  0:00:01   352{
  "id": "chatcmpl-97P6lgei32JXzR5SJLepUjWulGkSC",
  "object": "chat.completion",
  "created": 1711551839,
  "model": "gpt-4-1106-vision-preview",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "In the land of code, there's a curious notion,\nWhere a function, quite boldly, sets itself in motion.\nIt calls upon itself in a repetitive fashion,\nA process that's filled with recursive passion.\n\nRecursion, recursion, a magical loop,\nWhere the end of the story's in its very own group.\nIt's like a strange loop in a hall of mirrors,\nReflecting forever, in programming frontiers.\n\nImagine a puzzle, one piece inside another,\nNested and nestled, like a child and its mother.\nEach piece is a call, a beckoning stride,\nTo solve the great riddle that lies deep inside.\n\nThe base case arrives, the anchor, the key,\nTo halt the recursion, set the function free.\nFor without this clause, it would run amiss,\nAn infinite loop, computing's abyss.\n\nIt's a principle used in algorithms grand,\nFrom sorting to searches, across data land.\nDivide and conquer, the mantra it sings,\nSolving problems in steps, the elegance it brings.\n\nSo marvel at recursion, a concept so neat,\nWhere the lines of code can so sweetly repeat.\nA powerful tool in a programmer's creation,\nComplexity born from simple iteration."
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 39,
    "completion_tokens": 243,
    "total_tokens": 282
  },
  "system_fingerprint": null
}

The exact image url will work for me. Try to change the model name to this one that you get answer, gpt-4-1106-vision-preview, Otherwise send message to OpenAI support.

1 Like

Looks like their example is not working for some reason (maybe Wikimedia blocked them? :thinking:). If I run the request with my data, it works like a charm :joy::rofl:
thanks everyone!

1 Like