bitsrun

Use the API

Every endpoint is an OpenAI-compatible API at its own address, so existing OpenAI code works after you change the base URL and the key.

On this page

Each endpoint you deploy gets its own web address, called the base URL. It looks like this:

https://01k8y4000d3m00000000000011.endpoint.bitsrun.com/v1

The part before .endpoint is your endpoint id. You find the full URL on the endpoint's card in the dashboard (with a Copy button), or with bitsrun status <endpoint> in the terminal.

Your code sends an API key with every request. An API key is a secret that proves the request comes from you. Create one on the API keys page; see API keys.

What the API answers

PathMethodWhat it doesWorks on
/v1/chat/completionsPOSTChat: send messages, get the next reply. Streaming and tool calls supportedChat models
/v1/completionsPOSTPlain text completion from a promptChat models
/v1/embeddingsPOSTTurns text into vectors (lists of numbers) for search and RAGEmbedding models
/v1/modelsGETLists the one model this endpoint servesEvery endpoint

GGUF models also answer the native Ollama paths (/api/chat, /api/generate, /api/embed, /api/embeddings, /api/tags) on the same host without /v1, so Ollama libraries that can send the Authorization header work too (the ollama command line app cannot). See Chat and completions.

Any other path answers 404. Endpoints that only run embeddings answer only /v1/embeddings and /v1/models.

Your first call

Set your key once in your terminal, then call the endpoint:

bash
export BITSRUN_API_KEY="brk_..."

curl https://01k8y4000d3m00000000000011.endpoint.bitsrun.com/v1/chat/completions \
  -H "Authorization: Bearer $BITSRUN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen3:8b", "messages": [{"role": "user", "content": "Say hello in five words."}]}'

The same call with the official OpenAI SDKs:

python
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://01k8y4000d3m00000000000011.endpoint.bitsrun.com/v1",
    api_key=os.environ["BITSRUN_API_KEY"],
)
reply = client.chat.completions.create(
    model="qwen3:8b",
    messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(reply.choices[0].message.content)
javascript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://01k8y4000d3m00000000000011.endpoint.bitsrun.com/v1",
  apiKey: process.env.BITSRUN_API_KEY,
});
const reply = await client.chat.completions.create({
  model: "qwen3:8b",
  messages: [{ role: "user", content: "Say hello in five words." }],
});
console.log(reply.choices[0].message.content);

When the endpoint is asleep

An endpoint sleeps when nobody uses it, and the first request wakes it. That start takes a few seconds on a warm GPU and a few minutes when a new GPU starts. You are never billed for it. How your request behaves while it waits:

  • Every request stays open and waits for the model, up to 8 minutes, then answers normally. Streaming requests get keep-alive comments while they wait; other requests get spaces before the JSON, which JSON parsers skip.
  • After 8 minutes, or if the model fails to start, the answer has status 200 and an error body (model_starting or model_unavailable). Send the request again.
  • Header X-BitsRun-Wait: 0: a request that finds the model asleep gets 503 with the code model_starting and a Retry-After: 30 header after about 45 seconds instead.

Read Cold starts for timings and how to avoid them.

Errors

Every error has the same shape: a stable code your code can check, a friendly message, and a requestId to send to support.

json
{
  "error": {
    "code": "payment_required",
    "message": "Your credit balance has run out. Add credit in the dashboard to continue.",
    "requestId": "01k9a2b3c4d5e6f7g8h9j0k1m2"
  }
}

The full list, with what each one means and how to fix it, is on Error codes.

Pages in this section

View as MarkdownUpdated

Still stuck?

Email support@bitsrun.com with what you tried and any request id you saw. A real person answers.