Most gateways and model servers accept OpenAI’s Chat Completions request and return its streaming format. For all of them the code is the same; only the URL, the key and the model id change.
import { prompt } from "@gistui/catalog";
import { textDeltas, toReadable } from "@gistui/server";
const URL = "https://ai-gateway.vercel.sh/v1/chat/completions";
const KEY = process.env.AI_GATEWAY_API_KEY;
const MODEL = "openai/gpt-oss-120b";
export async function POST(req: Request) {
const { messages } = await req.json();
const res = await fetch(URL, {
method: "POST",
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
model: MODEL,
stream: true,
messages: [{ role: "system", content: prompt().text }, ...messages],
}),
});
if (!res.ok) return new Response(await res.text(), { status: res.status });
return new Response(toReadable(textDeltas(res, "openai")));
}Endpoints
| Service | URL | Model id looks like |
|---|---|---|
| Vercel AI Gateway | https://ai-gateway.vercel.sh/v1/chat/completions |
openai/gpt-oss-120b |
| OpenRouter | https://openrouter.ai/api/v1/chat/completions |
google/gemini-3.7-flash |
| Groq | https://api.groq.com/openai/v1/chat/completions |
openai/gpt-oss-120b |
| Together | https://api.together.xyz/v1/chat/completions |
the provider’s model name |
| Ollama (local) | http://localhost:11434/v1/chat/completions |
qwen3:8b |
| vLLM, LM Studio, llama.cpp | your server’s /v1/chat/completions |
whatever you loaded |
Model ids change often: check the service’s own list.
Local models
A local server needs no key. Small models follow the prompt less exactly; two things help.
- A smaller prompt. Leave out the groups you do not need:
prompt({ groups: ["Layout", "Content", "Data"] }). - Autofix. It is on by default in every renderer and repairs most slips in code. See Autofix and repair.
In a chat
The openai() adapter of @gistui/chat speaks to any of these through your endpoint:
import { createChat, openai } from "@gistui/chat";
const store = createChat({ adapter: openai({ model: "openai/gpt-oss-120b", url: "/api/chat" }) });