Claude API

How do you send images to the Claude API?

QUICK ANSWER

To send an image to the Claude API, include an image content block in your messages array, passing the base64-encoded file string and declaring the correct media type.

JSON Payload Image Request

{
  "model": "claude-3-5-sonnet-20241022",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "image",
          "source": {
            "type": "base64",
            "media_type": "image/jpeg",
            "data": "/9j/4AAQSkZJRgABAQEASABIAAD..."
          }
        },
        {
          "type": "text",
          "text": "What is in this picture?"
        }
      ]
    }
  ]
}
Verified against: Anthropic API Vision Spec