Overview

Base URL: All API requests should be made to https://api.aicopilot.pro (or your self-hosted domain). All responses return JSON.

Authentication

All authenticated endpoints require a Bearer token in the Authorization header:

HTTP Header
Authorization: Bearer YOUR_ACCESS_TOKEN

Rate Limits

Rate limits are applied per-user based on your subscription tier. If you exceed the limit, you will receive a 429 Too Many Requests response.

Error Format

JSON
{
  "detail": "Error message describing what went wrong"
}

Authentication

POST /auth/login
Authenticate with email and password. Returns an access token and user object.
ParameterTypeRequiredDescription
emailstringrequiredUser email address
passwordstringrequiredUser password
"access_token": string // JWT token
"user": object // { id, email, created_at }
cURL
curl -X POST https://api.aicopilot.pro/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "user@example.com",
    "password": "your-password"
  }'
Python
import requests

resp = requests.post("https://api.aicopilot.pro/auth/login", json={
    "email": "user@example.com",
    "password": "your-password"
})
data = resp.json()
token = data["access_token"]
print(f"Token: {token}")
JavaScript
const resp = await fetch('https://api.aicopilot.pro/auth/login', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    email: 'user@example.com',
    password: 'your-password'
  })
});
const data = await resp.json();
console.log('Token:', data.access_token);
POST /auth/register
Create a new account. Returns an access token and user object.
ParameterTypeRequiredDescription
emailstringrequiredEmail address
passwordstringrequiredPassword (min 8 characters)
"access_token": string // JWT token
"user": object // { id, email, created_at }
cURL
curl -X POST https://api.aicopilot.pro/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "email": "new@example.com",
    "password": "secure-password"
  }'
Python
import requests

resp = requests.post("https://api.aicopilot.pro/auth/register", json={
    "email": "new@example.com",
    "password": "secure-password"
})
data = resp.json()
token = data["access_token"]
JavaScript
const resp = await fetch('https://api.aicopilot.pro/auth/register', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    email: 'new@example.com',
    password: 'secure-password'
  })
});
const data = await resp.json();
console.log('Token:', data.access_token);
GET /auth/me
Get the current authenticated user's information.
"id": integer
"email": string
"created_at": string // ISO 8601 datetime

Chat Completions

Chat completions support both standard JSON responses and SSE streaming. Set stream: true to receive real-time token delivery.
POST /v1/chat/completions
Send a message and receive a completion. Supports streaming via Server-Sent Events (SSE).
ParameterTypeRequiredDescription
messagestringrequiredThe user message to send
session_idstringoptionalConversation session ID for context continuity
streambooleanoptionalEnable SSE streaming (default: false)

Non-streaming Response

"id": string
"content": string // Full response text
"model": string
"usage": object // { input_tokens, output_tokens, cost_usd }

SSE Stream Events

When stream: true, the response is a stream of data: ... lines. Each line contains a JSON object with a type field:

SSE Events
data: {"type": "delta", "content": "Hello"}
data: {"type": "delta", "content": " world"}
data: {"type": "cost", "input_tokens": 12, "output_tokens": 45, "cost_usd": 0.0023}
data: {"type": "done", "session_id": "abc123"}
data: [DONE]
cURL (Streaming)
curl -X POST https://api.aicopilot.pro/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{
    "message": "Explain quantum computing",
    "stream": true
  }'
Python (Streaming)
import requests

resp = requests.post(
    "https://api.aicopilot.pro/v1/chat/completions",
    headers={
        "Authorization": f"Bearer {token}",
        "Content-Type": "application/json",
    },
    json={
        "message": "Explain quantum computing",
        "stream": True,
    },
    stream=True,
)

for line in resp.iter_lines():
    if not line or not line.startswith(b"data: "):
        continue
    data = line[6:].decode()
    if data == "[DONE]":
        break
    import json
    event = json.loads(data)
    if event["type"] == "delta":
        print(event["content"], end="", flush=True)
    elif event["type"] == "cost":
        print(f"\nCost: ${event['cost_usd']:.4f}")
JavaScript (Streaming)
const resp = await fetch('https://api.aicopilot.pro/v1/chat/completions', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer ' + token,
  },
  body: JSON.stringify({
    message: 'Explain quantum computing',
    stream: true,
  }),
});

