Developer API

The /v1 gateway

Everything you can do in the console, your code can do too. The public API base is https://asksybil.codexlabsai.com/api/v1 (the shorter /v1 spelling is a permanent alias - same routes, same auth). /v1 is a programmatic surface over the same chat engine, metering ledger, and model router that powers the interactive workspace - same models, same tools, same accounting. Responses are JSON, streaming is SSE, and errors are structured so your client can react properly. This reference documents the API as it's deployed on this host, nothing aspirational.

⚿Authentication

/v1 endpoints require an hs_ API key in the Authorization header. Browser session tokens are rejected - keys are the programmatic credential, sessions are for people. That separation means a key you hand to a script can never be used to log in as you.

Authorization: Bearer hs_xxxxxxxxxxxxxxxx

Optional X-Org-Id: <org id> header attributes the request's metered spend to an organization you belong to - membership is verified on every call, so the header is a claim the server checks, never a bypass. Org-attributed usage rolls up in the org's portal view and invoices.

❖API keys

Create keys after signing in (via the portal or directly). Secrets are shown once at creation/rotation - only the hash is stored, so even we can't recover a lost key; you'd rotate it instead. Keys can be scoped to specific API areas and given an expiry, and rotation mints a new secret on the same row so all of your historical usage attribution survives.

# create a scoped, expiring key (session token auth)
POST /auth/keys        {"name": "prod", "password": "…", "scopes": ["api"], "expires_at": "2026-12-31T00:00:00"}
  → 201 {"id": 1, "key": "hs_…", "scopes": ["api"], …}   # key shown once
GET  /auth/keys        # list (metadata only)
POST /auth/keys/{id}/rotate  # new secret, same row → usage attribution survives
DELETE /auth/keys/{id}

◉POST /v1/chat

The workhorse: a chat completion through the same routing engine the console uses. Send a message and optionally pin a model, continue a session_id, enable oracle routing or council multi-model deliberation, steer with pref (speed|balanced|quality|local), or attach images. The reply comes back with the model that actually answered and the metered usage your request generated - the real ledger events, not an estimate.

curl -X POST https://asksybil.codexlabsai.com/api/v1/chat \
  -H "Authorization: Bearer hs_…" -H "Content-Type: application/json" \
  -d '{"message": "Explain retry budgets in one paragraph."}'
→ 200 {
  "reply": "…", "model": "qwen3:0.6b", "provider": "ollama",
  "session_id": "…", "request_id": "req_…",
  "usage": {"prompt_tokens": N, "completion_tokens": N, "events": N}
}

Retries are safe. Send an Idempotency-Key header with any unique value and a replayed request returns the stored response with idempotent_replay: true instead of re-executing - no double model work, no double metering. Keys live 24h and are scoped to your credential. A key is claimed before execution: a concurrent request on the same key gets 409 idempotency_in_progress - retry it after the first finishes and you'll get the stored replay. A failed request releases the key, so a corrected retry re-executes cleanly.

∿POST /v1/chat/stream

Server-sent events stream of the same turn: meta, token deltas, routing/verification events, and a terminal done carrying the final model, Oracle-mode metadata, usage (same ledger read as /v1/chat), and request_id.

⬡GET /v1/models

Installed model inventory on the configured provider, plus the configured chat and vision models - the catalog the router selects from.

▥GET /v1/usage

Your own metering summary: event counts, token totals, provider cost and customer charge in integer millicents, and unpriced-event counts - plus by_kind, by_model, and by_day breakdowns of the same period. ?days=1..365 (default 30).

→ 200 {"summary": {"events": N, "tokens_in": …, "tokens_out": …,
  "provider_cost_millicents": …, "charge_millicents": …,
  "unpriced_events": …, "by_kind": […], "by_model": […], "by_day": […]},
  "request_id": "req_…"}

◈Capabilities

The same tool layer the console orchestrates - research fetches, document processing, data analysis, code execution - callable directly. GET /v1/caps lists the commercial catalog (user-permission capabilities only; admin tools are never advertised or reachable here). POST /v1/caps/call executes one synchronously with schema-validated args.

GET  /v1/caps                          # catalog + availability
POST /v1/caps/call   {"capability": "web_get", "args": {"url": "…"}}
  → 200 {"result": {…}, "usage": {…}, "request_id": "req_…"}

◔Async jobs

Work that outlives an HTTP window runs on the durable job layer: submit, poll, cancel, resume. Jobs queue by priority, checkpoint progress to disk, survive restarts, and meter exactly like synchronous calls.

POST /v1/jobs             {"capability": "doc_summarize", "args": {…}, "priority": 5}
  → 201 {"job": {"id": "…", "status": "queued"}}
GET  /v1/jobs             # your jobs, newest first
GET  /v1/jobs/{id}        # status, live progress, result
POST /v1/jobs/{id}/cancel # cooperative stop

▤Request history

GET /v1/requests?limit=1..200 rolls your metered usage up per request_id - event counts, token totals, charge, the models and kinds involved. Metadata only: the ledger never stores prompt or response content.

