Concepts · ai
Content
Content block types: Text, Reminder, Thinking, Image, File, ToolCall
- Working with message content blocks
- Handling thinking/reasoning output or tool calls
- Attaching documents/files to user messages
- Adding injected context to a message the reader still sees
This page gives the content block model inside Messages. Each message contains a slice of Content.
Design: sealed interface
Content is a sealed interface with an unexported content() method. External packages cannot add implementations. This gives exhaustive handling. If you match all six types, Text, Reminder, Thinking, Image, File, and ToolCall, you cover the set. New content types require an SDK release.
Use AsContent[T] for safe type assertion. It handles nil safely.
Content types
- Text — plain text content. It can carry a provider-specific
Signaturefor integrity verification, such as OpenAI or Google. - Reminder — injected text that rides inside an ordinary message.
Originnames the injector, for example"harness/claudemd:/repo/CLAUDE.md". See Injected context below. - Thinking — reasoning or chain-of-thought from models that support extended thinking. It appears only when
WithThinkingenables thinking. See Options. - Image — base64-encoded image data with MIME type. User messages and image generation results use it for images.
- File — a document or file attachment in user messages. Set exactly one of
Data(base64),URL, orFileID.MimeTypeis the IANA media type, for exampleapplication/pdfortext/plain.Filenameis optional. - ToolCall — a tool call from the model. It carries
ID,Name, andArguments. The agent loop matchesNameto a registered Tool, runs it, and feeds back aToolResultMessage.IDlinks the call to its result.- For provider-hosted server tools, such as web search and code execution, the same
ToolCallblock carries the result inline.Serveristrue,ServerTypeidentifies the canonical tool, andOutputis a*ServerToolOutput. There is no separateToolResultMessage. The provider already ran the call, and the agent skips local execution.
- For provider-hosted server tools, such as web search and code execution, the same
Injected context inside a message
A Reminder is context that the model must read and the reader must not see. A harness appends one to a tool result: the output of the tool belongs to the reader, and the rules stapled to it do not. The block persists with the message that carries it.
The message around a Reminder stays ordinary. That is the point of the block. ai.Message.Injected marks a whole message as injected, which is the right tool when nothing in it is for the reader. Neither replaces the other. See Messages.
Design: the SDK never interprets Origin. It is a string that the injector chooses and reads back later, usually to find what it already injected and avoid a second copy. Giving it structure would make the SDK the owner of a naming scheme that every harness would then fight.
Reminder has one flavor, and it persists. There is no ephemeral block. Context that is true only at this moment belongs in an ephemeral message, not in a block glued to a tool result that outlives it.
ServerToolOutput
ServerToolOutput is the result of a provider-run server tool. It attaches to its ToolCall.
Content— a normalized text form of the result. For web search, it can be a numbered list of “Title — URL” entries. For code execution, it can be concatenated stdout and stderr. Use it for screen output or prompt input.Raw— the provider’s original JSON. Callers can extract structured fields that do not fit the normalized form. Examples include citations, encrypted indices, and per-chunk confidence scores.IsError— true when the provider reported an error for the call.
File support per provider
File blocks are input-only user message blocks. Provider support varies by source variant.
| Provider | Inline Data | URL | FileID | Notes |
|---|---|---|---|---|
| Anthropic | PDF, plain text | — | Maps to document block; FileIDs are not supported. | |
| OpenAI Chat Completions | yes | — | yes | URL is dropped; use the Files API to obtain a FileID. |
| OpenAI Responses | yes | yes | yes | Maps to input_file. |
| Google Gemini | yes | yes | yes | Inline uses inlineData; URL/FileID use fileData. |
| Claude CLI | — | — | — | The CLI subprocess only forwards user text; files are skipped. |
Provider boundaries silently skip unsupported variants. Messages with mixed-support content can still flow through.
Related
- Messages — messages contain content blocks, and carry their own provenance
- Messages (agent) — why
Textreturns blocks instead of a string - Tools —
ToolCalltriggers tool execution - Options —
WithThinkingenablesThinkingcontent