const reader = resp.body.getReader();
const decoder = new TextDecoder();
let buffer = '';

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  buffer += decoder.decode(value, { stream: true });
  const lines = buffer.split('\n');
  buffer = lines.pop();

  for (const line of lines) {
    if (!line.startsWith('data: ')) continue;
    const data = line.slice(6).trim();
    if (data === '[DONE]') { console.log('\nDone'); return; }
    const event = JSON.parse(data);
    if (event.type === 'delta') process.stdout.write(event.content);
    if (event.type === 'cost') console.log(`Cost: ${event.cost_usd.toFixed(4)}`);
  }
}

Sessions

GET /chat/conversations
List all conversation sessions for the authenticated user.
"conversations": array // List of session objects
  [{ "id": string, "title": string, "created_at": string, "updated_at": string }]
POST /chat/conversations
Create a new conversation session.
ParameterTypeRequiredDescription
titlestringoptionalSession title (auto-generated if omitted)
"id": string // New session ID
"title": string
"created_at": string
GET /chat/conversations/{id}
Get details of a specific conversation session, including message history.
"id": string
"title": string
"messages": array // Message history
"created_at": string

Models

GET /v1/models
List all available models. Returns model IDs, names, and capabilities.
"data": array
  [{ "id": string, "name": string, "provider": string }]
cURL
curl https://api.aicopilot.pro/v1/models \
  -H "Authorization: Bearer YOUR_TOKEN"
Python
import requests

resp = requests.get(
    "https://api.aicopilot.pro/v1/models",
    headers={"Authorization": f"Bearer {token}"},
)
models = resp.json()["data"]
for m in models:
    print(f"{m['id']} — {m['name']}")
JavaScript
const resp = await fetch('https://api.aicopilot.pro/v1/models', {
  headers: { 'Authorization': 'Bearer ' + token }
});
const { data: models } = await resp.json();
models.forEach(m => console.log(`${m.id} — ${m.name}`));

Subscriptions

GET /subscription/plans
List all available subscription plans.
"plans": array
  [{ "id": string, "name": string, "price_usd": number, "monthly_credits_usd": number, "features": array }]
POST /subscription/checkout
Create a checkout session for a subscription plan.
ParameterTypeRequiredDescription
plan_idstringrequiredThe plan ID to subscribe to
"checkout_url": string // Redirect user to this URL
POST /subscription/token-pack/checkout
Purchase a one-time token pack.
ParameterTypeRequiredDescription
pack_typestringrequiredPack type identifier (e.g., "small", "medium", "large")
"checkout_url": string // Redirect user to this URL

User & Usage

GET /user/token-balance
Get the current user's token balance across all pools.
"trial_usd": number // Remaining trial credits
"monthly_usd": number // Remaining monthly credits
"pack_usd": number // Remaining pack credits
"total_usd": number // Sum of all pools
cURL
curl https://api.aicopilot.pro/user/token-balance \
  -H "Authorization: Bearer YOUR_TOKEN"
Python
import requests

resp = requests.get(
    "https://api.aicopilot.pro/user/token-balance",
    headers={"Authorization": f"Bearer {token}"},
)
balance = resp.json()
print(f"Total: ${balance['total_usd']:.2f}")
JavaScript
const resp = await fetch('https://api.aicopilot.pro/user/token-balance', {
  headers: { 'Authorization': 'Bearer ' + token }
});
const balance = await resp.json();
console.log(`Total: $${balance.total_usd.toFixed(2)}`);
GET /user/usage?page=1&per_page=20
Get paginated usage history. Returns usage records with token counts and costs.
ParameterTypeRequiredDescription
pageintegeroptionalPage number (default: 1)
per_pageintegeroptionalItems per page (default: 20, max: 100)
"items": array
  [{ "model": string, "input_tokens": integer, "output_tokens": integer, "cost_usd": number, "created_at": string }]
"total": integer // Total record count
"page": integer
"per_page": integer

Pricing

Per-model pricing for API usage. Credits are consumed in USD equivalent.

Model Input (per 1K tokens) Output (per 1K tokens) Provider
Loading pricing...

API Tester

Send real API requests directly from this page. Enter your API key and select an endpoint to test.

Response