Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

Chunks

Distinguish incremental content chunks from complete content blocks.

developer

content.Chunk is the sealed in-memory vocabulary for incremental output. Chunks are not serialized by core and do not have a wire tag; a provider stream decoder creates them from frames.

API surface

type Chunk interface{ isChunk() }

type TextChunk struct{ Text string }

type ThinkingChunk struct {
	Thinking  string
	Signature string
}

type ToolUseChunk struct {
	Index     int
	ID        string
	Name      string
	InputJSON string
}
VariantDelta semantics
TextChunkAppend Text to the answer buffer
ThinkingChunkAppend Thinking; retain a non-empty terminal Signature
ToolUseChunkAccumulate InputJSON by Index; ID and name may arrive later
switch typed := chunk.(type) {
case *content.TextChunk:
	answer.WriteString(typed.Text)
case *content.ThinkingChunk:
	reasoning.WriteString(typed.Thinking)
case *content.ToolUseChunk:
	toolParts.Add(typed)
}

Complete blocks have different ownership and fields. Use streamaccumulator to fold chunks into TextBlock, ThinkingBlock, and ToolUseBlock values.

Proof

Related: Text deltas, Thinking deltas, Tool-call deltas.

← back to documentation