Quickstart

Get started in 5 minutes

Three steps: get an API key, install the SDK, make your first call. Everything else is optional.

Step 1 — Get your API key

Create a free account at belugapi.com. Once registered, navigate to Dashboard → API Keys → New Key. Your key looks like bapi_xxxxxxxxxxxxx.

Keep it secret. Never commit your API key to git or expose it in client-side JavaScript. Use environment variables.

Store it as an env variable

export BELUGAPI_KEY="bapi_your_key_here"
BELUGAPI_KEY=bapi_your_key_here

Step 2 — Install the SDK

BelugAPI is OpenAI-compatible. Install the official OpenAI SDK for your language.

pip install openai
npm install openai
# No installation needed — use curl or any HTTP client

Step 3 — Your first chat call

Point the SDK at https://api.belugapi.com/v1 — that's the only change you need.

import os
from openai import OpenAI

client = OpenAI(
    api_key=os.getenv("BELUGAPI_KEY"),
    base_url="https://api.belugapi.com/v1",
)

response = client.chat.completions.create(
    model="gpt-5.4",
    messages=[
        {"role": "system",  "content": "You are a helpful assistant."},
        {"role": "user",    "content": "What is BelugAPI?"},
    ],
)

print(response.choices[0].message.content)
# Usage info
print(response.usage.total_tokens, "tokens")
import OpenAI from "openai";

const client = new OpenAI({
  apiKey:  process.env.BELUGAPI_KEY,
  baseURL: "https://api.belugapi.com/v1",
});

const res = await client.chat.completions.create({
  model:    "gpt-5.4",
  messages: [
    { role: "system", content: "You are a helpful assistant." },
    { role: "user",   content: "What is BelugAPI?" },
  ],
});

console.log(res.choices[0].message.content);
console.log(res.usage?.total_tokens, "tokens");
curl https://api.belugapi.com/v1/chat/completions \
  -H "Authorization: Bearer $BELUGAPI_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user",   "content": "What is BelugAPI?"}
    ]
  }'

Streaming responses

Add "stream": true to receive tokens as Server-Sent Events (SSE) — same as OpenAI.

with client.chat.completions.stream(
    model="gpt-5.4",
    messages=[{"role": "user", "content": "Tell me a short story."}],
) as stream:
    for chunk in stream.text_stream:
        print(chunk, end="", flush=True)
const stream = await client.chat.completions.stream({
  model:    "gpt-5.4",
  messages: [{ role: "user", content: "Tell me a short story." }],
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Next steps