Skip to content

AnthropicContentBlock

AnthropicContentBlock = { text: string; type: "text"; } | { source: { type: "url"; url: string; } | { data: string; media_type: string; type: "base64"; }; type: "image"; } | { id: string; input: Record<string, unknown>; name: string; type: "tool_use"; }

Defined in: adapters/anthropic.ts:72

Anthropic content block type supporting text, images, and tool usage.

Claude uses a structured content block format where each piece of content is represented as an object with a discriminated type field. This enables multimodal messages mixing text, images, and tool interactions.

// Text block
const text: AnthropicContentBlock = {
type: 'text',
text: 'Hello, Claude!'
};
// Image from URL
const imageUrl: AnthropicContentBlock = {
type: 'image',
source: {
type: 'url',
url: 'https://example.com/photo.jpg'
}
};
// Base64 image
const imageB64: AnthropicContentBlock = {
type: 'image',
source: {
type: 'base64',
media_type: 'image/jpeg',
data: '/9j/4AAQSkZJRg...'
}
};
// Tool use request
const toolUse: AnthropicContentBlock = {
type: 'tool_use',
id: 'toolu_123',
name: 'get_weather',
input: { location: 'San Francisco' }
};