API Documentation

Sleepy provides an OpenAI-compatible API for AI completions. You can use any OpenAI client library (Python, Node.js, curl, GitHub Copilot, etc.) by simply changing the base URL and API key.

All requests go through our proxy which handles authentication, rate limiting, usage tracking, and routing to the appropriate AI provider.

Getting Started

Follow these steps to make your first request in under a minute:

  1. Create an account — sign up at sleepyai.org/signup
  2. Generate an API key — from your dashboard keys page. Each key is tied to your account and plan tier.
  3. Point your client at our base URLhttps://www.sleepyai.org/api/v1
  4. Send your first request — see the examples below

Video Tutorials

Using GitHub Copilot with SleepyAI

Watch how to connect GitHub Copilot to the SleepyAI endpoint and start generating with your own keys:

Using the CLI

Watch how to install and use the SleepyCode terminal-native CLI:

Authentication

Authenticate using a Bearer token in the Authorization header:

Authorization: Bearer sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Generate API keys from the dashboard. Each key is tied to your account and plan tier. Keep your keys secret — anyone with a key can spend your usage allowance.

Base URL

https://www.sleepyai.org/api/v1

All endpoints are prefixed with this base URL. For example, to list models:

curl https://www.sleepyai.org/api/v1/models \
  -H "Authorization: Bearer sk-..."

Models

List available models and their pricing:

GET /api/v1/models

Returns a list of active models with pricing, context window, and capabilities.

curl https://www.sleepyai.org/api/v1/models \
  -H "Authorization: Bearer sk-..."

Each model includes inputPrice, outputPrice, and cacheReadPrice per 1M tokens.

Chat Completions

Create a chat completion. Fully compatible with the OpenAI Chat Completions API format.

POST /api/v1/chat/completions

curl https://www.sleepyai.org/api/v1/chat/completions \
  -H "Authorization: Bearer sk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4",
    "messages": [
      {"role": "user", "content": "Hello!"}
    ],
    "stream": true,
    "max_tokens": 1024
  }'

Parameters

ParameterTypeDescription
modelstringModel ID from the models list
messagesarrayArray of message objects (role + content)
streambooleanEnable SSE streaming (default: true)
max_tokensintegerMaximum tokens in the response
temperaturenumberSampling temperature (0-2, default: 1)

Response Format

Streaming responses use Server-Sent Events (SSE). Each chunk follows the OpenAI format:

data: {"id":"...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Hello"},"index":0}]}

data: [DONE]

Non-streaming responses return the complete message object. Usage data (including cached tokens) is included in the final response.

Client SDKs

Use any OpenAI-compatible client by pointing it at our base URL:

Python (openai)

from openai import OpenAI

client = OpenAI(
    base_url="https://www.sleepyai.org/api/v1",
    api_key="sk-..."
)

response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(response.choices[0].message.content)

Node.js (openai)

import OpenAI from "openai";

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

const response = await client.chat.completions.create({
  model: "gpt-4",
  messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);

Using GitHub Copilot with SleepyAI

SleepyAI's endpoint is OpenAI-compatible, so GitHub Copilot can be pointed at it. In your Copilot client settings, configure:

  • Base URLhttps://www.sleepyai.org/api/v1
  • API key — your SleepyAI key from the dashboard
  • Model — any active model from the models list

Once configured, Copilot routes completions and chat through SleepyAI, and usage shows up in your usage dashboard. See the video above for a walkthrough.

SleepyCode CLI

SleepyCode is a terminal-native AI coding assistant built on the SleepyAI platform. It can read and write code, run commands, manage Git, and use persistent memory across sessions.

Install

# One-line install
curl -fsSL https://www.sleepyai.org/install | bash

# Or install via npm
npm install -g @sleepy-ai/cli

Run

sleepy

On first launch, choose a channel: Sleepy Auto (free for a limited time, zero configuration), Sleepy Platform (OAuth login), or connect your own OpenAI-compatible provider. See the video above for a full walkthrough.

Usage & Rate Limits

Usage is tracked per request and displayed in your dashboard. The proxy records prompt tokens, completion tokens, cached tokens, and cost.

Rate Limits

  • Requests per minute (RPM) — based on your plan
  • Spending limits per time window (5h, 24h, weekly, monthly)
  • Monthly allowance resets every 30 days
  • Extra credits can be purchased if you exceed your plan allowance

Context Caching

The proxy supports context caching to reduce costs on repeated prefix content. When enabled, cached portions of the prompt are billed at a lower cacheReadPrice.

Cache hit rate and savings are displayed in the usage dashboard. The cache status is reported transparently — no extra configuration needed.

Error Codes

StatusCodeMeaning
401unauthorizedInvalid or missing API key
403forbiddenModel disabled or access denied
429rate_limitRate or spending limit exceeded
502proxy_errorUpstream provider error
503model_unavailableModel temporarily disabled

Support

  • Email[email protected]
  • Community — join our Telegram group for updates and support