Skip to main content
▲

Use Antseed with the Vercel AI SDK

Use @ai-sdk/openai-compatible to call Antseed from generateText / streamText.

FrameworksOpenAI Chat Completions~5 min

What the AI SDK is. Vercel's ai package is a provider-agnostic TypeScript toolkit for building LLM apps and agents. You pick a provider (a small adapter package), instantiate a model from it, and pass that model into one of the framework's primitives: generateText or streamText, with an output setting for structured data. The AI SDK handles tool-calling, structured output, message history, and streaming for you.

How Antseed plugs in. Your Antseed gateway is OpenAI-Chat-compatible at its /v1 URL, so the right adapter is @ai-sdk/openai-compatible (not @ai-sdk/openai). The official OpenAI provider is locked to OpenAI's API surface and quietly drops third-party fields; the openai-compatible provider is the one Vercel's own docs recommend for proxies, gateways, and any non-OpenAI server that speaks Chat Completions. You pass the gateway URL as baseURL and a gateway key as apiKey, which the SDK sends as Authorization: Bearer. On the same computer as a buyer you can use the local buyer proxy instead (http://localhost:8377/v1, any non-empty key).

Which model ids work. The first argument to the provider call is a model id from the Antseed catalog (e.g. deepseek-v4-flash, kimi-k2.6). Any model on the network works - list them with GET /v1/models. To route to a specific peer per call, prefix that peer offer's service id: <peerId>@deepseek-v4-flash.

Run Antseed first

Every integration needs an Antseed endpoint: a gateway, best on a small server so every tool on every machine can reach it, or the local buyer proxy (same computer only). One-time setup, a few minutes.

Before you start

Prerequisites

  • Node.js 22 or newer (ai 7 requires it)

Step 1

Install Vercel AI SDK

  • Create an ES module project and install the SDK and the openai-compatible provider
    npm init -y npm pkg set type=module npm install ai @ai-sdk/openai-compatible zod

    The examples below use top-level await, which only works in an ES module, so the package needs "type": "module". Without it, npx tsx fails with "Top-level await is currently not supported with the "cjs" output format". zod is only needed for structured output (structured.ts).

Step 2

Point Vercel AI SDK at Antseed

Recommended: a gateway

ANTSEED_BASE_URLhttps://gateway.example.com/v1
ANTSEED_API_KEYantseed_…
Show as shell exports
export ANTSEED_BASE_URL="https://gateway.example.com/v1" export ANTSEED_API_KEY="antseed_…"

Your gateway's base URL, ending in /v1, and an API key from the Keys page of its console. Recommended: a gateway on a server, which every machine can reach. A gateway on this computer is http://localhost:8379/v1; publish it with a tunnel (antseed tunnel start) for other machines. No gateway yet: see Run Antseed first above.

// antseed.ts - a single provider instance you can import everywhere import { createOpenAICompatible } from '@ai-sdk/openai-compatible'; export const antseed = createOpenAICompatible({ name: 'antseed', baseURL: process.env.ANTSEED_BASE_URL!, // gateway URL ending in /v1 apiKey: process.env.ANTSEED_API_KEY!, // gateway key, sent as Authorization: Bearer includeUsage: true, // surface token counts in streaming responses too supportsStructuredOutputs: true, // send the zod schema as a JSON schema (structured.ts) });

Same computer as a buyer, no gateway: baseURL: 'http://localhost:8377/v1' and any non-empty apiKey, such as 'antseed'; the local proxy checks no key.

// stream.ts import { streamText } from 'ai'; import { antseed } from './antseed'; const result = streamText({ model: antseed('deepseek-v4-flash'), // an Antseed catalog model id // model: antseed('<peerId>@deepseek-v4-flash'), // …or pin a specific peer prompt: 'Why is the sky blue?', }); for await (const chunk of result.textStream) { process.stdout.write(chunk); } const { inputTokens, outputTokens } = await result.usage; console.log(`\ntokens: ${inputTokens} in, ${outputTokens} out`);
// structured.ts - a typed object instead of text import { generateText, Output } from 'ai'; import { z } from 'zod'; import { antseed } from './antseed'; const { output } = await generateText({ model: antseed('deepseek-v4-flash'), output: Output.object({ schema: z.object({ title: z.string(), bullets: z.array(z.string()).min(3).max(5), }), }), prompt: 'Make one slide that explains why the sky is blue.', }); console.log(output);

generateObject and streamObject still work but are deprecated in ai 7; Output.object replaces them. The schema is only enforced because antseed.ts sets supportsStructuredOutputs: true.

Step 3

Pick a model

deepseek-v4-flashkimi-k2.6gpt-oss-120bglm-5.2

The string you pass to antseed('<id>') is forwarded verbatim as model in the OpenAI Chat request. Run curl -s "$ANTSEED_BASE_URL/models" -H "Authorization: Bearer $ANTSEED_API_KEY" | jq '.data[].id' to list every model on the network. antseed('<peerId>@<id>') routes that one call to a specific peer.

The full list is every model on the network. Run GET /v1/models on your endpoint, antseed network browse, or open the live network page to see what's available right now.

Verify

Test it

  • Run a smoke test with `tsx`
    npx tsx stream.ts
    Example output
    The sky appears blue due to a phenomenon called **Rayleigh scattering**… tokens: 1698 in, 215 out

    If you see 502 model_not_found, no seller your routing policy allows currently advertises the id you passed - check GET /v1/models. A 401 means ANTSEED_API_KEY is missing or not a valid gateway key.

  • Check structured output
    npx tsx structured.ts
    Example output
    { title: 'Why the Sky Is Blue', bullets: [ 'Sunlight appears white but contains all colors of the rainbow.', … ] }
  • Per-request peer override (no session pin needed)
    // Use `headers` to fan out to different peers per call. const result = streamText({ model: antseed('deepseek-v4-flash'), prompt: 'hi', headers: { 'x-antseed-pin-peer': 'cccccccccccccccccccccccccccccccccccccccc', }, }); // Equivalent without headers: antseed('cccccccccccccccccccccccccccccccccccccccc@deepseek-v4-flash')

    Useful when one Node process serves many tenants and you want each request routed to a different peer. Gateway routing policies still apply to a pinned request.

How Vercel AI SDK talks to Antseed

  • Wire format sent by Vercel AI SDK: OpenAI Chat Completions (hits /v1/chat/completions on your gateway or buyer proxy)
  • Best-fit services: any service whose protocols array contains openai-chat-completions. That's what the peer advertises as natively-supported - zero translation overhead, no transform edge cases.
  • How to check a peer: run antseed network peer <peerId> --json and look at providerServiceApiProtocols[provider].services[service]. The browse command exposes the same field per peer.
  • What happens when protocols don't match: Antseed's @antseed/api-adapter translates between OpenAI Chat Completions and the service's native protocol on the fly, inside the buyer. So a request from Vercel AI SDK can still reach a service that only advertises anthropic-messages - just with a small transform step.
  • One known caveat: services whose only advertised protocol is openai-responses require streaming. If Vercel AI SDK sends a non-streaming request and Antseed routes it to one of those services, the call fails with HTTP 400: Stream must be set to true. Pick a service whose protocols includes openai-chat-completions (or another non-responses protocol) to avoid this.

If it goes wrong

Troubleshooting

  • TypeScript complains that antseed has no call signatureYou imported from @ai-sdk/openai instead of @ai-sdk/openai-compatible. Switch the package - the SDK's official OpenAI provider is locked to OpenAI's service ids and rejects unknown ones.
  • NoObjectGeneratedError: No object generated: response did not match schemaWithout supportsStructuredOutputs: true on createOpenAICompatible, the provider asks only for JSON (response_format: json_object) and never sends your schema, so the model invents its own fields. Set it, as in antseed.ts above, to send the schema as json_schema. If it still fails, the seller that served the call ignores JSON schemas: pick a model whose offers in GET /v1/models list structuredOutput: true under capabilities, or pin such a seller with <peerId>@<id>.
  • includeUsage is set but result.usage is undefinedSome upstream providers behind Antseed do not emit usage on streamed responses. Try generateText instead of streamText for definitive token counts; the gateway console's Logs page (or antseed buyer metering with a local buyer) shows the tokens and cost Antseed measured.
  • Browser/edge runtime fails with fetch errorsCall Antseed from server code (Route Handlers, Server Actions, a Node process), never from a client component: the gateway key is a bearer secret and must not ship to the browser. Deployed functions need a gateway they can reach (a server or tunnel URL); the local buyer proxy only listens on 127.0.0.1.

Reference

Links

Same category

Related

Run Vercel AI SDK on the open market

Run a gateway, point this tool at it, and pay per request.

All integrationsGateway API