‰Prepaid credits

Accounts on prepaid plans (or deployments with strict prepay) draw from a credit balance: GET /v1/credits shows balance_millicents plus available_millicents - the balance minus in-flight reservations. Each billable call reserves a bounded hold at admission (402 insufficient_credit when the remainder can't cover it), the real metered charge settles against the balance after execution, and credit-settled usage never reappears on an invoice.

Topping up is self-service: POST /v1/credits/topup {amount_millicents} mints a payment intent with a TOP-… reference, payment instructions, and (when a checkout link is configured) a checkout_url you can send the customer straight to. The APEX processor's signed webhook settles it (a captured checkout payment posts as checkout.completed) and the credit lands automatically. Accounts with an invoice past its grace period get 402 account_past_due on billable calls until settlement - reads and the top-up path itself stay open.

❑Machine-readable spec

The whole surface is also published as JSON at GET /v1/spec - anonymous, interface metadata only (routes, request/response shapes, scopes, limits). Point your codegen or docs tooling at it; the section below renders from that live endpoint when this page is served by the API host, so the reference you read is the contract the server enforces.

curl https://asksybil.codexlabsai.com/api/v1/spec   # no auth - interface metadata only
MethodPathScopeSummary
POST/v1/chatapichat completion
POST/v1/chat/streamapiSSE streaming chat
GET/v1/modelsapimodel inventory
GET/v1/usageapimetering summary (?days=)
GET/v1/capsapicapability catalog
POST/v1/caps/callapirun a capability
GET/v1/jobsapilist your jobs
POST/v1/jobsapisubmit async job
GET/v1/jobs/{id}apijob status/result
POST/v1/jobs/{id}/cancelapicooperative job stop
GET/v1/requestsapiper-request history
GET/v1/creditsapiprepaid balance
POST/v1/credits/topupapimint a top-up payment intent
GET/v1/specanonymousthis machine-readable contract
GET/v1/openapi.jsonanonymousOpenAPI 3.0 document

⚠Errors

Failures are structured JSON with a stable type:

StatustypeMeaning
400invalid_requestvalidation failed (message too long, bad field)
401-missing/invalid/expired key
403authentication_errorsession token used on /v1 - use an hs_ key
403insufficient_scopekey lacks the scope this route requires
403entitlementyour plan does not include API access (or this model)
402insufficient_creditprepaid balance exhausted - top up first
402account_past_duean invoice is past grace - settle it to resume billable access
404not_foundthe referenced object does not exist
409idempotency_in_progressa request with this Idempotency-Key is still running - retry shortly
429rate_limitkey rate limit or plan daily quota - honor Retry-After
503provider_unavailableinference provider unreachable/refused admission
503maintenancethe API is in maintenance - retry shortly

◔Rate limits

Each key is rate-limited per minute, so one busy script can't starve the rest of the platform. The effective limit is your plan's max_rpm entitlement when subscribed, else the platform default of 120 requests/min per key. On this deployment the window is shared platform-wide in the ledger database - the same budget applies whichever instance or restart your request lands on. Plans can also set a daily_requests quota - counted over distinct request ids in the ledger, resetting 00:00 UTC. Over-limit requests return 429 with Retry-After - back off for that many seconds and you're fine.

◍Scopes

Scopes are least-privilege for your own credentials: a key with a scopes list is confined to those API areas, so a key that only needs to chat can't also read your invoices. An unscoped key is full-access (legacy behavior) - fine for a personal key, but give production integrations only what they need. Known scope areas: api (/v1), chat, caps, docs, media, usage, models, account (/auth/keys, /billing, /portal - financial data), admin. Scope checks are enforced on every request, and usage events attribute to the key's identity - key-level analytics appear in your portal.

⌗SDK examples

No SDK needed - the surface is plain JSON over HTTPS. Both snippets below are dependency-free and runnable as-is.

# Python 3 stdlib
import json, urllib.request
req = urllib.request.Request(
    "https://asksybil.codexlabsai.com/api/v1/chat",
    data=json.dumps({"message": "Explain retry budgets."}).encode(),
    headers={"Authorization": "Bearer hs_…",
             "Content-Type": "application/json",
             "Idempotency-Key": "run-42"},      # safe retry
    method="POST")
with urllib.request.urlopen(req, timeout=120) as r:
    print(json.load(r)["reply"])
// JavaScript (browser or Node 18+)
const r = await fetch("https://asksybil.codexlabsai.com/api/v1/chat", {
  method: "POST",
  headers: {"Authorization": "Bearer hs_…",
            "Content-Type": "application/json",
            "Idempotency-Key": "run-42"},
  body: JSON.stringify({message: "Explain retry budgets."})});
const {reply, usage, request_id} = await r.json();
console.log(reply);
Metering note. Every API request mints a request-scoped id; model, capability, and media executions beneath it each write their own ledger event under that id. usage in a chat response reflects exactly what this request cost - provider-reported token counts where the provider reports them, capability executions itemized separately. Your portal and invoices read the same ledger, so the numbers always agree.