AI SDK API
Generated public TypeScript reference for @relkit/ai-sdk.
For configuration and examples, read ai, tools, function tools.
Public imports
@relkit/ai-sdk— 7 exports@relkit/ai-sdk/runtime— 8 exports
All exported APIs
Names link to their complete contracts. Re-exports share their original contract; legacy exports keep their separate identity. Examples link to the API’s inline sample, a maintained repository usage, or the shared module walkthrough.
| API | Kind | Import from | Example |
|---|---|---|---|
| aiSdk | Value | @relkit/ai-sdk |
API example |
| AiSdkAgentOptions | Type | @relkit/ai-sdk |
Module example |
| aiSdkAgentRuntime | Value | @relkit/ai-sdk/runtime |
API example |
| AiSdkInvocationOptions | Type | @relkit/ai-sdk/runtime |
Module example |
| aiSdkModel | Value | @relkit/ai-sdk |
API example |
| AiSdkModelAdapter | Type | @relkit/ai-sdk |
Module example |
| AiSdkModelOptions | Type | @relkit/ai-sdk |
Module example |
| AiSdkModelRegistry | Type | @relkit/ai-sdk/runtime |
Module example |
| AiSdkNativeFields | Type | @relkit/ai-sdk |
Module example |
| AiSdkRuntime | Type | @relkit/ai-sdk |
Module example |
| assertAgentRuntimeDependencies | Value | @relkit/ai-sdk/runtime |
API example |
| createAiSdkModelRegistry | Value | @relkit/ai-sdk/runtime |
API example |
| invokeAgentFunction | Value | @relkit/ai-sdk/runtime |
API example |
| releaseAgentPersistence | Value | @relkit/ai-sdk/runtime |
API example |
| runtimeIntegration | Value | @relkit/ai-sdk/runtime |
Source example |
adapter-runtime.ts
Runtime half of the AI SDK adapter for the shared agent loop: one model turn is one streamText
call with the bridged tools declared and no execute, so RelKit’s loop runs every tool. The turn
passes text to the loop as the model produces it.
aiSdkAgentRuntime
The AI SDK adapter’s runtime half, used by the shared agent loop and the conformance suite.
Example
const execution = aiSdkAgentRuntime.execution(context);
Signature
declare const aiSdkAgentRuntime: AgentAdapterRuntime<"ai-sdk">;
adapter.ts
The Vercel AI SDK agent adapter. aiSdk({ ... }) is the value an agent’s runtime field holds; it
imports nothing from the AI SDK, so declaring an agent loads no SDK.
aiSdk
Selects the Vercel AI SDK to execute an agent.
Example
import { aiSdk } from "@relkit/ai-sdk";
import { defineAgent } from "relkit/agents";
import { z } from "relkit/schema";
const support = defineAgent({
id: "support",
runtime: aiSdk(),
model: "default",
input: z.object({ message: z.string() }),
output: z.object({ answer: z.string() }),
instructions: "Reply briefly.",
tools: [],
limits: { maxSteps: 4, maxToolCalls: 2, timeoutMs: 30_000 },
});
void support;
Signature
declare const aiSdk: (options?: AiSdkAgentOptions) => AiSdkRuntime;
Since v0.9.0
AiSdkAgentOptions (interface)
AI SDK-native options accepted by aiSdk({ ... }).
Signature
export interface AiSdkAgentOptions {
/** An AI SDK language model; omitted resolves the agent's model profile. Ties the agent to this adapter. */
readonly model?: object;
}
AiSdkNativeFields (interface)
Descriptor fields the AI SDK adapter adds to an agent.
Signature
export interface AiSdkNativeFields {
readonly model?: object | string;
}
AiSdkRuntime (type alias)
Value returned by aiSdk({ ... }).
Signature
type AiSdkRuntime = AgentRuntimeAdapter<"ai-sdk", AiSdkAgentOptions, AiSdkNativeFields>;
index.ts
Publishes the AI SDK adapter’s authoring value; execution lives in @relkit/ai-sdk/runtime.
“./adapter.js” (namespace export)
Re-exports all named exports from the “./adapter.js” module.
Signature
export * from "./adapter.js";
“./model-profile.js” (namespace export)
Re-exports all named exports from the “./model-profile.js” module.
Signature
export * from "./model-profile.js";
model-profile-runtime.ts
Runtime registration of the AI SDK model profile provider: resolves an agent’s profile to its bound model ID.
AiSdkModelRegistry (interface)
Registry value an AI SDK agent run reads its model from.
Signature
export interface AiSdkModelRegistry {
/**
* @param selector - The agent's `model` value; `profile:name` replaces the bound model name and
* keeps its provider.
* @returns The bound model identity and the model ID the AI SDK resolves.
*/
readonly resolveModel: (selector?: string) => { readonly id: string; readonly model: string };
}
aiSdkModelRegistration
Registers the AI SDK model registry for the model capability.
Signature
declare const aiSdkModelRegistration: RuntimeProviderRegistration;
createAiSdkModelRegistry
Creates the registry for one bound profile.
Example
createAiSdkModelRegistry({ connection: { model: "openai/gpt-5" }, profile: "default" });
Signature
declare const createAiSdkModelRegistry: (
context: Pick<RuntimeProviderContext, "connection" | "profile">,
) => AiSdkModelRegistry;
model-profile.ts
Model profiles for the AI SDK adapter: aiSdkModel({ model }) binds a profile in
relkit.config.ts to a model ID that the AI SDK resolves with its global provider, so an
application that uses only the AI SDK binds models without installing LangChain.
aiSdkModel
Binds a model profile to an AI SDK model ID.
Example
import { aiSdkModel } from "@relkit/ai-sdk";
const models = { default: aiSdkModel({ model: "openai/gpt-5" }) };
void models;
Signature
declare const aiSdkModel: (options: AiSdkModelOptions) => AiSdkModelAdapter;
Since v0.10.0
AiSdkModelAdapter (type alias)
Model provider value bound to a profile.
Signature
type AiSdkModelAdapter = ProviderAdapter<typeof model, "ai-sdk-model">;
AiSdkModelOptions (interface)
Options for aiSdkModel.
Signature
export interface AiSdkModelOptions {
/**
* A model ID the AI SDK's global provider resolves: `provider/model` for the AI Gateway, such as
* `openai/gpt-5`, or the IDs of the provider set in `globalThis.AI_SDK_DEFAULT_PROVIDER`.
*/
readonly model: string;
}
runtime-content.ts
Connects the shared loop of an AI SDK agent to the generated server: the thread history the
server loaded from the application’s agent-state profile, the run’s content sink, which journals
text, tools and output as the run produces them, and the run’s approval handler, which waits for a
client’s decision inside the tool call.
approvingTools
Wraps the tool bridge so a tool that needs approval waits for the run’s approval handler inside the call, as the LangChain adapter’s RelKit tools do; the run does not end while it waits.
Signature
declare const approvingTools: (
bridge: AgentToolBridge,
options: AiSdkInvocationOptions & {
readonly approval: NonNullable<AiSdkInvocationOptions["approval"]>;
},
signal: AbortSignal,
) => AgentToolBridge;
contentWriter
Writes the loop’s frames to the run’s content sink: text as it streams, and each tool call’s input and outcome.
Signature
declare const contentWriter: (
sink: AgentContentSink | undefined,
signal: AbortSignal,
) => (frame: AgentAdapterFrame) => Promise<void>;
threadFromHistory
Builds the stored thread a run continues from the conversation the server loaded for it; the shared loop puts the agent’s instructions first.
Signature
declare const threadFromHistory: (
threadId: string,
history: readonly AgentConversationMessage[] | undefined,
) => AgentThreadState | undefined;
runtime-invoke.ts
Runs one AI SDK agent invocation for the generated server: model from the agent’s profile, tools through the bridge, approvals through the run’s approval handler, the thread’s history from the server, and text, tools and output written to the run’s content sink as the run produces them.
invokeAgentFunction
Invokes an AI SDK agent once and returns its validated output.
Throws
AgentAdapterError when the run fails, is stopped or waits for an approval nobody can give.
Example
await invokeAgentFunction({ agent, input, tools, engine, modelRegistry });
Signature
declare const invokeAgentFunction: (options: AiSdkInvocationOptions) => Promise<unknown>;
runtime-invoke.types.ts
Inputs the generated server passes to an agent adapter’s invokeAgentFunction.
AiSdkInvocationOptions (interface)
Agent invocation options shared with the LangChain adapter’s runtime entry.
Signature
export interface AiSdkInvocationOptions {
readonly agent: {
readonly id: string;
readonly model?: unknown;
readonly instructions: unknown;
readonly output: import("relkit/schema").StandardSchemaV1;
readonly tools: readonly { readonly ref: { readonly id: string } }[];
readonly limits: {
readonly maxSteps: number;
readonly maxToolCalls: number;
readonly timeoutMs: number;
};
readonly runtime: import("relkit/agent-adapters").AgentRuntimeReference;
};
readonly input: unknown;
readonly tools: ToolSource;
readonly engine: ToolEngine;
readonly modelRegistry?: {
readonly resolveModel: (selector?: string) => unknown;
};
readonly invocationId?: string;
readonly threadId?: string;
readonly signal?: AbortSignal;
/** Earlier messages of the thread, loaded by the server from the application's `agent-state`. */
readonly messages?: readonly AgentConversationMessage[];
/** The run's journal; text, tool states and the output are written to it as the run produces them. */
readonly contentSink?: AgentContentSink;
readonly approval?: (
approval: PendingApproval,
) =>
| "approved"
| "denied"
| boolean
| ApprovalRecord
| Promise<"approved" | "denied" | boolean | ApprovalRecord>;
}
index.ts
Runtime entry of the AI SDK adapter: the generated server imports it only for agents that select aiSdk().
AiSdkInvocationOptions
Agent invocation options shared with the LangChain adapter’s runtime entry.
Signature
export interface AiSdkInvocationOptions {
readonly agent: {
readonly id: string;
readonly model?: unknown;
readonly instructions: unknown;
readonly output: import("relkit/schema").StandardSchemaV1;
readonly tools: readonly { readonly ref: { readonly id: string } }[];
readonly limits: {
readonly maxSteps: number;
readonly maxToolCalls: number;
readonly timeoutMs: number;
};
readonly runtime: import("relkit/agent-adapters").AgentRuntimeReference;
};
readonly input: unknown;
readonly tools: ToolSource;
readonly engine: ToolEngine;
readonly modelRegistry?: {
readonly resolveModel: (selector?: string) => unknown;
};
readonly invocationId?: string;
readonly threadId?: string;
readonly signal?: AbortSignal;
/** Earlier messages of the thread, loaded by the server from the application's `agent-state`. */
readonly messages?: readonly AgentConversationMessage[];
/** The run's journal; text, tool states and the output are written to it as the run produces them. */
readonly contentSink?: AgentContentSink;
readonly approval?: (
approval: PendingApproval,
) =>
| "approved"
| "denied"
| boolean
| ApprovalRecord
| Promise<"approved" | "denied" | boolean | ApprovalRecord>;
}
AiSdkModelRegistry
Signature
declare const AiSdkModelRegistry: any;
aiSdkAgentRuntime
Signature
declare const aiSdkAgentRuntime: AgentAdapterRuntime<"ai-sdk">;
assertAgentRuntimeDependencies
Confirms the AI SDK package can be loaded before the server accepts requests.
Example
await assertAgentRuntimeDependencies([]);
Signature
declare const assertAgentRuntimeDependencies: (agents: readonly unknown[]) => Promise<void>;
createAiSdkModelRegistry
Signature
declare const createAiSdkModelRegistry: (
context: Pick<RuntimeProviderContext, "connection" | "profile">,
) => AiSdkModelRegistry;
invokeAgentFunction
Signature
declare const invokeAgentFunction: (options: AiSdkInvocationOptions) => Promise<unknown>;
releaseAgentPersistence
Releases adapter-owned persistence; AI SDK agents keep their threads in RelKit’s agent state.
Example
await releaseAgentPersistence([]);
Signature
declare const releaseAgentPersistence: (agents: readonly unknown[]) => Promise<void>;
runtimeIntegration
Runtime integration the generated server loads for agents that use aiSdk().
Signature
declare const runtimeIntegration: Readonly<{
kind: "runtime-integration";
integrationId: "ai-sdk";
registrations: ReadonlyArray<
RuntimeProviderRegistration | { capability: string; adapterId: string; protocolVersion: number }
>;
}>;