Skip to main content

Overview

core-ai uses a comprehensive type system to ensure type safety across all operations. This page documents the essential types for working with messages, models, configurations, and results.

Message types

Message

Union type representing all message types in a conversation.

SystemMessage

UserMessage

TextPart

ImagePart

FilePart

AudioPart

AssistantMessage

AssistantTextPart

ReasoningPart

The metadata field is application-owned and provider adapters ignore it. The providerMetadata field is provider-namespaced. The top-level key is the provider identifier (for example 'anthropic', 'google', 'openai', or 'azure-openai'). Adapters treat other providers’ keys as foreign and downgrade those reasoning blocks to plain text instead of forwarding opaque metadata. Use getProviderMetadata() for typed access.

ToolCallPart

providerMetadata follows the same provider-namespaced convention as ReasoningPart. Keep it on the part when you replay history: Gemini 3 rejects a request when a function call from the current turn comes back without its thought signature.

ToolCall

ToolResultMessage

metadata on message parts, tool calls, and tool results is for your application and middleware. It stays in conversation history and generated results, but core-ai does not send it to provider APIs.

Tool types

ToolDefinition

ToolSet

ToolChoice

Model types

ChatModel

capabilities describes how a specific model accepts unified generation options. It is different from the provider-level feature lists in the provider guides: those show which APIs a provider exposes, while ModelCapabilities describes request constraints for one model ID.

ModelCapabilities

mode: 'unsupported' means the provider does not map the unified reasoning option. The model may still return reasoning output. optional means callers can enable reasoning, while always-on means the model reasons without an option and cannot disable it. An empty supportedEfforts list means the model does not accept effort control. It does not necessarily mean the model cannot produce reasoning output. When restrictsSamplingParams is true, consult the provider guide for the exact accepted values. modalities.input / modalities.output describe chat I/O modalities. Check them with .includes(...), or with the exported helpers supportsInputModality and supportsOutputModality. Core also exports the common presets TEXT_ONLY_MODALITIES (text in / text out) and MULTIMODAL_INPUT_MODALITIES (text + image + file in / text out). Providers that support AudioPart add 'audio' to their input array. 'video' is reserved until a dedicated user content part exists. Sending image, file, or audio parts when those modalities are not in modalities.input throws an UnsupportedInputModalityError before the provider call. Unrecognized model IDs are treated as multimodal capable on purpose for image and file input (fail-open), so self-hosted endpoints and newly released models are not blocked locally for those parts. Audio remains opt-in. Typos and custom deployment names that do not match a registry key therefore include 'image' and 'file' in modalities.input and still rely on the provider to reject unsupported requests. For Azure and other wrappers, pass a known registry model ID when you need accurate capability data. modalities.output currently always includes 'text'. Dedicated image generation uses ImageModel / generateImage, not chat output. Provider packages also export get*ModelCapabilities(modelId) helpers that return the same data without constructing a ChatModel. Kimi exposes this data through ChatModel.capabilities only.

EmbeddingModel

ImageModel

Configuration types

ReasoningConfig

Provider options types

Provider-specific options are namespaced by provider name and validated with Zod schemas by each provider adapter.
Providers extend these via declaration merging to provide type-safe options:

Generation options

BaseGenerateOptions

Shared options for all generation functions.

GenerateOptions

Extends BaseGenerateOptions with tool support.

GenerateObjectOptions

StreamObjectOptions

Result types

GenerateResult

GenerateObjectResult

FinishReason

Streaming types

ChatStream

Replayable handle for a chat streaming operation. Iterating after events have arrived replays the buffered history.

StreamEvent

ObjectStream

Replayable handle for a structured object streaming operation.

ObjectStreamEvent

Usage types

ChatUsage

inputTokens is the total including cached reads and cache writes. outputTokens is the total including visible text and reasoning.

ChatInputTokenDetails

ChatOutputTokenDetails

EmbeddingUsage

Embedding types

EmbedOptions

EmbedResult

Image generation types

ImageGenerateOptions

ImageGenerateResult

GeneratedImage

Type usage examples

Building type-safe conversations

Type-safe tool handling