Use Antseed with the Vercel AI SDK
Use @ai-sdk/openai-compatible to call Antseed from generateText / streamText.
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 (
ai7 requires it)
Step 1
Install Vercel AI SDK
- Create an ES module project and install the SDK and the openai-compatible providernpm 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 tsxfails with "Top-level await is currently not supported with the "cjs" output format".zodis only needed for structured output (structured.ts).
Step 2
Point Vercel AI SDK at Antseed
Recommended: a gateway
| ANTSEED_BASE_URL | https://gateway.example.com/v1 |
| ANTSEED_API_KEY | antseed_… |
Show as shell exports
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.
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.
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
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.tsExample outputThe 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 - checkGET /v1/models. A401meansANTSEED_API_KEYis missing or not a valid gateway key. - Check structured outputnpx tsx structured.tsExample 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/completionson your gateway or buyer proxy) - Best-fit services: any service whose
protocolsarray containsopenai-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> --jsonand look atproviderServiceApiProtocols[provider].services[service]. The browse command exposes the same field per peer. - What happens when protocols don't match: Antseed's
@antseed/api-adaptertranslates 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 advertisesanthropic-messages- just with a small transform step. - One known caveat: services whose only advertised protocol is
openai-responsesrequire streaming. If Vercel AI SDK sends a non-streaming request and Antseed routes it to one of those services, the call fails withHTTP 400: Stream must be set to true. Pick a service whoseprotocolsincludesopenai-chat-completions(or another non-responses protocol) to avoid this.
If it goes wrong
Troubleshooting
- TypeScript complains that
antseedhas no call signatureYou imported from@ai-sdk/openaiinstead 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 schemaWithoutsupportsStructuredOutputs: trueoncreateOpenAICompatible, 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 inantseed.tsabove, to send the schema asjson_schema. If it still fails, the seller that served the call ignores JSON schemas: pick a model whose offers inGET /v1/modelsliststructuredOutput: trueundercapabilities, or pin such a seller with<peerId>@<id>.includeUsageis set butresult.usageis undefinedSome upstream providers behind Antseed do not emit usage on streamed responses. TrygenerateTextinstead ofstreamTextfor definitive token counts; the gateway console's Logs page (orantseed buyer meteringwith a local buyer) shows the tokens and cost Antseed measured.- Browser/edge runtime fails with
fetcherrorsCall 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 on127.0.0.1.
Reference
Links
Same category