Basic request and response
JSON
Multiple conversational turns
The Messages API is stateless, which means that you always send the full conversational history to the API. You can use this pattern to build up a conversation over time. Earlier conversational turns don’t necessarily need to actually originate from Claude — you can use syntheticassistant
messages.
JSON
Putting words in Claude’s mouth
You can pre-fill part of Claude’s response in the last position of the input messages list. This can be used to shape Claude’s response. The example below uses"max_tokens": 1
to get a single multiple choice answer from Claude.
JSON
Vision
Claude can read both text and images in requests. We support bothbase64
and url
source types for images, and the image/jpeg
, image/png
, image/gif
, and image/webp
media types. See our vision guide for more details.
JSON