API overview
The Sleepy gateway exposes an OpenAI- and Anthropic-compatible API at `/api/v1/*`.
The Sleepy gateway exposes an OpenAI- and Anthropic-compatible API at
/api/v1/*. One virtual key works with every endpoint, every client, and
every surface — and all usage lands in the same allowance.
- Base URL (OpenAI dialect):
https://www.sleepyai.org/api/v1 - Base URL (Anthropic dialect):
https://www.sleepyai.org/api - Auth:
Authorization: Bearer <key>(Anthropic clients may sendx-api-keyinstead) - Metering: per-token cost for chat, native units for image/video/audio
- Limits: RPM, rolling 5h/24h/weekly windows, and a 30-day monthly allowance — see Usage limits
Authentication
Virtual API keys
Mint keys at Dashboard → API Keys
(the /api/editor/keys endpoints back that page). Each key:
- is tied to your account and plan, and draws on the same usage pool as the CLI, the chat app, and the VS Code extension;
- can be given a display name (max 40 chars) and revoked individually;
- is capped at 10 keys per account.
Key format: ork_ followed by 32 random base64url characters (e.g.
ork_Ab12…Xy34). The dashboard masks them as
ork_xxxx••••••••••••••••••••xxxx in lists. The raw key is shown once at
creation and stored encrypted after that — save it somewhere safe. Treat a key
like a password: anyone holding it can spend your allowance.
Key generation is a plan feature. Free accounts may not have the API Key Generation feature. The
sleepyCLI and the VS Code extension use OAuth (device flow / session) instead of a static key — see Sleepy CLI.
CLI / session auth
The CLI obtains a short-lived access token (JWT) via an OAuth device flow. The
gateway accepts either a JWT (three dot-separated segments) or a virtual key
on the Authorization header, so the same endpoints serve both.
Auth header details
- OpenAI-style clients:
Authorization: Bearer <key> - Anthropic-style clients: send
x-api-key: <key>(Claude Code and the official SDKs do this); the gateway also acceptsAuthorization: Bearer. - Browser/session auth (the chat app) takes precedence when a session cookie is present.
Base URLs — don't mix these up
| Client dialect | Base URL | It then calls |
|---|---|---|
| OpenAI | https://www.sleepyai.org/api/v1 | /v1/chat/completions |
| Anthropic | https://www.sleepyai.org/api | /v1/messages |
The Anthropic base URL stops at /api because Anthropic clients append
/v1/messages themselves. If you set it to /api/v1, the client calls
/api/v1/v1/messages → 404. The full walkthrough is in
Anthropic clients.
Endpoints
See the endpoint reference for the full list with curl examples. Summary:
- Chat & text:
POST /v1/chat/completions(OpenAI envelope, streaming),POST /v1/messages(Anthropic envelope, translated),POST /v1/messages/count_tokens(free),POST /v1/completions(legacy),POST /v1/systemone(TypeSafe/Jev native decisions) - Images:
POST /v1/images/generations(max 10 per request) - Video:
POST /v1/videos,GET /v1/videos/{id},GET /v1/videos/{id}/content - Audio:
POST /v1/audio/speech(TTS),POST /v1/audio/transcriptions(STT) - Catalogue:
GET /v1/models
Request / response shape
Chat completions are standard OpenAI. Streaming is Server-Sent Events with
data: {…} chunks and a terminal data: [DONE]. The final chunk carries a
usage block (prompt_tokens, completion_tokens, cached_tokens,
total_tokens). Non-streaming responses include the same usage object.
The gateway forces usage reporting on (stream_options.include_usage) for
token-metered streams so it can meter accurately — you don't need to set it
yourself.
Errors
Every error is JSON. The shape depends on the dialect you're calling:
-
OpenAI-style paths (
/v1/chat/completions, modalities, etc.):{ "error": "Rate limit exceeded (RPM)" } -
Anthropic paths (
/v1/messages,/v1/messages/count_tokens): the Anthropic envelope, so Claude Code and theanthropicSDK can surface the message:{ "type": "error", "error": { "type": "rate_limit_error", "message": "…" } }
Status codes
| Status | error.type (Anthropic) | Meaning |
|---|---|---|
400 | invalid_request_error | Malformed body; e.g. SystemOne body sent to a chat path |
401 | authentication_error | Missing/invalid virtual key or session |
402 | api_error | The billing reservation couldn't cover the request's worst-case cost (allowance + credits), or a modality's daily free allowance is exhausted with no credits |
403 | permission_error | Model not on your plan, invalid/unknown model id, wrong envelope for the model's type, or the Telegram group gate |
404 | not_found_error | Wrong base URL, unknown endpoint, or a video job you don't own |
413 | request_too_large | Request body too large |
429 | rate_limit_error | RPM exceeded, a rolling window (5h/24h/weekly) at cap with no credits, the monthly allowance exhausted, the free-model daily token budget spent (and no bonus tokens), or the upstream queue timed out |
502 | api_error | Upstream provider error (after retries) |
503 | model_unavailable | Model temporarily disabled |
529 | overloaded_error | Upstream overloaded |
A 429 from the queue ("Upstream capacity exhausted; try again shortly")
carries Retry-After: 1.
Gateway behaviours worth knowing
- Billing reservations. Your plan/credit usage is reserved before the upstream call and settled/released after — a crashed request can never grant free tokens, and you're never charged more than the reservation.
- Clamped metering. Request-metered modalities (images) rewrite the outgoing body so upstream can't generate more than was billed; response- metered ones (STT) clamp after the fact.
- Ownership-checked jobs. Async video job ids are recorded per user; a
job-addressed
GETfor someone else's generation returns 404, not 403, so job ids can't be probed. - Multi-router failover. Router selection, health tracking, retries and queueing happen server-side. Transient upstream failures (5xx, 408, 425, and a few 4xx) are retried with backoff before you see an error.
- Model translation. You call the public
modelId; the gateway maps it to the router's internal id. Unknown ids are rejected403"Invalid model ID". - Max-output clamp. A model's admin-set
maxOutputLimitcapsmax_tokens/max_completion_tokensto the lesser of your request and the model's limit.
Next: Endpoint reference · Models · OpenAI clients