AI Transport providers

Stream model output from Vercel AI SDK, OpenAI, Anthropic, OpenAI-compatible APIs, and custom providers through Sockudo AI Transport.

7 min read
View .mdEdit on GitHub

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:

IntegrationImportBest for
Vercel AI SDK transport@sockudo/ai-transport/vercelApps already using ai, streamText, useChat, Vue, React, or Svelte AI SDK UI primitives.
Direct provider adapters@sockudo/ai-transport/providersWorkers that call OpenAI, Anthropic, OpenAI-compatible HTTP/SSE endpoints, or local model servers directly.
Core codec transport@sockudo/ai-transportCustom model protocols, custom UI projections, or non-Vercel message shapes.
You haveUse
Vercel AI SDK streamText already wired@sockudo/ai-transport/vercel
A provider with OpenAI-compatible SSEcreateOpenAICompatibleProvider
Official OpenAI SDKcreateOpenAISdkProvider
Official Anthropic SDKcreateAnthropicSdkProvider
A custom internal model gatewayDirectLlmProvider
A non-Vercel UI modelCore codec API from @sockudo/ai-transport
AI SDK agent or workflow outputConvert to UI message chunks, then stream through the Vercel transport
Realtime voice or generated videoProvider 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.

User client
Sockudo
Agent worker
Model provider
History store
1ai-input on the session channel
2persist the user message
3stream request
4deltas, tool calls, finish
5create and append ai-output
6persist every mutation
7live rolled-up appends
a refreshed client rewinds history instead
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:

server/api/chat.post.ts
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:

src/chat.ts
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 capabilitySockudo behavior
Reasoning controlsPass model options through streamText; Sockudo carries emitted reasoning text and reasoning-file chunks.
Tool context and runtime contextKeep context on the trusted worker. Publish only safe derived metadata, never provider secrets or raw tool credentials.
Provider file and skill uploadsLet 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 partsPreserve custom chunks and provider metadata. Rendering app iframes or custom widgets remains a client responsibility.
Tool approvalsPersist approval requests and responses as normal run state. The app still owns approval policy, signature checks, and tool execution authorization.
WorkflowAgent and HarnessAgent outputStream their UI-message output through toUIMessageStream. Use the workflow store for agent checkpoints and Sockudo for transcript/reconnect history.
Realtime voiceKeep low-latency audio on the provider’s realtime channel. Mirror transcripts, tool calls, approvals, and final state through Sockudo.
Video generationStore generated media outside Sockudo and publish progress, asset URLs, thumbnails, or final file parts through the AI session channel.
Telemetry and lifecycle callbacksCorrelate 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 pathFunctionNotes
OpenAI-compatible HTTP/SSEstreamOpenAICompatibleTextUses Chat Completions-compatible /chat/completions streaming.
OpenAI-compatible reusable providercreateOpenAICompatibleProviderGood for named provider registries.
OpenAI SDK Chat CompletionsstreamOpenAIChatCompletion / createOpenAISdkProviderUses a structural subset of the official OpenAI SDK.
OpenAI SDK ResponsesstreamOpenAIResponse / createOpenAISdkProvider({ mode: "responses" })Maps output text and tool argument deltas to UI chunks.
Anthropic SDK MessagesstreamAnthropicMessage / createAnthropicSdkProviderMaps text, thinking, tool use, and finish reasons.

OpenAI-compatible presets are:

NameDefault base URL
openaihttps://api.openai.com/v1
openrouterhttps://openrouter.ai/api/v1
groqhttps://api.groq.com/openai/v1
togetheraihttps://api.together.xyz/v1
fireworkshttps://api.fireworks.ai/inference/v1
deepseekhttps://api.deepseek.com
perplexityhttps://api.perplexity.ai
mistralhttps://api.mistral.ai/v1
xaihttps://api.x.ai/v1
ollamahttp://127.0.0.1:11434/v1
lmstudiohttp://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.

worker/groq-agent.ts
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

worker/openai-agent.ts
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:

worker/openai-responses-agent.ts
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

worker/anthropic-agent.ts
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.

worker/providers.ts
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.

worker/echo-provider.ts
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.

Agent
Sockudo
Web client
Tool executor
1tool-input-start + deltas
2pending approval appears
3approval response
4tool output
5continue ai-output append
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:

  1. The agent streams a tool-approval-request chunk with a stable approval id and tool call id.

  2. Sockudo stores that request on the ai-output mutable message and fans it out to every attached client.

  3. 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-response input.

  4. The worker verifies the response, runs or denies the tool, then appends tool-result, tool-result-error, or output-denied state.

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.

Next steps