This page shows how to use a custom OpenAI endpoint in the Vercel AI SDK, so your TypeScript app calls an open model you deployed on BitsRun. At the end you will generate text, stream it and create embeddings with the SDK's usual functions. It takes about 10 minutes once you have an endpoint.
Checked against the AI SDK docs on ai-sdk.dev on 2026-11-14.
What you get
| Package | @ai-sdk/openai-compatible with createOpenAICompatible |
| Functions | generateText, streamText, embed |
| API used | Chat Completions (/v1/chat/completions) and /v1/embeddings |
| Tool calls | Supported, with a model trained for tools |
| Cost when idle | Nothing. The endpoint sleeps and wakes on the next request |
Which provider should I use: openai-compatible or createOpenAI?
Use @ai-sdk/openai-compatible. The AI SDK's own OpenAI provider calls OpenAI's Responses API by default, and BitsRun answers the Chat Completions API. The OpenAI provider docs say that if your custom base URL only supports Chat Completions, you should create models with openai.chat('model-id') or use the OpenAI-compatible provider. The OpenAI-compatible provider is the simpler choice and is what this page uses.
Before you start
- A BitsRun endpoint. Follow Deploy your first model or Deploy an Ollama model to the cloud.
- Its base URL,
https://<endpoint-id>.endpoint.bitsrun.com/v1, from the Copy button on the endpoint card.<endpoint-id>is your endpoint's id. - An API key starting with
brk_(see API keys). - Node.js and a project with ES modules.
How to set up the Vercel AI SDK with a custom endpoint
Install the packages:
bashnpm install ai @ai-sdk/openai-compatibleSave your key in an environment variable (or your host's secret settings):
bashexport BITSRUN_API_KEY="brk_your_key"Create
generate.mjs. This is thegenerateTextexample from the AI SDK docs, with our name, key, base URL and model:javascriptimport { createOpenAICompatible } from '@ai-sdk/openai-compatible'; import { generateText } from 'ai'; const provider = createOpenAICompatible({ name: 'bitsrun', apiKey: process.env.BITSRUN_API_KEY, baseURL: 'https://<endpoint-id>.endpoint.bitsrun.com/v1', }); const { text } = await generateText({ model: provider('qwen3:8b'), prompt: 'Write a vegetarian lasagna recipe for 4 people.', }); console.log(text);Run
node generate.mjs. You should see the recipe printed after a few seconds (longer if the endpoint was asleep).
apiKey is sent as Authorization: Bearer <key>, which is what BitsRun expects. The model name is the one you deployed; an endpoint serves exactly one model and always uses it.
How to stream text with streamText
Streaming shows words as the model writes them, so people see a reply right away:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { streamText } from 'ai';
const provider = createOpenAICompatible({
name: 'bitsrun',
apiKey: process.env.BITSRUN_API_KEY,
baseURL: 'https://<endpoint-id>.endpoint.bitsrun.com/v1',
includeUsage: true, // Include usage information in streaming responses
});
const { textStream } = streamText({
model: provider('qwen3:8b'),
prompt: 'Invent a new holiday and describe its traditions.',
});
for await (const textPart of textStream) {
process.stdout.write(textPart);
}How to create embeddings
Point a second provider at an embedding endpoint and use embeddingModel:
import { createOpenAICompatible } from '@ai-sdk/openai-compatible';
import { embed } from 'ai';
const provider = createOpenAICompatible({
name: 'bitsrun',
apiKey: process.env.BITSRUN_API_KEY,
baseURL: 'https://<embedding-endpoint-id>.endpoint.bitsrun.com/v1',
});
const { embedding } = await embed({
model: provider.embeddingModel('snowflake-arctic-embed-l-v2.0'),
value: 'The quick brown fox jumps over the lazy dog',
});See Self-hosted embeddings API for choosing and deploying an embedding model.
What happens on the first request after the endpoint sleeps
A sleeping endpoint wakes on the next request, and the wait is never billed.
| Model kind | Warm GPU (ran recently) | New GPU machine |
|---|---|---|
| GGUF models on llama.cpp | A few seconds to about 40 seconds | About 2 to 3 minutes |
| Embedding models on Text Embeddings Inference | A few seconds to about 40 seconds | About 2 to 3 minutes |
| Safetensors chat models on vLLM | About 40 seconds | About 3 to 4 minutes |
BitsRun keeps the request open for up to 8 minutes and sends keep-alive data while it waits. If you use the timeout option, give it at least 10 minutes (timeout: 600000), and do not set short timeout.firstChunkMs or timeout.chunkMs values on streamText: keep-alive comments are not content, so a short value would abort during a cold start. Your hosting platform's function time limit matters too. If it is shorter than a cold start, wake the endpoint first with Start on the endpoint card. More on Cold starts.
If something goes wrong
| Message or symptom | What to do |
|---|---|
401 unauthorized | BITSRUN_API_KEY is missing, mistyped or revoked. Check the variable in the environment that runs the code. |
404 not_found | Check baseURL ends in /v1. Chat calls on an embedding endpoint, or a key limited to another endpoint, also get 404. |
402 payment_required | Your balance is $0. Add credit in the dashboard. |
429 rate_limited | Too many requests open at once for your plan. Retry with a short, growing pause. |
Error body with model_starting | The model took longer than 8 minutes to wake. Send the request again. |
| Request aborted during a cold start | Your timeout or the platform's function limit is too short. Raise it or start the endpoint first. |
Every code is on Error codes.
Frequently asked questions
Does the Vercel AI SDK work with self-hosted models?
Yes. Any server that speaks the OpenAI Chat Completions API works with @ai-sdk/openai-compatible. Deploy the model on BitsRun and pass its base URL and brk_ key to createOpenAICompatible.
Do tool calls work with the AI SDK and BitsRun?
Yes, with a model trained for tools. BitsRun passes tools, tool_choice and parallel_tool_calls; check your model with bitsrun size <model> --json and look for "tools": true.
Can I use createOpenAI with a baseURL instead?
Yes, but call openai.chat('model-id') so it uses Chat Completions. The default openai('model-id') uses the Responses API, which BitsRun does not answer.
Can I send images to my model?
Not yet. BitsRun serves text-only models today, so send text prompts only.
Next step
Estimate what your app will cost with the cost calculator, or bring your own weights with Host a GGUF model as an OpenAI-compatible API. Then create your account.