Quickstarts
Quickstart: AI Gateway
One OpenAI-compatible API with your provider keys, budgets and caching.
Add a provider (BYOK), create an hbai_… key and use any OpenAI SDK.
Variables used below: $HOSTBASE_TOKEN (access token), $REF (project ref). SDKs: @hostbase/management (TypeScript) and hostbase_management (Python); full reference at /docs/api.
1. Add a provider and a key
The provider key is encrypted and never returned by the API.
curl -X PUT https://host.ulewicz.space/api/v1/projects/$REF/ai-gateway/providers -H "Authorization: Bearer $HOSTBASE_TOKEN" -H "Content-Type: application/json" -d '{"provider":"openai","api_key":"sk-..."}'
curl -X POST https://host.ulewicz.space/api/v1/projects/$REF/ai-gateway/keys -H "Authorization: Bearer $HOSTBASE_TOKEN" -H "Content-Type: application/json" -d '{"name":"backend"}'const key = await hb.createAiKey({ ref, body: { name: "backend" } as never });key = hb.create_ai_key(ref=ref, body={"name": "backend"})2. Call a model
Only the base URL changes.
curl https://host.ulewicz.space/api/ai/v1/chat/completions -H "Authorization: Bearer $HBAI_KEY" -H "Content-Type: application/json" \
-d '{"model":"gpt-4o-mini","messages":[{"role":"user","content":"Hello"}]}'import OpenAI from "openai";
const ai = new OpenAI({ baseURL: "https://host.ulewicz.space/api/ai/v1", apiKey: process.env.HBAI_KEY });
const r = await ai.chat.completions.create({ model: "gpt-4o-mini", messages: [{ role: "user", content: "Hello" }] });from openai import OpenAI
ai = OpenAI(base_url="https://host.ulewicz.space/api/ai/v1", api_key=os.environ["HBAI_KEY"])
ai.chat.completions.create(model="gpt-4o-mini", messages=[{"role": "user", "content": "Hello"}])3. Usage
Requests, tokens, cost and cache hits.
curl "https://host.ulewicz.space/api/v1/projects/$REF/ai-gateway/usage?range=7d" -H "Authorization: Bearer $HOSTBASE_TOKEN"const usage = await hb.getAiUsage({ ref, query: { range: "7d" } });usage = hb.get_ai_usage(ref=ref, query={"range": "7d"})Next: /docs/ai-gateway.