Ghost API docs

Everything you need to call Ghost from your own code, Claude Code, Codex or any agent. Web page: https://thesapientdirective.com/ghost/api/docs/

Quickstart

Three steps: make a key, add credits, and send a request with the OpenAI or Anthropic SDK you already use.

Quickstart

  1. Get a key. Sign in and press Generate a key on the API page, or Get your key in Account, Billing, API. The key is shown once.
  1. Add credits. Add $5 or more on the API page. Your first deposit of $10 or more adds $5 free.
  1. Make a request. Replace YOUR_GHOST_KEY below with your key.

curl:

curl https://api.thesapientdirective.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_GHOST_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"ghost-x2","messages":[{"role":"user","content":"Hello"}]}'

Base URL and auth

The Anthropic endpoint also accepts the key as x-api-key. Keys start with ak_. Keep them private: anyone with your key spends your credits.

Models

Every model you can call, with its id, context window and price. Pass the id as model in any request.

US dollars per 1M tokens. A request costs its input tokens times the input price plus its output tokens times the output price, so a short message is a fraction of a cent. The same list as Markdown: /ghost/api/index.md.

ModelidSizeContextBest forInput per 1MOutput per 1M
Ghost X2ghost-x2125B256KCoding, Text, Research$0.20$0.80
Ghost X1ghost-x1125B256KCoding, Text$0.20$0.80
GLM 5.3 Uncensoredglm-5-3-uncensored753B1MResearch, Coding, Text$3$5
GLM 5.3 Flash Uncensoredglm-5-3-flash-uncensoredFlash1MText, Research$0.20$0.80
DeepSeek V4.1 Flash Uncensoreddeepseek-v4-1-flash-uncensoredFlash256KCoding, Research$0.60$2.25
Kimi K3.1 Pro Uncensoredkimi-k3-1-pro-uncensored2.8T256KResearch, Coding$7.50$22.50
Hy4 Uncensoredhy4-uncensored770B256KResearch, Coding$2.50$5
MiMo V2.6 Flash Uncensoredmimo-v2-6-flash-uncensoredFlash256KText, Research$0.70$2.25
MiMo V2.6 Flash Abliteratedmimo-v2-6-flash-abliteratedFlash256KText, Research, Coding$0.80$2.25
Qwen 3.8 27B Obliteratedqwen3-8-27b-obliterated27B256KCoding, Text$0.40$2.25
Qwen 3.8 27B Queenqwen3-8-27b-queen27B256KText$0.20$1
Qwen 3.8 27B Uncensoredqwen3-8-27b-uncensored27B256KText, Coding$0.80$3.50
Qwen 3.8 27B Uncensored Fastqwen3-8-27b-uncensored-fast27B256KText$1.25$4
CyberHeabsycyberheabsyHosted256KCoding$2.25$6.75
Qwen 3.8 Abliteratedqwen3.8-abliterated27B256KCoding, Text$0.20$0.80
Gemma 4 Uncensoredgemma4-26b26B32KText, Images$0.60$1.25
Gemma 4 31B Hereticgemma4-31b-heretic31B32KText, Images$0.80$2.25
Qwen 3 VL Abliteratedqwen3-vl-32b32B32KText, Research, Images$0.70$2.50
MedGemma 1.5medgemma-1-5-4b4B32KResearch, Images$0.30$0.60

Python and JavaScript

The official OpenAI SDKs work as they are. Change the base URL and the key.

Python

The official OpenAI SDK works as it is. Change the base URL and the key.

Terminal:

pip install openai

Python:

from openai import OpenAI

client = OpenAI(base_url="https://api.thesapientdirective.com/v1", api_key="YOUR_GHOST_KEY")
r = client.chat.completions.create(
    model="ghost-x2",
    messages=[{"role": "user", "content": "Hello"}],
)
print(r.choices[0].message.content)

JavaScript

Terminal:

npm install openai

JavaScript:

import OpenAI from "openai";

const client = new OpenAI({ baseURL: "https://api.thesapientdirective.com/v1", apiKey: "YOUR_GHOST_KEY" });
const r = await client.chat.completions.create({
  model: "ghost-x2",
  messages: [{ role: "user", content: "Hello" }],
});
console.log(r.choices[0].message.content);

Streaming

Get the reply token by token as server-sent events.

Pass "stream": true to get the reply token by token as server-sent events, ending with data: [DONE]. Leave it out, or pass false, to get one JSON reply.

curl:

curl -N https://api.thesapientdirective.com/v1/chat/completions \
  -H "Authorization: Bearer YOUR_GHOST_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"ghost-x2","stream":true,"messages":[{"role":"user","content":"Count to five"}]}'

Python:

stream = client.chat.completions.create(
    model="ghost-x2",
    messages=[{"role": "user", "content": "Count to five"}],
    stream=True,
)
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

Tool calling

Let the model call your functions, in the OpenAI tools format.

