Overview
core-ai exports helpers for schema conversion, assistant message construction, stream creation, model middleware wrapping, reasoning effort clamping, and provider-specific metadata access.zodSchemaToJsonSchema()
Convert a Zod schema to JSON Schema using Zod 4’s native conversion APIs.clampReasoningEffort()
Clamp a requested reasoning effort to the nearest value in a model’s supported effort list.ChatModel.capabilities or a provider get*ModelCapabilities helper before calling generate / stream.
resultToMessage()
Convert aGenerateResult into an AssistantMessage so you can continue a conversation with the assistant’s full response parts.
Options
includeReasoning: false if you want to drop reasoning parts when reusing the message.
assistantMessage()
Create a simple assistant message from plain text.getProviderMetadata()
Read provider-specific metadata from reasoning parts in a type-safe way.'anthropic', 'google', or 'openai'.
createChatStream()
Create aChatStream from an async iterable of StreamEvents. This is useful when building custom providers or testing.
source parameter accepts an AsyncIterable<StreamEvent> or a () => Promise<AsyncIterable<StreamEvent>> factory function. You can pass an optional { signal: AbortSignal } options object.
createObjectStream()
Create anObjectStream from an async iterable of ObjectStreamEvents.
createChatStream, this accepts an optional { signal: AbortSignal } options object.
wrapChatModel()
Wrap aChatModel with middleware to add cross-cutting behavior like logging, validation, or tracing.
ChatModel with the same interface. See the Middleware concept page for details on writing and composing middleware.
wrapEmbeddingModel()
Wrap anEmbeddingModel with middleware.
wrapImageModel()
Wrap anImageModel with middleware.
stripModelDateSuffix()
Remove a trailing-YYYYMMDD date suffix from a model ID. This is used internally for model capability lookups.
asObject()
Safely cast an unknown value toRecord<string, unknown>. Returns an empty object if the input is not an object.
safeParseJsonObject()
Safely parse a JSON string into an object. Returnsundefined if parsing fails or the result is not an object.