Skip to content

Concepts · ai

Content

Content block types: Text, Reminder, Thinking, Image, File, ToolCall

Read this when
  • 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 Signature for integrity verification, such as OpenAI or Google.
  • Reminder — injected text that rides inside an ordinary message. Origin names 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 WithThinking enables 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, or FileID. MimeType is the IANA media type, for example application/pdf or text/plain. Filename is optional.
  • ToolCall — a tool call from the model. It carries ID, Name, and Arguments. The agent loop matches Name to a registered Tool, runs it, and feeds back a ToolResultMessage. ID links the call to its result.
    • For provider-hosted server tools, such as web search and code execution, the same ToolCall block carries the result inline. Server is true, ServerType identifies the canonical tool, and Output is a *ServerToolOutput. There is no separate ToolResultMessage. The provider already ran the call, and the agent skips local execution.

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.

ProviderInline DataURLFileIDNotes
AnthropicPDF, plain textPDFMaps to document block; FileIDs are not supported.
OpenAI Chat CompletionsyesyesURL is dropped; use the Files API to obtain a FileID.
OpenAI ResponsesyesyesyesMaps to input_file.
Google GeminiyesyesyesInline uses inlineData; URL/FileID use fileData.
Claude CLIThe CLI subprocess only forwards user text; files are skipped.

Provider boundaries silently skip unsupported variants. Messages with mixed-support content can still flow through.

  • Messages — messages contain content blocks, and carry their own provenance
  • Messages (agent) — why Text returns blocks instead of a string
  • ToolsToolCall triggers tool execution
  • OptionsWithThinking enables Thinking content