Your first request

Authenticate#

Each product has a key issued by the operator. Send it in one of two headers:

Authorization: Bearer <product key>
X-Api-Key: <product key>

A missing key and a wrong key both give 401 {"error":"unauthorized"}.

The API listens on the server's internal network, at the address your operator gives you, written here as $BLACKGATE_URL. All bodies are JSON, except audio transcription, which is multipart. Every response carries Cache-Control: no-store.

Ask for a completion#

curl -sS "$BLACKGATE_URL"/v1/complete \
  -H "Authorization: Bearer $BLACKGATE_KEY" \
  -H "Content-Type: application/json" \
  -d '{"tier":"fast","messages":[{"role":"user","content":"Say ok"}],"max_tokens":16,"subject":"myproduct:bot:support"}'
{
  "content": "ok",
  "model": "<model name>",
  "pool": "<pool name>",
  "rung": 0,
  "tier": "fast",
  "attempts": [
    { "rung": 0, "model": "<model name>", "pool": "<pool name>", "outcome": "ok",
      "httpStatus": 200, "latencyMs": 812, "tries": 1,
      "promptTokens": 9, "completionTokens": 1, "totalTokens": 10, "detail": null }
  ],
  "totalLatencyMs": 812
}

rung: 0 means the first model of the tier answered. A higher number means it did not; your product should surface that rather than hide it.

Check what is available#

RequestReturns
GET /v1/tiersThe tiers and their ladders
GET /v1/poolsThe state of each pool: healthy, exhausted, down or unknown
GET /v1/usageYour product's count for the current UTC day and its limit: {"product","usedToday","cap"}

/health/live and /health/ready need no key.

Python client#

Python products can use the blackgate-client package:

from blackgate_client import BudgetExhausted, AllRungsFailed, Blackgate, Message

async with Blackgate(blackgate_url, key) as ai:
    try:
        done = await ai.complete(
            "fast",
            [Message("system", "You are a classifier."), Message("user", "...")],
            max_tokens=512,
            subject="myproduct:bot:support",
        )
    except BudgetExhausted:
        ...  # hand over to a human
    except AllRungsFailed:
        ...  # your own fail-safe

done has content, model, pool, rung and attempts. The exceptions are described in Daily limits and errors. TypeScript products use @exo/kit/ai.