Describe your functions in tools. When the model wants one, the reply has finish_reason: "tool_calls" and the call in message.tool_calls. Run it, send the result back as a tool message, and ask again.

Python:

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {"city": {"type": "string"}},
            "required": ["city"],
        },
    },
}]
r = client.chat.completions.create(
    model="ghost-x2",
    messages=[{"role": "user", "content": "What is the weather in Paris?"}],
    tools=tools,
)
call = r.choices[0].message.tool_calls[0]
print(call.function.name, call.function.arguments)  # get_weather {"city": "Paris"}

JSON output

Get a reply you can parse as JSON.

Ask for JSON in the prompt and pass "response_format": {"type": "json_object"}. Some models wrap the JSON in a Markdown code fence, so remove the fence markers before you parse it, as below.

Python:

import json, re

r = client.chat.completions.create(
    model="ghost-x2",
    response_format={"type": "json_object"},
    messages=[{"role": "user", "content": "Give me JSON with keys a and b, both numbers."}],
)
text = re.sub(r"^```(?:json)?\s*|\s*```
quot;, "", r.choices[0].message.content.strip()) data = json.loads(text)

Images

Send pictures to the models that read them.

Models whose Reads column on Models says images take pictures. Send the image as a URL or a base64 data URL in the message content.

Python:

import base64

img = base64.b64encode(open("photo.png", "rb").read()).decode()
r = client.chat.completions.create(
    model="gemma4-26b",
    messages=[{"role": "user", "content": [
        {"type": "text", "text": "What is in this picture?"},
        {"type": "image_url", "image_url": {"url": f"data:image/png;base64,{img}"}},
    ]}],
)
print(r.choices[0].message.content)

Anthropic and Responses

The same models answer in the Anthropic Messages format and the OpenAI Responses format.

Anthropic format

The same models answer on /v1/messages in the Anthropic Messages format, which is what Claude Code uses.

curl:

curl https://api.thesapientdirective.com/v1/messages \
  -H "x-api-key: YOUR_GHOST_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "Content-Type: application/json" \
  -d '{"model":"ghost-x1","max_tokens":256,"messages":[{"role":"user","content":"Hello"}]}'

Responses format

/v1/responses takes the OpenAI Responses format, which is what Codex uses. Point any Responses client at https://api.thesapientdirective.com/v1 with your key.

curl:

curl https://api.thesapientdirective.com/v1/responses \
  -H "Authorization: Bearer YOUR_GHOST_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"ghost-x2","input":"Hello"}'

Endpoints

Every route the API serves.

MethodPathWhat it does
GET/v1/modelsEvery model your key can call, with its id, context and price per 1M tokens. Needs your key.
POST/v1/chat/completionsChat, OpenAI format. Streaming, tool calls, JSON output and images.
POST/v1/responsesResponses format (Codex).
POST/v1/messagesChat, Anthropic format (Claude Code).

Every reply carries usage with the exact input and output tokens you are charged for.

All integrations

One command sets up Claude Code or Codex on Ghost. It works with any coding agent.

The installer makes a Ghost folder on your Desktop with a ghost launcher that starts Claude Code or Codex on Ghost. It installs the tool if it is missing and does not change your own Claude or ChatGPT login.

Mac and Linux:

curl -fsSL https://thesapientdirective.com/ghost/install.sh | GHOST_KEY=YOUR_GHOST_KEY sh

Windows PowerShell:

$env:GHOST_KEY="YOUR_GHOST_KEY"; irm https://thesapientdirective.com/ghost/install.ps1 | iex

Then open a new terminal and run ~/Desktop/Ghost/ghost. Options: GHOST_MODEL picks the model (default ghost-x2) and GHOST_TOOL picks claude or codex.

Using a coding agent? Paste this prompt into it and it does the setup for you:

Prompt for your agent:

Set up the Ghost API on my computer. Run this one command in my terminal:

curl -fsSL https://thesapientdirective.com/ghost/install.sh | GHOST_KEY=YOUR_GHOST_KEY sh

It makes a Ghost folder on my Desktop with a launcher. When it finishes, tell me to open a new terminal and run ~/Desktop/Ghost/ghost to start Claude Code (or Codex) on Ghost. For code that calls the API directly, use the OpenAI-compatible base URL https://api.thesapientdirective.com/v1 with this key as the Bearer token, and a model id from /ghost/api/index.md (for example ghost-x2). Docs: /ghost/api/docs/index.md

Claude Code

Run Claude Code on Ghost models without the installer.

Without the installer, set these variables in any terminal, then start Claude Code:

Mac and Linux:

export ANTHROPIC_BASE_URL=https://api.thesapientdirective.com
export ANTHROPIC_AUTH_TOKEN=YOUR_GHOST_KEY
export ANTHROPIC_MODEL=ghost-x2
export ANTHROPIC_SMALL_FAST_MODEL=ghost-x2
export ANTHROPIC_DEFAULT_OPUS_MODEL=ghost-x2
export ANTHROPIC_DEFAULT_SONNET_MODEL=ghost-x2
export ANTHROPIC_DEFAULT_HAIKU_MODEL=ghost-x2
claude

