Use AntSeed with the Vercel AI SDK
Use @ai-sdk/openai-compatible to call AntSeed from generateText / streamText / generateObject.
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, streamText, generateObject, or streamObject. The AI SDK handles tool-calling, structured output, message history, and streaming for you.
How AntSeed plugs in. AntSeed is OpenAI-Chat-compatible at http://localhost:8377/v1, 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 point it at the AntSeed proxy with baseURL and pass any non-empty apiKey placeholder - the proxy authenticates with your local identity key, not with this header.
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 curl http://localhost:8377/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 assumes a buyer proxy at http://localhost:8377. One-time setup, ~2 minutes.
Before you start
Prerequisites
- Node.js 18 or newer
Step 1
Install Vercel AI SDK
- Install the SDK and the openai-compatible providernpm install ai @ai-sdk/openai-compatible zod
zodis only needed if you callgenerateObject/streamObject. Skip it for plain text generation.
Step 2
Point Vercel AI SDK at AntSeed
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 http://localhost:8377/v1/models | 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 curl -s localhost:8377/v1/models, 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 is blue because shorter (blue) wavelengths of sunlight scatter much more than longer (red) wavelengths in Earth's atmosphere… usage: { promptTokens: 14, completionTokens: 78, totalTokens: 92 }
If you see
502 model_not_found, no policy-allowed peer currently advertises the id you passed - checkcurl localhost:8377/v1/models.no_peer_pinnedonly occurs on proxies older than this release, or when the request carries no model at all - upgrade the CLI and/or pass a model id. - 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. The header overrides the session pin for that single call.
How Vercel AI SDK talks to AntSeed
- Wire format sent by Vercel AI SDK:
OpenAI Chat Completions(hits/v1/chat/completionson the 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. 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 the proxy 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. generateObjectreturns malformed JSONThe AI SDK is strict about JSON Schema support. PasssupportsStructuredOutputs: truetocreateOpenAICompatibleonly if the routed service supports OpenAI-style structured outputs natively. If unsure, leave it off - the SDK falls back to tool-call-based JSON which works everywhere.includeUsageis set butresult.usageis undefinedSome upstream providers behind AntSeed do not emit usage on streamed responses. TrygenerateTextinstead ofstreamTextfor definitive token counts; otherwise runantseed buyer meteringfor the authoritative per-channel token + USDC totals AntSeed itself measured.- Browser/edge runtime fails with
fetcherrorsThe AntSeed proxy listens on127.0.0.1:8377, which is not reachable from a browser tab on a deployed site. The AI SDK is designed to run on the server (Route Handlers, Server Actions, edge functions on your own machine, or a Node process); don't call it from a client component when the model is AntSeed.
Reference
Links
Same category