messages array carries that history: what the user said and what the assistant answered before, in order. Use it to build chat experiences on top of a Canvas, or to give the model context that does not fit a variable.
messages is optional, and it works together with variables: the Canvas prompt is still rendered with the variables, and the messages are added to the conversation.
Message shape
Each message has arole and a content:
roleisuserorassistant.contentis the text of the message. It can also be a file; see Files and images in messages.
user and assistant messages.
choices[0].message.content. To continue the conversation, append the assistant answer and the next user message to the array and call again: the API does not keep the conversation between calls.
Files and images in messages
Besides a string,content accepts a file reference with a file_url, in the same formats accepted by file variables:
HTTP body
{ "type": "text", "text": "…" } or an image part { "type": "image_url", "image_url": { "url": "…", "detail": "auto" | "high" | "low" } }.
input_content.files with used_at: "messages" and a name such as message-0, where the number is the position of the message in the array.