Windows PowerShell:

$env:ANTHROPIC_BASE_URL="https://api.thesapientdirective.com"
$env:ANTHROPIC_AUTH_TOKEN="YOUR_GHOST_KEY"
$env:ANTHROPIC_MODEL="ghost-x2"
$env:ANTHROPIC_SMALL_FAST_MODEL="ghost-x2"
$env:ANTHROPIC_DEFAULT_OPUS_MODEL="ghost-x2"
$env:ANTHROPIC_DEFAULT_SONNET_MODEL="ghost-x2"
$env:ANTHROPIC_DEFAULT_HAIKU_MODEL="ghost-x2"
claude

Use any model id from Models in place of ghost-x2.

Codex

Add Ghost as a provider in Codex.

Add Ghost as a provider in ~/.codex/config.toml, then start Codex with the profile:

~/.codex/config.toml:

[model_providers.ghost]
name = "Ghost"
base_url = "https://api.thesapientdirective.com/v1"
wire_api = "responses"
env_key = "GHOST_API_KEY"

[profiles.ghost]
model = "ghost-x2"
model_provider = "ghost"

Terminal:

export GHOST_API_KEY=YOUR_GHOST_KEY
codex --profile ghost

Other tools

Hermes Agent, OpenCode, Cursor and anything else that takes a custom provider.

Hermes Agent, OpenCode, Cursor, Cline, LibreChat and any other tool that lets you add a custom OpenAI-compatible provider work with Ghost. In the tool's provider or model settings, enter these three values:

Tools that speak the Anthropic format instead use https://api.thesapientdirective.com as the base URL. Pick any model id from Models.

Agent tools send the whole conversation on every step. If you pay with a plan, see Limits for how fast that uses the plan's allowance.

API keys

Make, name and revoke the keys that call the API.

Make, name and revoke keys in Account, Billing, API. A key is shown once, when it is made, so save it somewhere safe. Revoking a key stops it at once. The same page lists every request with its model, tokens and price.

Billing and credits

How API credits, plans and charges work.

Credits and billing

Add $5, $10, $25, $50 or $100 on the API page. Your first deposit of $10 or more adds $5 of credit free. Turn on auto-reload in Account, Billing, Payments. Each request is charged when it finishes, on its real token count. Credits never expire.

Plan or credits

With a Pro or Max plan and credits, choose how you pay in the account menu, the model picker or Billing. Plan uses your plan first and credits only after it runs out. Credits skips the plan and charges every request to your balance. When the balance is empty, requests return 402 api_balance_empty.

Limits

Per-key limits, plan allowances and what each one answers.

Limits

LimitValue
Requests per key120 a minute
Input tokens per key12M a minute
Spend per accountRequests pause past $50 of credits in 10 minutes, then resume

Each limit answers 429 with a Retry-After header in seconds.

Plan limits

Requests paid by a Pro or Max plan, rather than credits, also count against the plan's allowances. Each has a 5-hour session and a weekly window, and Ghost X1 and X2 have their own allowance apart from the other models. When a window is used up the request answers 429 with reason session or weekly, a Retry-After header and an X-Ghost-Reset time. The account menu and Account, Billing, Usage show whichever window is fuller.

PlanRequests a minuteRequests at once
Pro405
Max 5x12010
Max 10x22018
Max 20x30025

Coding agents send the whole conversation on every step, so they use an allowance much faster than chat. To keep going when a window is full, add credits and set Pay with to Credits.

Errors

Every error comes back as JSON with a status, a reason and a message.

Errors come back as JSON: {"error": {"code": 401, "reason": "invalid_token", "message": "..."}}.

StatusReasonWhat to do
401missing_token, invalid_tokenThe key is missing, wrong or revoked. Make a new one.
402api_balance_emptyAdd credits on the API page.
403unknown_modelUse an id from /v1/models.
429key_rate, key_tokens, spend_velocityA key or spend limit. Wait for the Retry-After seconds, then retry.
429session, weeklyA plan window is used up. Wait for X-Ghost-Reset, or pay with credits.
429rate, concurrencyToo many requests a minute, or at once, for your plan. Slow down and retry.
502empty_upstreamThe model sent no reply. Retry, or try another model.
5xxRetry with backoff.

What is blocked

Models answer without refusals, with a few things always blocked.

Models answer without refusals, with a few things always blocked: child sexual abuse material; chemical, biological, radiological and nuclear weapons; terrorism and mass violence; human trafficking; and instructions for self-harm. Every block is logged, and repeated blocked requests can lock the account. See the Acceptable Use Policy and the Content Policy.

The live model list with prices: https://thesapientdirective.com/ghost/api/index.md