AI Transport providers
Stream model output from Vercel AI SDK, OpenAI, Anthropic, OpenAI-compatible APIs, and custom providers through Sockudo AI Transport.
Sockudo AI Transport is provider-neutral. Sockudo carries ordered, durable run state; your agent chooses how to call the model and converts provider output into AI SDK UI message chunks. This page shows how to connect each supported provider family, with complete agent code, and how to handle tool calls, approvals, voice, and generated media. Read it when you wire your first model into a session or switch providers.
Pick an integration
The JavaScript SDK has three entry points for agents:
| Integration | Import | Best for |
|---|---|---|
| Vercel AI SDK transport | @sockudo/ai-transport/vercel | Apps already using ai, streamText, useChat, Vue, React, or Svelte AI SDK UI primitives. |
| Direct provider adapters | @sockudo/ai-transport/providers | Workers that call OpenAI, Anthropic, OpenAI-compatible HTTP/SSE endpoints, or local model servers directly. |
| Core codec transport | @sockudo/ai-transport | Custom model protocols, custom UI projections, or non-Vercel message shapes. |
| You have | Use |
|---|---|
Vercel AI SDK streamText already wired | @sockudo/ai-transport/vercel |
| A provider with OpenAI-compatible SSE | createOpenAICompatibleProvider |
| Official OpenAI SDK | createOpenAISdkProvider |
| Official Anthropic SDK | createAnthropicSdkProvider |
| A custom internal model gateway | DirectLlmProvider |
| A non-Vercel UI model | Core codec API from @sockudo/ai-transport |
| AI SDK agent or workflow output | Convert to UI message chunks, then stream through the Vercel transport |
| Realtime voice or generated video | Provider media path plus Sockudo transcript/control events |
Provider flow
Every integration has the same shape. The provider only ever streams chunks to your worker; the worker turns them into mutable-message operations on the session channel.
sequenceDiagram participant U as User client participant S as Sockudo participant A as Agent worker participant M as Model provider participant H as History store U->>S: ai-input on the session channel S->>H: persist the user message A->>M: stream request M-->>A: deltas, tool calls, finish A->>S: create and append ai-output S->>H: persist every mutation S-->>U: live rolled-up appends Note over U,H: a refreshed client rewinds history instead
The provider never needs to know about connection recovery, rewind, history cursors, branch trees, presence, or multi-device fanout. It streams chunks. Sockudo makes those chunks durable and observable.
Vercel AI SDK
Use Vercel AI SDK when you want provider packages, tool calling, and UI message streams to stay in
the ai ecosystem. This Nuxt route mirrors the repository demo:
import { streamText, toUIMessageStream } from "ai";import { createAgentSession } from "@sockudo/ai-transport/vercel";import { realtimeClient } from "../utils/sockudo";import { requireSessionOwner } from "../utils/auth";
export default defineEventHandler(async (event) => { const body = await readBody(event); const channelName: string = body.sessionName; const userId = await requireSessionOwner(event, channelName);
const session = createAgentSession({ client: realtimeClient(), channelName, });
const run = session.createRun({ runId: body.runId, invocationId: body.invocationId, inputEventId: body.inputEventId, clientId: userId, onCancel(request) { return ( request.filter.all === true || request.runOwners.get(body.runId) === userId ); }, });
const work = (async () => { await run.start(); try { const result = streamText({ model: "openai/gpt-5-mini", instructions: "You are a concise incident-room assistant.", prompt: body.messages .at(-1) ?.parts?.map((part) => part.text ?? "") .join("") ?? "", abortSignal: run.abortSignal, }); await run.streamResponse(toUIMessageStream({ stream: result.stream })); await run.end("complete"); } catch { await run.end("error"); } })().finally(() => session.close());
event.waitUntil?.(work); setResponseStatus(event, 202); return null;});The client SDK posts sessionName, runId, invocationId, inputEventId, clientId, and the UI
messages. onCancel decides whether an ai-cancel may stop this run; checking runOwners
against the verified owner stops one user from cancelling another user’s run.
The frontend can use the Vercel-compatible transport in React, Vue, or Svelte:
import { createSockudoRealtimeClient } from "@sockudo/ai-transport";import { useChat } from "@ai-sdk/vue";import { provideChatTransport } from "@sockudo/ai-transport/vercel/vue";
const realtime = await createSockudoRealtimeClient("app-key", { clientOptions: { wsHost: "realtime.example.com", forceTLS: true, channelAuthorization: { endpoint: "/api/sockudo/channel-auth" }, authUrl: "/api/sockudo/token", },});
const provider = provideChatTransport({ api: "/api/chat", channelName: "private-ai-user-42-sess-01J", client: realtime, clientId: "user-42",});
const { sendMessage } = useChat({ id: "private-ai-user-42-sess-01J", transport: provider.chatTransport.value,});
await sendMessage({ text: "Summarize the last deploy failure." });React uses ChatTransportProvider and useChatTransport from
@sockudo/ai-transport/vercel/react; Svelte uses createChatTransportStore from
@sockudo/ai-transport/vercel/svelte.
AI SDK 7 feature coverage
AI SDK 7 does not require a separate Sockudo server mode. The compatibility surface is the AI SDK UI message stream: Sockudo persists ordered UI chunks, run lifecycle events, approval responses, and metadata, while the app runtime keeps provider calls, tool execution, and agent-local state.
| AI SDK capability | Sockudo behavior |
|---|---|
| Reasoning controls | Pass model options through streamText; Sockudo carries emitted reasoning text and reasoning-file chunks. |
| Tool context and runtime context | Keep context on the trusted worker. Publish only safe derived metadata, never provider secrets or raw tool credentials. |
| Provider file and skill uploads | Let the provider own uploads and references. Sockudo can carry file, source, reasoning-file, or custom chunks that point at externally stored assets. |
| MCP Apps and custom UI parts | Preserve custom chunks and provider metadata. Rendering app iframes or custom widgets remains a client responsibility. |
| Tool approvals | Persist approval requests and responses as normal run state. The app still owns approval policy, signature checks, and tool execution authorization. |
WorkflowAgent and HarnessAgent output | Stream their UI-message output through toUIMessageStream. Use the workflow store for agent checkpoints and Sockudo for transcript/reconnect history. |
| Realtime voice | Keep low-latency audio on the provider’s realtime channel. Mirror transcripts, tool calls, approvals, and final state through Sockudo. |
| Video generation | Store generated media outside Sockudo and publish progress, asset URLs, thumbnails, or final file parts through the AI session channel. |
| Telemetry and lifecycle callbacks | Correlate AI SDK spans with channelName, runId, and invocationId. Sockudo metrics continue to describe transport, history, and fanout health. |
Direct provider support
The @sockudo/ai-transport/providers entry point supports these built-in adapters:
| Provider path | Function | Notes |
|---|---|---|
| OpenAI-compatible HTTP/SSE | streamOpenAICompatibleText | Uses Chat Completions-compatible /chat/completions streaming. |
| OpenAI-compatible reusable provider | createOpenAICompatibleProvider | Good for named provider registries. |
| OpenAI SDK Chat Completions | streamOpenAIChatCompletion / createOpenAISdkProvider | Uses a structural subset of the official OpenAI SDK. |
| OpenAI SDK Responses | streamOpenAIResponse / createOpenAISdkProvider({ mode: "responses" }) | Maps output text and tool argument deltas to UI chunks. |
| Anthropic SDK Messages | streamAnthropicMessage / createAnthropicSdkProvider | Maps text, thinking, tool use, and finish reasons. |
OpenAI-compatible presets are:
| Name | Default base URL |
|---|---|
openai | https://api.openai.com/v1 |
openrouter | https://openrouter.ai/api/v1 |
groq | https://api.groq.com/openai/v1 |
togetherai | https://api.together.xyz/v1 |
fireworks | https://api.fireworks.ai/inference/v1 |
deepseek | https://api.deepseek.com |
perplexity | https://api.perplexity.ai |
mistral | https://api.mistral.ai/v1 |
xai | https://api.x.ai/v1 |
ollama | http://127.0.0.1:11434/v1 |
lmstudio | http://127.0.0.1:1234/v1 |
Local providers such as Ollama and LM Studio may omit apiKey when the local server does not
require one. Pass baseURL to target any other compatible endpoint.
A complete direct-provider worker
runDirectLlm(run, provider, request) does the whole run for you: it calls run.start(), streams
the provider through run.streamResponse, maps the provider finish reason to a run end reason,
publishes ai-run-end, and returns { pipeResult, runEndReason }. It also wires
run.abortSignal into the provider request, so ai-cancel stops the model call. Do not call
run.start() or run.end() yourself around it.
import { createAgentSession } from "@sockudo/ai-transport/vercel";import { createOpenAICompatibleProvider, runDirectLlm,} from "@sockudo/ai-transport/providers";import { realtimeClient } from "./sockudo";
const provider = createOpenAICompatibleProvider({ provider: "groq", apiKey: process.env.GROQ_API_KEY, model: "llama-3.3-70b-versatile",});
export async function handleRun(job: { channelName: string; runId: string; invocationId: string; inputEventId: string; userId: string; prompt: string;}) { const session = createAgentSession({ client: realtimeClient(), channelName: job.channelName, }); const run = session.createRun({ runId: job.runId, invocationId: job.invocationId, inputEventId: job.inputEventId, clientId: job.userId, });
try { const { runEndReason } = await runDirectLlm(run, provider, { model: "llama-3.3-70b-versatile", prompt: job.prompt, maxOutputTokens: 800, }); return runEndReason; } finally { session.close(); }}The remaining examples assume a run created the same way.
OpenAI SDK
import OpenAI from "openai";import { createOpenAISdkProvider, runDirectLlm,} from "@sockudo/ai-transport/providers";
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
const chatProvider = createOpenAISdkProvider({ client: openai, mode: "chat", model: "gpt-4.1-mini",});
await runDirectLlm(run, chatProvider, { model: "gpt-4.1-mini", messages: [ { role: "system", content: "Answer as a production engineer." }, { role: "user", content: "Why did reconnect recovery fail?" }, ],});Use mode: "responses" for the Responses API. Provider-specific fields go in body:
const responsesProvider = createOpenAISdkProvider({ client: openai, mode: "responses", model: "gpt-5-mini",});
await runDirectLlm(run, responsesProvider, { model: "gpt-5-mini", prompt: "Explain the latest channel history page in plain English.", body: { reasoning: { effort: "low" }, },});Anthropic SDK
import Anthropic from "@anthropic-ai/sdk";import { createAnthropicSdkProvider, runDirectLlm,} from "@sockudo/ai-transport/providers";
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
const provider = createAnthropicSdkProvider({ client: anthropic, model: "claude-sonnet-4-5", system: "Be concise and include risk levels.",});
await runDirectLlm(run, provider, { model: "claude-sonnet-4-5", prompt: "Audit this failed push notification delivery chain.",});The adapters are structural: they accept any object with the same create(...) streaming shape as
the official SDK clients, so the package does not import provider SDKs itself.
Provider registry
Use a registry when the UI lets a user or tenant select a model provider.
import Anthropic from "@anthropic-ai/sdk";import { createAnthropicSdkProvider, createDirectLlmProviderRegistry, createOpenAICompatibleProvider,} from "@sockudo/ai-transport/providers";
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
export const providers = createDirectLlmProviderRegistry({ groq: createOpenAICompatibleProvider({ provider: "groq", apiKey: process.env.GROQ_API_KEY, model: "llama-3.3-70b-versatile", }), local: createOpenAICompatibleProvider({ provider: "ollama", model: "llama3.2", }), anthropic: createAnthropicSdkProvider({ client: anthropic, model: "claude-sonnet-4-5", }),});
const stream = await providers.streamText("local", { model: "llama3.2", prompt: "Return a JSON incident summary.",});providers.get(name) returns the provider (or undefined), which you can pass to runDirectLlm.
providers.streamText throws for an unknown name, so validate tenant input first.
Custom provider
Any provider that returns ReadableStream<VercelOutput> can participate.
import type { DirectLlmProvider } from "@sockudo/ai-transport/providers";
export const provider: DirectLlmProvider = { async streamText(request) { const words = (request.prompt ?? "").split(/\s+/);
return new ReadableStream({ start(controller) { controller.enqueue({ type: "start" }); controller.enqueue({ type: "text-start", id: "answer" }); for (const word of words) { controller.enqueue({ type: "text-delta", id: "answer", delta: `${word} `, }); } controller.enqueue({ type: "text-end", id: "answer" }); controller.enqueue({ type: "finish", finishReason: "stop" }); controller.close(); }, }); },};Emit start first and finish last, and give every text or reasoning part matching *-start,
*-delta, and *-end chunks with the same id.
Tool calling and human approval
Tool calls are just streamed UI message chunks. The transport persists every tool-input delta and the final tool state, so a user can approve from another tab or after a reconnect.
sequenceDiagram participant A as Agent participant S as Sockudo participant W as Web client participant T as Tool executor A->>S: tool-input-start + deltas S-->>W: pending approval appears W->>S: approval response T->>S: tool output A->>S: continue ai-output append
For AI SDK 7 approval flows, treat the request and response as part of the transcript:
-
The agent streams a
tool-approval-requestchunk with a stable approval id and tool call id. -
Sockudo stores that request on the
ai-outputmutable message and fans it out to every attached client. -
The client records an approval response on the assistant tool part. The Vercel chat transport diffs the optimistic message overlay and publishes a
tool-approval-responseinput. -
The worker verifies the response, runs or denies the tool, then appends
tool-result,tool-result-error, oroutput-deniedstate.
Use channel auth and V2 capabilities to decide who can approve. If the provider supplies approval signatures or automatic-approval markers, keep them with the approval chunk so the worker can verify them before executing the tool.
Realtime voice and generated media
AI SDK realtime voice sessions are optimized for provider-native WebSocket or WebRTC media paths. Sockudo should not proxy high-rate PCM frames, microphone buffers, or generated video bytes through mutable-message appends. Use Sockudo as the durable control and transcript plane:
- publish session start, model, voice, and participant metadata
- append transcript deltas, final transcript text, tool calls, and approval state
- fan out presence for the user, agent, and handoff devices
- publish push notifications or completion events when the media job finishes
- store recordings, uploaded files, thumbnails, and generated videos in object storage, then publish references as file, source, or custom chunks
This keeps reconnect, rewind, audit, and multi-device UI recovery in Sockudo without putting latency-sensitive media on the same path as durable chat history.