Overview
The AI SDK integration provides Effect-first wrappers for Vercel AI SDK functions. All callbacks are automatically bridged to support Effect-based handlers, allowing you to use services and structured concurrency within AI SDK operations.Installation
Exports
generateText
Generate text using a language model with Effect-based callbacks.Signature
Parameters
GenerateTextParams<R>
required
Configuration object matching AI SDK’s
generateText parameters, but with callbacks accepting Effects instead of Promises.Effectified Callbacks:onStepFinish?: (step) => Effect.Effect<void, never, R>onFinish?: (result) => Effect.Effect<void, never, R>experimental_onStart?: () => Effect.Effect<void, never, R>experimental_onStepStart?: (step) => Effect.Effect<void, never, R>experimental_onToolCallStart?: (call) => Effect.Effect<void, never, R>experimental_onToolCallFinish?: (result) => Effect.Effect<void, never, R>
Returns
Returns anEffect that yields the same result type as AI SDK’s generateText:
Example
streamText
Stream text generation with Effect-based callbacks.Signature
Parameters
StreamTextParams<R>
required
Configuration object matching AI SDK’s
streamText parameters, with effectified callbacks:Effectified Callbacks:onChunk?: (chunk) => Effect.Effect<void, never, R>onError?: (error) => Effect.Effect<void, never, R>onFinish?: (result) => Effect.Effect<void, never, R>onAbort?: () => Effect.Effect<void, never, R>onStepFinish?: (step) => Effect.Effect<void, never, R>- Plus all experimental callbacks from
generateText
Returns
Returns anEffect that yields AI SDK’s stream text result object. Requires Scope for proper cleanup.
Example
tool
Create AI SDK tools with Effect-based execute handlers.Signature
Parameters
EffectToolDef<INPUT, OUTPUT, R>
required
Tool definition object with effectified callbacks:
string
required
Human-readable description of what the tool does.
Schema<INPUT>
required
Schema for tool input validation (Zod, Valibot, or Effect schema).
(input: INPUT, options: ToolExecutionOptions) => Effect.Effect<OUTPUT, unknown, R>
Effect-based execution function. Can access Effect services.
(options: ToolExecutionOptions) => Effect.Effect<void, never, R>
Called when input parsing starts.
(options: { inputTextDelta: string } & ToolExecutionOptions) => Effect.Effect<void, never, R>
Called for each input text delta during streaming.
(options: { input: INPUT } & ToolExecutionOptions) => Effect.Effect<void, never, R>
Called when full input is available.
(options: { toolCallId: string; input: INPUT; output: OUTPUT }) => Effect.Effect<ToolModelOutput, never, R>
Custom output formatter for the model.
Returns
Returns anEffect that yields an AI SDK Tool object. Requires Scope.
Example: Simple Tool
Example: Tool with Services
effectSchema
Convert an Effect Schema to an AI SDK schema with automatic validation.Signature
Example
describe
Add descriptions to Effect Schema fields for better AI understanding.Signature
Example
AiError
Tagged error type for AI SDK operation failures.Example Error Handling
Complete Example
See Also
- AI SDK Documentation
- Effect Schema
- extract - Used internally for callback handling