Skip to main content

Install Omni in Vercel AI SDK

AI SDK 6 split MCP support out of the ai core into the dedicated @ai-sdk/mcp package. It speaks streamable HTTP, accepts custom headers, and returns AI-SDK-compatible tools that any Anthropic, OpenAI, or other model can call.

Prerequisites

  • Omni API key (free — 250 calls/month). Sign up at secapi.ai. Set OMNI_DATASTREAM_API_KEY.
  • Node.js ≥ 18 with ai ≥ 6.0, @ai-sdk/mcp ≥ 1.0, and a model SDK (e.g. @ai-sdk/anthropic ≥ 3.0).

Install

npm install ai @ai-sdk/anthropic @ai-sdk/mcp
import { createMCPClient } from "@ai-sdk/mcp";
import { generateText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

const mcp = await createMCPClient({
  transport: {
    type: "http",
    url: "https://api.secapi.ai/mcp",
    headers: { "x-api-key": process.env.OMNI_DATASTREAM_API_KEY! },
  },
});

try {
  const tools = await mcp.tools();
  const { text } = await generateText({
    model: anthropic("claude-sonnet-4-5"),
    tools,
    prompt: "Show me Apple's latest 8-K filing.",
  });
  console.log(text);
} finally {
  await mcp.close();
}

Verify

Run the snippet. The agent should call the filings.latest tool with ticker: AAPL, form: 8-K and print the filing URL plus a short summary.

Troubleshooting

  • 401 Unauthorizedx-api-key is missing or wrong. Sanity check: curl https://api.secapi.ai/v1/limits -H "x-api-key: $OMNI_DATASTREAM_API_KEY".
  • 429 Too Many Requests — rate limit hit. See GET https://api.secapi.ai/v1/billing for your plan’s cap.
  • Process hangs after first call — always await mcp.close() in a finally block (or in onFinish and onError if you use streaming). Open SSE connections will keep the event loop alive.
  • Cannot find module '@ai-sdk/mcp' — you’re on AI SDK ≤ 5; either upgrade to ai ≥ 6 or use the legacy experimental_createMCPClient import from ai.

Streaming variant

For streamText, close the client in both callbacks:
const { textStream } = await streamText({
  model: anthropic("claude-sonnet-4-5"),
  tools: await mcp.tools(),
  prompt: "Show me Apple's latest 8-K filing.",
  onFinish: () => mcp.close(),
  onError: () => mcp.close(),
});

Next