You can include images directly in your chat conversations with Palmyra X5 using mixed content support. This allows you to send both text and images in the same message, enabling rich visual conversations with Palmyra X5.
Image analysis in chat completions is only supported with the Palmyra X5 model. Other models don’t support the image_url content type.
You need an API key to access the Writer API. Get an API key by following the steps in the API quickstart.We recommend setting the API key as an environment variable in a .env file with the name WRITER_API_KEY.

Overview

Mixed content support allows you to send messages that contain both text and images in a chat with Palmyra X5. Instead of using the separate Vision tool, you can now include images directly in your chat messages, making conversations more natural and contextual.

How it works

When sending a message to the chat completion endpoint, you can use the content field in two ways:
  1. Text-only message:
    "messages": [
        {
            "role": "user",
            "content": "Hello, how are you?"
        }
    ]
  1. Mixed content message:
    "messages": [
        {
            "role": "user",
            "content": [{"type": "text", "text": "What do you see in this image?"}, {"type": "image_url", "image_url": {"url": "https://example.com/image.jpg"}}]
        }
    ]

Endpoint

URL: POST https://api.writer.com/v1/chat

Content fragment types

Text fragment

{
  "type": "text",
  "text": "Your text content here"
}

Image fragment

{
  "type": "image_url",
  "image_url": {
    "url": "https://example.com/image.jpg"
  }
}

Examples

Single image analysis

This example shows how to send a message with a single image. The content field is an array of content fragments, where each fragment can be either text or image. The text fragment includes the message for the model to analyze. The image fragment includes the image URL.
curl --location 'https://api.writer.com/v1/chat' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $WRITER_API_KEY" \
--data '{
  "model": "palmyra-x5",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What do you see in this image?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.jpg"
          }
        }
      ]
    }
  ]
}'

Using local images with data URLs

You can also use data URLs to send local images without uploading them to a remote server. This is useful for testing or when working with local files:
# Convert local image to base64 data URL
base64_image=$(base64 -i local_image.jpg)
data_url="data:image/jpeg;base64,$base64_image"

curl --location 'https://api.writer.com/v1/chat' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $WRITER_API_KEY" \
--data "{
  \"model\": \"palmyra-x5\",
  \"messages\": [
    {
      \"role\": \"user\",
      \"content\": [
        {
          \"type\": \"text\",
          \"text\": \"Analyze this local image:\"
        },
        {
          \"type\": \"image_url\",
          \"image_url\": {
            \"url\": \"$data_url\"
          }
        }
      ]
    }
  ]
}"

Multiple images with text

You can include multiple images in a single message:
curl --location 'https://api.writer.com/v1/chat' \
--header 'Content-Type: application/json' \
--header "Authorization: Bearer $WRITER_API_KEY" \
--data '{
  "model": "palmyra-x5",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "Compare these two images and tell me the differences:"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/before.jpg"
          }
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/after.jpg"
          }
        }
      ]
    }
  ]
}'

Next steps