Skip to content

OpenAI-compatible clients

The gateway speaks the OpenAI Chat Completions dialect natively.

The gateway speaks the OpenAI Chat Completions dialect natively. Any client that lets you set a custom base URL and API key works — point it at https://www.sleepyai.org/api/v1 and use your Sleepy virtual key.

  • Base URL: https://www.sleepyai.org/api/v1
  • API key: your virtual key from Dashboard → API Keys
  • Model: any id from GET /v1/models

Anthropic clients (Claude Code, the anthropic SDK) use a different base URL (…/api). See Anthropic clients.

curl

curl https://www.sleepyai.org/api/v1/chat/completions \
  -H "Authorization: Bearer ork_..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [{ "role": "user", "content": "Say hello in one sentence." }]
  }'

Add "stream": true for Server-Sent Events.

Python

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://www.sleepyai.org/api/v1",
    api_key=os.environ["SLEEPY_API_KEY"],
)

resp = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Say hello in one sentence."}],
)
print(resp.choices[0].message.content)

Node.js / TypeScript

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://www.sleepyai.org/api/v1",
  apiKey: process.env.SLEEPY_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "gpt-4o",
  messages: [{ role: "user", content: "Say hello in one sentence." }],
});
console.log(resp.choices[0]?.message?.content);

Environment variables (drop-in for existing OpenAI tooling)

export OPENAI_BASE_URL="https://www.sleepyai.org/api/v1"
export OPENAI_API_KEY="ork_..."

Everything that reads those two variables — scripts, notebooks, agents — now runs against Sleepy. Usage lands in your ledger like any other request.

GitHub Copilot-style setups

Copilot-compatible clients accept a custom OpenAI endpoint. Configure:

  • Base URL: https://www.sleepyai.org/api/v1
  • API key: your Sleepy key
  • Model: any active chat model from the catalogue

Completions and chat then route through Sleepy and appear in Dashboard → Usage under source api.

Streaming & usage

Streaming responses are standard OpenAI SSE. The gateway forces stream_options.include_usage so it can meter; the final chunk carries usage with prompt_tokens, completion_tokens, and cached_tokens.

Notes

  • Tool calling is supported (it rides on the chat completions body).
  • Max output is clamped to the model's maxOutputLimit.
  • Limits apply exactly as for any surface — see Usage limits.

Next: Anthropic clients · Cursor / Continue / LiteLLM