Integrations

AI SDK Adapter

Capture AI SDK v6 generate and stream calls with language-model middleware, extract tool proposals, and wrap tool execute handlers.

@isplay/adapter-ai-sdk provides middleware and tool wrappers for common AI SDK shapes.

Install for AI SDK

npm install isplay @isplay/sdk @isplay/adapter-ai-sdk ai

Initialize the SDK in the process before model calls:

import { init } from "@isplay/sdk";

const client = init({
  projectId: process.env.ISPLAY_PROJECT_ID!,
  baseUrl: process.env.ISPLAY_API_URL,
});

Exports

ExportPurpose
createIsplayMiddleware(options)Returns typed AI SDK v6 LanguageModelMiddleware. Requires client or projectId.
wrapIsplayModel(model, options)Wraps a v6 language model with isplay middleware using wrapLanguageModel.
instrumentTools(tools, options)Wraps AI SDK execute handlers. Requires client or projectId.
recordToolProposals(client, modelCallId, result)Extracts tool calls from provider result and records proposals.
extractToolCalls(value)Finds common tool-call shapes recursively.
extractLogprobSignals(value)Pulls logprob-like provider metadata.
inferProvider(model)Infers provider metadata from model object when possible.
inferModel(model)Infers model name from model object when possible.

Middleware

import { createIsplayMiddleware, wrapIsplayModel } from "@isplay/adapter-ai-sdk";

const isplayMiddleware = createIsplayMiddleware({
  client,
  provider: "openai",
  model: "gpt-5.4-mini",
});

const model = wrapIsplayModel(yourModel, { client });

The middleware:

  1. Starts a model call with provider, model, operation, params, and settings.
  2. Calls doGenerate() or doStream().
  3. Records tool proposals extracted from the result or stream chunks.
  4. Finishes the model call with output, usage, logprobs, or error.

Drain streams

For wrapStream, the model call finishes when the transformed stream flushes. If your application does not consume the stream, capture remains incomplete.

Tool Instrumentation

import { instrumentTools } from "@isplay/adapter-ai-sdk";

const tools = instrumentTools(
  {
    lookupClaim: {
      description: "Read claim details.",
      inputSchema,
      __isplaySideEffectClass: "read",
      __isplaySchemaVersion: "1",
      __isplayImplementationVersion: "2026-05-24",
      async execute(args) {
        return lookupClaim(args.claimId);
      },
    },
  },
  { client }
);

instrumentTools() preserves non-executable tool entries. For tools with execute, it wraps execution with adapter-kit wrapTool().

Captured Evidence

EvidenceSource
Model provider/modelAdapter options or inference from model object.
Operationgenerate for wrapGenerate, stream for wrapStream.
Request paramsAI SDK middleware params.
Response outputResult object, or stream result with captured chunks.
Usageresult.usage when present.
LogprobsExtracted from result or provider metadata.
Tool proposalsExtracted recursively from result shapes.
Tool executionsWrapped execute handlers.

Advice

  • Pass explicit provider/model options when inference is ambiguous.
  • Add __isplaySideEffectClass to every tool that can read, write, or mutate external systems. Shell/code-like names default to external_mutation; unknown tools remain unknown.
  • Capture tool schemas in context through adapter-kit if your tool definitions are not visible in request params.
  • Keep AI SDK calls inside client.withRun() or an adapter-managed run context.
  • Use pause-for-fixture replay policy for divergent tool calls; do not rerun side-effecting tools implicitly.

On this page