Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

OpenAI API 400: image_url is only supported by certain models

ErrorBadRequestError: 400 Invalid content type. image_url is only supported by certain models.

Short answer

The request carried an image part, but the model you named cannot take image input. Switch to a model from OpenAI's vision guide, such as gpt-4o or gpt-4.1. Also check the content part type: Chat Completions uses image_url, while the Responses API uses input_image.

  • Applies to openai Node.js SDK (current release), Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Print the model name and the types of the content parts that go in the request. The error is about that combination.

    console.log(model);
    console.log(messages.map((m) => Array.isArray(m.content) ? m.content.map((p) => p.type) : typeof m.content));
  2. 2Match what you see, then jump to its fix

    1. 1400 on every request that contains an image_url part, while the same call without the image worksThe model does not accept imagesFix
    2. 2Code was copied from a Responses API example into chat.completions.create, or the other way roundThe content part type does not match the API you callFix

What does the error look like?

  • BadRequestError: 400 Invalid content type. image_url is only supported by certain models.

Cause 1 of 2

The model does not accept images

1Check

OpenAI's image guide lists the general-purpose models that take image input, for example gpt-4o, gpt-4o-mini and gpt-4.1. A model that is not on that list, or an old text-only name still left in your config, rejects the image.

grep -rn "model:" src/ .env* 2>/dev/null

2Fix

Set the model to one from the vision guide's list.

const completion = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [
    {
      role: "user",
      content: [
        { type: "text", text: "What is in this image?" },
        { type: "image_url", image_url: { url: "https://example.com/photo.jpg" } },
      ],
    },
  ],
});

3Verify

Send the same request and read the first choice.

console.log(completion.choices[0].message.content);

Confirmed by developers.openai.com

Did this fix it?

Cause 2 of 2

The content part type does not match the API you call

1Check

In the Chat Completions reference a user message part of type image_url carries an image_url object with a url (a link or base64 data) and an optional detail. The vision guide's Responses API example uses an input_image item next to input_text instead.

grep -rn -e "input_image" -e "image_url" src/

2Fix

Use image_url with chat.completions, or input_image with responses, and match the text part type as well.

const response = await client.responses.create({
  model: "gpt-4o",
  input: [
    {
      role: "user",
      content: [
        { type: "input_text", text: "What is in this image?" },
        { type: "input_image", image_url: "https://example.com/photo.jpg", detail: "auto" },
      ],
    },
  ],
});

3Verify

Run the request and print the output text.

console.log(response.output_text);

Confirmed by developers.openai.com

Did this fix it?

How do I stop it coming back?

  • Keep the model name in one config value and check it against the vision guide when you change it.
  • Write one helper that builds the image part, so the part type lives in a single place.
  • Stay within the documented image formats (PNG, JPEG, WEBP, non-animated GIF) and size limits.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

AI

The model's reply breaks JSON.parse

SyntaxError: Unterminated string in JSON at position 1874

JSON.parse rejects model output for a few repeatable reasons: the JSON sits inside markdown fences or next to a sentence, the reply stopped at the token limit mid-object, a stream was parsed before it ended, or the model refused.

5 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.