/ How to use Netra Runtime with the Vercel AI SDK
How to use Netra Runtime with the Vercel AI SDK
Published:
Last updated:
The Vercel AI SDK is the standard TypeScript toolkit for AI apps: generateText and streamText on the server, useChat in React. Its provider system has a dedicated package for OpenAI-style endpoints, so an app built on the AI SDK can run against a model served by Netra Runtime by swapping the provider object and nothing else.
What you need
- The packages:
npm install ai @ai-sdk/openai-compatible(see the OpenAI-compatible provider docs). - A Netra Runtime API key from your dashboard at app.netra.sh. The API base URL is
https://api.netra.sh/v1(self-hosted deployments use their own endpoint URL instead).
Step 1: create the provider
Create a provider once and reuse it everywhere in your app:
import { createOpenAICompatible } from "@ai-sdk/openai-compatible"
export const netra = createOpenAICompatible({
name: "netra",
baseURL: "https://api.netra.sh/v1",
apiKey: process.env.NETRA_API_KEY,
})
Step 2: generate and stream
Pass a model instance to the AI SDK functions as usual:
import { generateText, streamText } from "ai"
import { netra } from "./netra"
const { text } = await generateText({
model: netra("qwen3.6-35b"),
prompt: "Say hello from Netra Runtime.",
})
const result = streamText({
model: netra("qwen3.6-35b"),
prompt: "Explain continuous batching in two sentences.",
})
for await (const chunk of result.textStream) {
process.stdout.write(chunk)
}
In a Next.js route handler, return result.toUIMessageStreamResponse() and useChat on the client renders the stream token by token. Token streaming is where fast inference shows: time-to-first-token is what the user feels on every message.
Notes
- Tool calling and structured output.
toolsandgenerateObjectwork if your deployed model supports tool calling and JSON output; the SDK sends both in standard OpenAI format. - Keep the key server-side. Create the provider only in server code (route handlers, server actions) so
NETRA_API_KEYnever reaches the browser. - The @ai-sdk/openai package also works.
createOpenAI({ baseURL, apiKey })targets the same endpoints, but the openai-compatible package makes no OpenAI-specific assumptions, so prefer it for custom backends.
Frequently asked questions
Which AI SDK package do I use for Netra Runtime?
Use @ai-sdk/openai-compatible and its createOpenAICompatible factory. It is built for third-party OpenAI-style endpoints and makes no OpenAI-specific assumptions about model names or features.
Does streaming with useChat work on Netra Runtime?
Yes. streamText consumes the OpenAI-style streaming protocol Netra Runtime emits, and useChat renders it in React, so chat UIs stream token by token unchanged.
Can I use AI SDK tool calling with a Netra-served model?
Yes, if the model you deployed supports tool calling. The SDK sends tools in the standard OpenAI format, which Netra's API passes through to the model.