---
title: AI SDK API
description: Generated public TypeScript reference for @relkit/ai-sdk.
search:
  exclude: true
sidebar:
  icon: braces
---

{/* Generated by apps/docs/scripts/generate.ts. Do not edit. */}

For configuration and examples, read [ai](/docs/modules/ai), [tools](/docs/modules/ai/tools), [function tools](/docs/modules/ai/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](/docs/api/integrations/ai-sdk#aisdk)                                                   | Value | `@relkit/ai-sdk`         | [API example](/docs/api/integrations/ai-sdk#aisdk)                                                                         |
| [AiSdkAgentOptions](/docs/api/integrations/ai-sdk#aisdkagentoptions-interface)                 | Type  | `@relkit/ai-sdk`         | [Module example](/docs/modules/ai)                                                                                         |
| [aiSdkAgentRuntime](/docs/api/integrations/ai-sdk#aisdkagentruntime)                           | Value | `@relkit/ai-sdk/runtime` | [API example](/docs/api/integrations/ai-sdk#aisdkagentruntime)                                                             |
| [AiSdkInvocationOptions](/docs/api/integrations/ai-sdk#aisdkinvocationoptions)                 | Type  | `@relkit/ai-sdk/runtime` | [Module example](/docs/modules/ai)                                                                                         |
| [aiSdkModel](/docs/api/integrations/ai-sdk#aisdkmodel)                                         | Value | `@relkit/ai-sdk`         | [API example](/docs/api/integrations/ai-sdk#aisdkmodel)                                                                    |
| [AiSdkModelAdapter](/docs/api/integrations/ai-sdk#aisdkmodeladapter-type-alias)                | Type  | `@relkit/ai-sdk`         | [Module example](/docs/modules/ai)                                                                                         |
| [AiSdkModelOptions](/docs/api/integrations/ai-sdk#aisdkmodeloptions-interface)                 | Type  | `@relkit/ai-sdk`         | [Module example](/docs/modules/ai)                                                                                         |
| [AiSdkModelRegistry](/docs/api/integrations/ai-sdk#aisdkmodelregistry-interface)               | Type  | `@relkit/ai-sdk/runtime` | [Module example](/docs/modules/ai)                                                                                         |
| [AiSdkNativeFields](/docs/api/integrations/ai-sdk#aisdknativefields-interface)                 | Type  | `@relkit/ai-sdk`         | [Module example](/docs/modules/ai)                                                                                         |
| [AiSdkRuntime](/docs/api/integrations/ai-sdk#aisdkruntime-type-alias)                          | Type  | `@relkit/ai-sdk`         | [Module example](/docs/modules/ai)                                                                                         |
| [assertAgentRuntimeDependencies](/docs/api/integrations/ai-sdk#assertagentruntimedependencies) | Value | `@relkit/ai-sdk/runtime` | [API example](/docs/api/integrations/ai-sdk#assertagentruntimedependencies)                                                |
| [createAiSdkModelRegistry](/docs/api/integrations/ai-sdk#createaisdkmodelregistry)             | Value | `@relkit/ai-sdk/runtime` | [API example](/docs/api/integrations/ai-sdk#createaisdkmodelregistry)                                                      |
| [invokeAgentFunction](/docs/api/integrations/ai-sdk#invokeagentfunction)                       | Value | `@relkit/ai-sdk/runtime` | [API example](/docs/api/integrations/ai-sdk#invokeagentfunction)                                                           |
| [releaseAgentPersistence](/docs/api/integrations/ai-sdk#releaseagentpersistence)               | Value | `@relkit/ai-sdk/runtime` | [API example](/docs/api/integrations/ai-sdk#releaseagentpersistence)                                                       |
| [runtimeIntegration](/docs/api/integrations/ai-sdk#runtimeintegration)                         | Value | `@relkit/ai-sdk/runtime` | [Source example](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/tests/model-profile.test.ts#L32) |

## `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**

```ts
const execution = aiSdkAgentRuntime.execution(context);
```

**Signature**

```ts
declare const aiSdkAgentRuntime: AgentAdapterRuntime<"ai-sdk">;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/adapter-runtime.ts#L17)

## `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**

```ts
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**

```ts
declare const aiSdk: (options?: AiSdkAgentOptions) => AiSdkRuntime;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/adapter.ts#L46)

Since v0.9.0

### AiSdkAgentOptions (interface)

AI SDK-native options accepted by `aiSdk({ ... })`.

**Signature**

```ts
export interface AiSdkAgentOptions {
  /** An AI SDK language model; omitted resolves the agent's model profile. Ties the agent to this adapter. */
  readonly model?: object;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/adapter.ts#L8)

### AiSdkNativeFields (interface)

Descriptor fields the AI SDK adapter adds to an agent.

**Signature**

```ts
export interface AiSdkNativeFields {
  readonly model?: object | string;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/adapter.ts#L14)

### AiSdkRuntime (type alias)

Value returned by `aiSdk({ ... })`.

**Signature**

```ts
type AiSdkRuntime = AgentRuntimeAdapter<"ai-sdk", AiSdkAgentOptions, AiSdkNativeFields>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/adapter.ts#L19)

## `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**

```ts
export * from "./adapter.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/index.ts#L2)

### "./model-profile.js" (namespace export)

Re-exports all named exports from the "./model-profile.js" module.

**Signature**

```ts
export * from "./model-profile.js";
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/index.ts#L3)

## `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**

```ts
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 };
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/model-profile-runtime.ts#L5)

### aiSdkModelRegistration

Registers the AI SDK model registry for the `model` capability.

**Signature**

```ts
declare const aiSdkModelRegistration: RuntimeProviderRegistration;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/model-profile-runtime.ts#L37)

### createAiSdkModelRegistry

Creates the registry for one bound profile.

**Example**

```ts
createAiSdkModelRegistry({ connection: { model: "openai/gpt-5" }, profile: "default" });
```

**Signature**

```ts
declare const createAiSdkModelRegistry: (
  context: Pick<RuntimeProviderContext, "connection" | "profile">,
) => AiSdkModelRegistry;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/model-profile-runtime.ts#L20)

## `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**

```ts
import { aiSdkModel } from "@relkit/ai-sdk";
const models = { default: aiSdkModel({ model: "openai/gpt-5" }) };
void models;
```

**Signature**

```ts
declare const aiSdkModel: (options: AiSdkModelOptions) => AiSdkModelAdapter;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/model-profile.ts#L44)

Since v0.10.0

### AiSdkModelAdapter (type alias)

Model provider value bound to a profile.

**Signature**

```ts
type AiSdkModelAdapter = ProviderAdapter<typeof model, "ai-sdk-model">;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/model-profile.ts#L29)

### AiSdkModelOptions (interface)

Options for `aiSdkModel`.

**Signature**

```ts
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;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/model-profile.ts#L20)

## `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**

```ts
declare const approvingTools: (
  bridge: AgentToolBridge,
  options: AiSdkInvocationOptions & {
    readonly approval: NonNullable<AiSdkInvocationOptions["approval"]>;
  },
  signal: AbortSignal,
) => AgentToolBridge;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime-content.ts#L99)

### 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**

```ts
declare const contentWriter: (
  sink: AgentContentSink | undefined,
  signal: AbortSignal,
) => (frame: AgentAdapterFrame) => Promise<void>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime-content.ts#L44)

### 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**

```ts
declare const threadFromHistory: (
  threadId: string,
  history: readonly AgentConversationMessage[] | undefined,
) => AgentThreadState | undefined;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime-content.ts#L26)

## `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**

```ts
await invokeAgentFunction({ agent, input, tools, engine, modelRegistry });
```

**Signature**

```ts
declare const invokeAgentFunction: (options: AiSdkInvocationOptions) => Promise<unknown>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime-invoke.ts#L26)

## `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**

```ts
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>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime-invoke.types.ts#L11)

## `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**

```ts
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>;
}
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime-invoke.types.ts#L11)

### AiSdkModelRegistry

**Signature**

```ts
declare const AiSdkModelRegistry: any;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime/index.ts#L7)

### aiSdkAgentRuntime

**Signature**

```ts
declare const aiSdkAgentRuntime: AgentAdapterRuntime<"ai-sdk">;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime/index.ts#L6)

### assertAgentRuntimeDependencies

Confirms the AI SDK package can be loaded before the server accepts requests.

**Example**

```ts
await assertAgentRuntimeDependencies([]);
```

**Signature**

```ts
declare const assertAgentRuntimeDependencies: (agents: readonly unknown[]) => Promise<void>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime/index.ts#L27)

### createAiSdkModelRegistry

**Signature**

```ts
declare const createAiSdkModelRegistry: (
  context: Pick<RuntimeProviderContext, "connection" | "profile">,
) => AiSdkModelRegistry;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime/index.ts#L7)

### invokeAgentFunction

**Signature**

```ts
declare const invokeAgentFunction: (options: AiSdkInvocationOptions) => Promise<unknown>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime/index.ts#L8)

### releaseAgentPersistence

Releases adapter-owned persistence; AI SDK agents keep their threads in RelKit's agent state.

**Example**

```ts
await releaseAgentPersistence([]);
```

**Signature**

```ts
declare const releaseAgentPersistence: (agents: readonly unknown[]) => Promise<void>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime/index.ts#L37)

### runtimeIntegration

Runtime integration the generated server loads for agents that use `aiSdk()`.

**Signature**

```ts
declare const runtimeIntegration: Readonly<{
  kind: "runtime-integration";
  integrationId: "ai-sdk";
  registrations: ReadonlyArray<
    RuntimeProviderRegistration | { capability: string; adapterId: string; protocolVersion: number }
  >;
}>;
```

[Source](https://github.com/rel-kit/relkit/blob/main/integrations/packages/ai-sdk/src/runtime/index.ts#L12)
