Skip to content
providerkit
GitHub

ChatMessage

type ChatMessage =
| {
content: string;
role: "system";
}
| {
content: | string
| ContentPart[];
role: "user";
}
| {
citations?: Citation[];
content: string;
hostedCalls?: HostedCall[];
hostedItems?: HostedItems;
reasoning?: string;
reasoningDetails?: unknown[];
reasoningItems?: ReasoningItems;
role: "assistant";
toolCalls?: ToolCall[];
}
| {
content: string;
images?: ImagePart[];
name: string;
role: "tool";
toolCallId: string;
};

Defined in: core/src/types.ts:98

{
content: string;
role: "system";
}

{
content: | string
| ContentPart[];
role: "user";
}

{
citations?: Citation[];
content: string;
hostedCalls?: HostedCall[];
hostedItems?: HostedItems;
reasoning?: string;
reasoningDetails?: unknown[];
reasoningItems?: ReasoningItems;
role: "assistant";
toolCalls?: ToolCall[];
}
optional citations?: Citation[];

The sources the answer cites, with spans into content.

content: string;
optional hostedCalls?: HostedCall[];

What the vendor’s own tools did in this turn (a search, a fetch, a code run), in the order they ran. Never function calls: nothing here is run by the loop or answered with a tool message. Display data, with the sensitivity of content.

optional hostedItems?: HostedItems;

The vendor’s own record of its hosted tools, replayed only to the provider that made it. Provider-owned like reasoningItems: never echo it to a browser. See HostedItems.

optional reasoning?: string;

The model’s chain-of-thought. Thinking-mode providers require it replayed on a turn that made a tool call (DeepSeek 400s without it). OpenAI-shape serializes it as reasoning_content; Anthropic-shape drops it, since its thinking blocks carry signatures we never capture.

A turn that disables thinking must not carry it. Mixing the two is unsupported. stripReasoning below is that rule, once.

optional reasoningDetails?: unknown[];

OpenRouter’s normalized reasoning payload, arriving on the stream and riding back UNMODIFIED on the next turn’s assistant message.

Opaque on purpose, with the same contract as Gemini’s thoughtSignature, and for the same reason: it is the provider’s own record of how it got here, and reading, reshaping or dropping it costs the model its continuity across a tool round. Absent on every other dialect.

optional reasoningItems?: ReasoningItems;

The ChatGPT backend’s own reasoning items, encrypted, riding back UNMODIFIED on the next turn so the model keeps its chain of thought. Tagged with the provider that made them: only that provider replays them, because another vendor (after a fallback) would reject them. Opaque, like reasoningDetails.

role: "assistant";
optional toolCalls?: ToolCall[];

{
content: string;
images?: ImagePart[];
name: string;
role: "tool";
toolCallId: string;
}
content: string;
optional images?: ImagePart[];

Images a tool hands back (a screenshot, a rendered chart).

name: string;
role: "tool";
toolCallId: string;