Anthropic-compatible clients
The gateway also speaks the Anthropic Messages API. Claude Code and the official `anthropic` SDKs work by pointing them at Sleepy.
The gateway also speaks the Anthropic Messages API. Claude Code and the
official anthropic SDKs work by pointing them at Sleepy.
- Base URL:
https://www.sleepyai.org/api(stops at/api— see below) - API key: your Sleepy virtual key (sent as
x-api-key, orAuthorization: Bearer) - Model: a chat model id from
GET /v1/models
The one setting that will 404 if you get it wrong
Claude Code always appends /v1/messages to ANTHROPIC_BASE_URL. The Sleepy
gateway serves Anthropic Messages at /api/v1/messages, so the base URL
must stop at /api:
https://www.sleepyai.org/api
You set ANTHROPIC_BASE_URL to | Claude Code calls | Result |
|---|---|---|
https://www.sleepyai.org/api | POST /api/v1/messages | ✅ works |
https://www.sleepyai.org/api/v1 | POST /api/v1/v1/messages | ❌ 404 |
https://www.sleepyai.org | POST /v1/messages | ❌ 404 |
OpenAI clients are the opposite: they take …/api/v1 and append
/chat/completions. Don't reuse a value between the two.
Configure Claude Code
Export these in the shell you launch claude from (or put them in
~/.zshrc / ~/.bashrc):
export ANTHROPIC_BASE_URL="https://www.sleepyai.org/api"
export ANTHROPIC_AUTH_TOKEN="ork_..." # your Sleepy virtual key
export ANTHROPIC_MODEL="<model-id>" # a chat model id from GET /v1/models
Then run:
claude
Claude Code sends the key as x-api-key; the gateway accepts that header (and
Authorization: Bearer if you call the endpoint yourself).
Pin a model
ANTHROPIC_MODEL must be a chat model id (chat-completion or
anthropic-responses type). Image / video / TTS / STT ids will 404 on this
path. List the catalogue first:
curl https://www.sleepyai.org/api/v1/models \
-H "Authorization: Bearer ork_..."
Use the id field as-is (a sleepy/ prefix is optional and stripped; ids are
case-insensitive). If you skip ANTHROPIC_MODEL, Claude Code tries Anthropic's
own default (claude-sonnet-…), which only works if that exact id exists in
your catalogue. You can also pick per-session with claude --model <id>.
Settings file (optional)
Same three values in ~/.claude/settings.json (user) or
.claude/settings.json (project):
{
"env": {
"ANTHROPIC_BASE_URL": "https://www.sleepyai.org/api",
"ANTHROPIC_AUTH_TOKEN": "ork_...",
"ANTHROPIC_MODEL": "<model-id>"
}
}
Don't commit a project settings file containing a live key.
Smoke-test the path before launching Claude Code
If this fails, Claude Code will fail the same way:
curl https://www.sleepyai.org/api/v1/messages \
-H "x-api-key: ork_..." \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "<model-id>",
"max_tokens": 64,
"messages": [{"role": "user", "content": "ping"}]
}'
A good reply looks like Anthropic's Message object ("type": "message",
"role": "assistant", content as typed blocks) — not OpenAI's
choices array. With "stream": true you get named SSE events
(message_start, content_block_delta, message_stop). anthropic-version
is accepted and ignored; no specific version is required.
Using the Anthropic SDK directly
Same host, same key. The official clients also append /v1/messages to the
base URL.
Python
import anthropic
client = anthropic.Anthropic(
base_url="https://www.sleepyai.org/api",
api_key="ork_...",
)
msg = client.messages.create(
model="<model-id>",
max_tokens=1024,
messages=[{"role": "user", "content": "hello"}],
)
print(msg.content)
TypeScript
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://www.sleepyai.org/api",
apiKey: "ork_...",
});
const msg = await client.messages.create({
model: "<model-id>",
max_tokens: 1024,
messages: [{ role: "user", content: "hello" }],
});
console.log(msg.content);
What works
- Text turns, including a top-level
systemprompt - Tool use (
tool_use/tool_result) — what Claude Code's file/shell tools ride on - Images as
imageblocks (base64 or URL) max_tokens,temperature,top_p,stop_sequences,tool_choicePOST /v1/messages/count_tokens(free; no upstream call)
Both chat-completion and anthropic-responses models are reachable on this
path. Billing, plan restrictions, the free-model daily cap, and the output-
token clamp are identical to /v1/chat/completions.
What does not work
Claude Code (and the Anthropic SDK) also call a few sibling routes Sleepy does
not serve. Anything else is 404:
| Path | Status |
|---|---|
POST /v1/messages | supported |
POST /v1/messages/count_tokens | supported (unbilled) |
GET /v1/models | supported |
POST /v1/complete | not served |
| prompt-caching beta extras beyond what the translator maps | not a separate API |
If Claude Code 404s on a non-messages path, that call is outside this
compatibility layer — it's not a bad key.
Errors you'll actually see
Sleepy answers in Anthropic's error envelope
({"type":"error","error":{"type":"…","message":"…"}}), so the CLI prints the
message instead of dying on an unparseable body.
| HTTP | error.type | Usual cause |
|---|---|---|
| 401 | authentication_error | Missing or invalid virtual key |
| 403 | permission_error | Model not on your plan, or Telegram group gate |
| 402 | api_error (message mentions credits / daily limit) | Allowance spent and no extra credits |
| 429 | rate_limit_error | RPM / rolling window / free-model daily cap |
| 404 | not_found_error | Wrong base URL, or a non-chat model id |
Usage lands in Dashboard → Usage
under source api, same as any other key-authenticated call.
Next: OpenAI clients · Usage limits