# 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](https://thesapientdirective.com/ghost/api/), 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

- Base URL, OpenAI format: `https://api.thesapientdirective.com/v1`
- Base URL, Anthropic format: `https://api.thesapientdirective.com`
- Auth header: `Authorization: Bearer YOUR_GHOST_KEY`
- Default model: `ghost-x2`

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](https://thesapientdirective.com/ghost/api/index.md).

| Model | id | Size | Context | Best for | Input per 1M | Output per 1M |
| --- | --- | --- | --- | --- | --- | --- |
| Ghost X2 | `ghost-x2` | 125B | 256K | Coding, Text, Research | $0.20 | $0.80 |
| Ghost X1 | `ghost-x1` | 125B | 256K | Coding, Text | $0.20 | $0.80 |
| GLM 5.3 Uncensored | `glm-5-3-uncensored` | 753B | 1M | Research, Coding, Text | $3 | $5 |
| GLM 5.3 Flash Uncensored | `glm-5-3-flash-uncensored` | Flash | 1M | Text, Research | $0.20 | $0.80 |
| DeepSeek V4.1 Flash Uncensored | `deepseek-v4-1-flash-uncensored` | Flash | 256K | Coding, Research | $0.60 | $2.25 |
| Kimi K3.1 Pro Uncensored | `kimi-k3-1-pro-uncensored` | 2.8T | 256K | Research, Coding | $7.50 | $22.50 |
| MiMo V2.6 Flash Uncensored | `mimo-v2-6-flash-uncensored` | Flash | 256K | Text, Research | $0.70 | $2.25 |
| Qwen 3.8 27B Obliterated | `qwen3-8-27b-obliterated` | 27B | 256K | Coding, Text | $0.40 | $2.25 |
| Qwen 3.8 27B Queen | `qwen3-8-27b-queen` | 27B | 256K | Text | $0.20 | $1 |
| Qwen 3.8 27B Uncensored | `qwen3-8-27b-uncensored` | 27B | 256K | Text, Coding | $0.80 | $3.50 |
| Qwen 3.8 27B Uncensored Fast | `qwen3-8-27b-uncensored-fast` | 27B | 256K | Text | $1.25 | $4 |
| CyberHeabsy | `cyberheabsy` | Hosted | 256K | Coding | $2.25 | $6.75 |
| Qwen 3.8 Abliterated | `qwen3.8-abliterated` | 27B | 256K | Coding, Text | $0.20 | $0.80 |
| Gemma 4 Uncensored | `gemma4-26b` | 26B | 32K | Text, Images | $0.60 | $1.25 |
| Qwen 3 VL Abliterated | `qwen3-vl-32b` | 32B | 32K | Text, Research, Images | $0.70 | $2.50 |
| MedGemma 1.5 | `medgemma-1-5-4b` | 4B | 32K | Research, 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*```$", "", 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](https://thesapientdirective.com/ghost/api/docs/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.

| Method | Path | What it does |
| --- | --- | --- |

| GET | `/v1/models` | Every model your key can call, with its id, context and price per 1M tokens. Needs your key. |

| POST | `/v1/chat/completions` | Chat, OpenAI format. Streaming, tool calls, JSON output and images. |

| POST | `/v1/responses` | Responses format (Codex). |

| POST | `/v1/messages` | Chat, 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](https://thesapientdirective.com/ghost/api/docs/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:

- Base URL: `https://api.thesapientdirective.com/v1`
- API key: `YOUR_GHOST_KEY`
- Model: `ghost-x2`

Tools that speak the Anthropic format instead use `https://api.thesapientdirective.com` as the base URL. Pick any model id from [Models](https://thesapientdirective.com/ghost/api/docs/models/).

Agent tools send the whole conversation on every step. If you pay with a plan, see [Limits](https://thesapientdirective.com/ghost/api/docs/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](https://thesapientdirective.com/ghost/account/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](https://thesapientdirective.com/ghost/api/). Your first deposit of $10 or more adds $5 of credit free. Turn on auto-reload in [Account, Billing, Payments](https://thesapientdirective.com/ghost/account/billing/). 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

| Limit | Value |
| --- | --- |

| Requests per key | 120 a minute |
| Input tokens per key | 12M a minute |

| Spend per account | Requests 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](https://thesapientdirective.com/ghost/account/usage/) show whichever window is fuller.

| Plan | Requests a minute | Requests at once |
| --- | --- | --- |

| Pro | 40 | 5 |
| Max 5x | 120 | 10 |
| Max 10x | 220 | 18 |
| Max 20x | 300 | 25 |

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": "..."}}`.

| Status | Reason | What to do |
| --- | --- | --- |

| 401 | `missing_token`, `invalid_token` | The key is missing, wrong or revoked. Make a new one. |

| 402 | `api_balance_empty` | Add credits on the API page. |

| 403 | `unknown_model` | Use an id from `/v1/models`. |

| 429 | `key_rate`, `key_tokens`, `spend_velocity` | A key or spend limit. Wait for the `Retry-After` seconds, then retry. |

| 429 | `session`, `weekly` | A plan window is used up. Wait for `X-Ghost-Reset`, or pay with credits. |

| 429 | `rate`, `concurrency` | Too many requests a minute, or at once, for your plan. Slow down and retry. |

| 502 | `empty_upstream` | The model sent no reply. Retry, or try another model. |

| 5xx |  | Retry 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](https://thesapientdirective.com/ghost/acceptable-use/) and the [Content Policy](https://thesapientdirective.com/ghost/content-policy/).

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