API docs
Point the OpenAI SDK at Phantom: change the base URL and the key. Chat completions need no other change. Differences are listed under each endpoint. /v1/messages takes Anthropic's format too.
A hold is money Phantom sets aside before a call runs, enough for the most it could cost; it takes the real cost when the call ends. A receipt is signed proof of which model ran and what it cost.
- Base URL
https://phantom.codes/v1- Auth
Authorization: Bearer $PHANTOM_KEY
Make your first request
Get a key on /checkout (no account needed; it shows the key once) or on /keys, and keep it in PHANTOM_KEY. Then send:
curl https://phantom.codes/v1/chat/completions \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"messages": [{"role": "user", "content": "Hello!"}]
}'It prints one JSON answer; add "stream": true for events. Set model to a model ID, or to phantom-1 to let Phantom pick (how it picks). The response headers say which model ran and what it cost. SDK examples are in Call the API.
CLI / coding agent
- Install the Phantom CLI.
npm i -g @phantomcodes/clipnpm add -g @phantomcodes/clibun add -g @phantomcodes/cliOr run the one-line installer, curl -fsSL https://phantom.codes/install | sh. It installs the CLI, and Node 24.22.1 if yours is older, then runs phantom setup. To check the script first, compare its SHA-256 with this one:
curl -fsSL https://phantom.codes/install -o phantom-install.sh && \
echo "97bc74b9672e86bbca1235db73733aa7b500a2ce5a4317918d603f663c0a666e phantom-install.sh" | shasum -a 256 -c - && \
sh phantom-install.shphantom setup: Sign in and connect your coding agents. Until you add credit, phantom-1 runs free.phantom claude: Start Claude Code on Phantom AI. Codex and pi work too, or keep starting your agent as usual.
phantom setup keeps the CLI's own key in the macOS Keychain, or in a private file on other systems; it doesn't print one for an SDK. Until you add credit, phantom-1 runs on free models within its daily limit.
Call the API from your code
Point any OpenAI SDK at https://phantom.codes/v1 with your key and call phantom-1. phantom-1 works on every endpoint. Chat requests get Standard or Frontier; every other endpoint runs one model for its job.
curl https://phantom.codes/v1/chat/completions \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"messages": [{"role": "user", "content": "Hello!"}]
}'import os
from openai import OpenAI
client = OpenAI(
base_url="https://phantom.codes/v1",
api_key=os.environ["PHANTOM_KEY"]
)
response = client.chat.completions.create(
model="phantom-1",
messages=[
{"role": "user", "content": "Hello!"}
],
stream=True
)
for chunk in response:
if chunk.choices:
print(chunk.choices[0].delta.content or "", end="")import OpenAI from 'openai';
const openai = new OpenAI({
baseURL: 'https://phantom.codes/v1',
apiKey: process.env.PHANTOM_KEY,
});
const stream = await openai.chat.completions.create({
model: 'phantom-1',
messages: [{ role: 'user', content: 'Hello!' }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices?.[0]?.delta?.content ?? '');
}import { createOpenAI } from '@ai-sdk/openai';
import { streamText } from 'ai';
const phantom = createOpenAI({
baseURL: 'https://phantom.codes/v1',
apiKey: process.env.PHANTOM_KEY,
});
export async function POST(req: Request) {
const { prompt } = await req.json();
const result = streamText({
model: phantom('phantom-1'),
prompt,
});
return result.toUIMessageStreamResponse();
}import { ChatOpenAI } from '@langchain/openai';
import { HumanMessage } from '@langchain/core/messages';
const model = new ChatOpenAI({
model: 'phantom-1',
apiKey: process.env.PHANTOM_KEY,
configuration: {
baseURL: 'https://phantom.codes/v1',
},
});
const response = await model.invoke([
new HumanMessage('Hello!'),
]);
console.log(response.content);If a provider or model fails, Phantom tries another, and the response header x-phantom-fallback says true. To check a model before you call it, send GET /v1/models/status, which answers up, degraded or down. No key is needed.
Coding agents
# Installs the phantom-ai skill for Claude Code, Codex, Cursor and pi
npm i -g @phantomcodes/cli
phantom login # sign in by device code
phantom setup
phantom setup --agent claude --provider # Claude Code runs on Phantom AI# ~/.codex/config.toml
model = "phantom-1"
model_provider = "phantom"
[model_providers.phantom]
name = "Phantom AI"
base_url = "https://phantom.codes/codex/v1"
wire_api = "responses"
env_key = "PHANTOM_KEY"
model_catalog_url = "https://phantom.codes/codex/v1/models"
# Codex reads the model list only with this on
[features]
api_key_model_discovery = true
# then: export PHANTOM_KEY=sk-phantom-...// ~/.claude/settings.json
{
"env": {
"ANTHROPIC_BASE_URL": "https://phantom.codes/claude-code",
"ANTHROPIC_AUTH_TOKEN": "sk-phantom-...",
"ANTHROPIC_MODEL": "phantom-1",
"ANTHROPIC_DEFAULT_HAIKU_MODEL": "phantom-1",
"CLAUDE_CODE_SUBAGENT_MODEL": "phantom-1",
"CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY": "1",
"CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS": "1"
}
}
// /model then lists Phantom models as claude-code/<id>// opencode.json
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"phantom": {
"npm": "@ai-sdk/openai-compatible",
"name": "Phantom AI",
"options": {
"baseURL": "https://phantom.codes/coding-agent/v1",
"apiKey": "{env:PHANTOM_KEY}"
},
"models": {
"phantom-1": { "name": "Phantom 1" },
"anthropic/claude-sonnet-5.5": { "name": "Claude Sonnet 5.5" }
}
}
}
}API Provider: OpenAI Compatible
Base URL: https://phantom.codes/coding-agent/v1
API Key: sk-phantom-...
Model ID: phantom-1export OPENAI_API_BASE=https://phantom.codes/coding-agent/v1
export OPENAI_API_KEY=sk-phantom-...
aider --model openai/phantom-1Settings → Models
OpenAI API Key: sk-phantom-...
Override OpenAI Base URL: https://phantom.codes/cursor/v1
Add model: phantom-1
Chat only. Agent mode sends requests a custom base URL can't answer.Claude Code runs non-Claude models such as phantom-1, but Anthropic doesn't support that setup. Install the Phantom CLI from npm with npm i -g @phantomcodes/cli.
Choose how models are selected
In short: send phantom-1 and Phantom picks the model. Set a route policy on a key only when you want your own rules for the pick.
- phantom-1
- Phantom picks the model for each chat request; each other endpoint runs one model for that job. How it picks, and its three names, are on /phantom-1.
- Configurable: Per request: zdr, no_training, x-phantom-free and x-phantom-escalate. A key's route policy can also set zdr and no_training. A key's lineup (the models it uses for each tier) picks the Standard and Frontier models (PUT /v1/key/lineup).
- auto
- The key's route policy picks the model (GET, PUT, PATCH, DELETE /v1/key/route). On a key with no route policy, auto runs phantom-1's selection.
- Configurable: Yes: PUT /v1/key/route. Test it first with POST /v1/key/route/test, which charges nothing.
- An explicit model ID
- Calls that model directly, such as anthropic/claude-sonnet-5.5.
- Configurable: No: it skips phantom-1. A route policy with applies_to: "all" still routes it (below).
A route policy applies only to requests with model auto. Set applies_to: "all" and it also applies to requests that name a model. Three names never use a route policy: phantom-1 on chat, phantom-1:free and phantom-1:private.
Privacy controls
In short: Phantom stores no prompt or reply text. To keep a request on providers that retain no data, send zdr: true.
Phantom stores no prompt or reply text. Each call logs the key, model, token counts and cost. Phantom also keeps a one-way fingerprint of each conversation for a short time, so it can keep the conversation on one model. Providers keep their own data and set their own training policies, unless you use the controls below to pick which providers a request may use. Send zdr and no_training on a request, or set them in a key's route policy for every request on it.
| Control | Where | What it does |
|---|---|---|
zdr: true | request body | zdr means zero data retention. Phantom uses only providers that keep no data. If a lineup model has no such provider, Phantom uses that tier's default model. |
no_training: true | request body | Only providers that don't train on prompts, on the same terms. |
x-phantom-free: off | request header | On a key with no credit, refuse the request with 402 instead of running it on phantom-1:free's free models. |
x-openai-api-key: sk-... | request header | Your own OpenAI key, which Phantom never stores, logs or returns. How it bills. |
x-anthropic-api-key: sk-ant-... | request header | Your own Anthropic key, which Phantom never stores, logs or returns. How it bills. |
x-gateway-api-key: vck_... | request header | Your own Vercel AI Gateway key: the call runs on your Gateway account and Phantom charges $0. Phantom never stores, logs or returns it. How it bills. |
x-phantom-content-logged | response header | false on every call that reaches a model, and on an upstream error passed through. A refusal before that, such as a bad key or no credit, doesn't send it. It covers Phantom's own logging, not what a provider keeps. |
phantom-1 and phantom-1:private pick the model on Phantom's own servers. No text goes to another model to make the pick.
The full policy is on /privacy.
Spending and limits
A workspace holds one balance, and each of its keys spends from it. Before a call runs, Phantom holds the most it could cost; when it ends, Phantom takes the real cost and puts the rest back.
Cost of a call: x-phantom-cost-usd on each priced answer, and x-phantom-balance-usd, the balance left after it. A stream sends the cost in its phantom.receipt event instead.
When a call is refused for money
| Cause | Status | Code | What to do |
|---|---|---|---|
| Out of credit | 402 | insufficient_quota | Add credit. A call to phantom-1 runs on free models instead while you have none. Send x-phantom-free: off to get the 402 instead. |
| Over the key's budget | 402 | budget_exceeded | The key has spent its budget, the most it may spend per month or per a number of days you set. Raise it on /keys or with PATCH /v1/key/budget. |
| Over the spend-rate cap | 429 | spend_rate_exceeded | The key spent its per-minute cap. Wait the seconds in Retry-After. |
| Past the free daily limit | 429 | none | Wait the seconds in Retry-After, or add credit. |
The free limit
- 20 requests a minute per workspace.
- 50 requests a day per workspace, 200 through a coding agent.
- 1,000 requests a day once the workspace has taken in $10 of credit.
Receipts
Each paid call returns a signed receipt with the model, tokens, cost and hashes of the request and the answer. A hash is a short code made from the text that can't be turned back into it. Phantom stores the request and answer nowhere. A stream sends its receipt as its last event.
Get a receipt
It is in the x-phantom-receipt header. A stream sends it as its last event, event: phantom.receipt, right before data: [DONE], and a video job returns it when you poll the finished job.
curl -si https://phantom.codes/v1/chat/completions \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "phantom-1",
"messages": [{"role": "user", "content": "Hello"}]}' \
| grep -i x-phantom-receiptCheck a receipt
Paste one here and your browser checks the Ed25519 signature against the public key at GET /v1/receipts/key. No Phantom server gives the verdict. To check the signature in your own code, use WebCrypto with the same key.
What a receipt proves
- A valid signature
- Phantom issued this receipt, and nobody has changed it since. The tokens, cost and model it names are what Phantom billed.
- A Solana record
- The Solana transaction holds the receipt's hash, so the receipt existed in this exact form at that time. Recording one costs $0.01 with POST /v1/receipts/anchor.
- What neither proves
- That the provider ran that model. Phantom signs what the provider reports and can't check that the report is true.
- The key it trusts
- The public key at /v1/receipts/key. Save it once and compare it on later visits.
Receipt endpoints
/v1/receipts/keyRead the public key that signs receipts
Auth: None
Public key for checking receipts. No key required.
Request
curl https://phantom.codes/v1/receipts/key
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The key, or signs: false with detail when the deployment signs nothing. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"signs": true,
"algorithm": "Ed25519",
"receipt_version": 1,
"header": "x-phantom-receipt",
"format": "base64url(canonical JSON payload).base64url(signature)",
"public_key_jwk": {
"kty": "OKP",
"crv": "Ed25519",
"x": "..."
},
"public_key_pem": "-----BEGIN PUBLIC KEY-----\n...\n-----END PUBLIC KEY-----\n"
}/v1/receipts/anchorWrite a receipt's hash to Solana for $0.01
Auth: API key
Records the receipt hash on Solana. $0.01. Recording the same receipt again is free.
Request
curl https://phantom.codes/v1/receipts/anchor \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{"receipt": "<x-phantom-receipt value>"}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
receipt | body | string | yes | The x-phantom-receipt value, as received. |
| Status | Meaning |
|---|---|
| 200 | The receipt is anchored, now or earlier. |
| 400 | Bad JSON, no receipt, or a receipt that does not verify against this deployment's signing key. |
| 401 | No Bearer key in Authorization, or a key Phantom does not know (Key cannot be charged: not_found.). |
| 402 | The key cannot pay the fee: inactive, expired, insufficient_balance, budget_exceeded or spend_rate_exceeded, as Key cannot be charged: <reason>. |
| 502 | The Solana transaction did not land. |
| 503 | This deployment has no Solana signer configured for anchoring. |
Every field, with full descriptions, is in the API reference.
/v1/receipts/anchorLook up whether a receipt is anchored on Solana
Auth: None
leaf is the receipt hash, the SHA-256 of the receipt string. No key required.
Request
curl "https://phantom.codes/v1/receipts/anchor?leaf=<sha256-of-receipt>"
Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
leaf | query | string | yes | SHA-256 of the compact receipt, 64 hex characters. |
| Status | Meaning |
|---|---|
| 200 | The anchor, or anchored: false with the hash and network when there is none. |
| 400 | leaf is missing or not 64 hex characters. |
Every field, with full descriptions, is in the API reference.
Model calls
/v1/chat/completionsCreate a chat completion
Auth: API key
phantom-1 picks again on every request, tool calls included; /phantom-1 says how.
x-phantom-session names the conversation across requests.
x-phantom-escalate: 1 moves that one request up to Frontier, so send it on each request that should stay up.
With zdr: true, a pick that has no zero-data-retention provider fails with 400 zdr_unavailable.
phantom-1:private uses only providers that keep no data and don't train on prompts; the retired phantom-1:zdr answers 400 router_retired.
Request
curl https://phantom.codes/v1/chat/completions \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"messages": [{"role": "user", "content": "Hello"}],
"stream": false
}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
x-phantom-session | header | string | no | Your own conversation id. | |
x-claude-code-session-id | header | string | no | Claude Code's own session id, which it sends on every request. | |
x-claude-code-agent-id | header | string | no | Sent by Claude Code from its helper agents (such as Explore), never from the main agent. | |
x-openai-subagent | header | string | no | Codex's helper kind. | |
x-codex-turn-metadata | header | string | no | Codex's turn metadata, as JSON. | |
x-codex-parent-thread-id | header | string | no | The Codex thread a helper thread started from. | |
x-phantom-agent | header | string | no | The coding agent a request came through: claude-code, codex, cursor, gemini-cli or coding-agent. | |
x-phantom-route | header | string | no | Send off to skip the key's route policy for this request. | |
x-phantom-escalate | header | string | no | Send 1 when the current model isn't managing the task. | |
x-phantom-free | header | string | no | Send off on a key with no credit to get a 402 instead of having phantom-1 run as phantom-1:free, on free models only. | |
x-openai-api-key | header | string | no | Your own OpenAI API key. | |
x-anthropic-api-key | header | string | no | Your own Anthropic API key. | |
x-gateway-api-key | header | string | no | Your own Vercel AI Gateway API key. | |
x-phantom-route-debug | header | string | no | Send 1 or true (or set router_debug: true in the request body) to get phantom-1's score for each model in x-phantom-route-scores. | |
router | body | one of phantom-1, phantom-1:free, phantom-1:private | no | The router to pick the model: phantom-1, phantom-1:free or phantom-1:private (see GET /v1/routers). | |
model | body | string | no | "phantom-1" | A chat model id from GET /v1/models; phantom-1 to let phantom-1 pick its standard or frontier model (a key with no credit runs it as phantom-1:free); or auto to route by the key's route policy (phantom-1 when the key has none). |
messages | body | array of object | yes | The conversation, in OpenAI's format. | |
stream | body | boolean | no | false | Answer as a server-sent event stream. |
stream_options | body | object | no | Passed through, with include_usage forced to true on streams so the usage frame always arrives. | |
max_tokens | body | integer | no | Your output limit. | |
max_completion_tokens | body | integer | no | Read before max_tokens when both are set. | |
n | body | integer | no | Always sent as 1. | |
tools | body | array of object | no | Tool definitions. | |
functions | body | array of object | no | Legacy function definitions. | |
sort | body | one of cost, ttft, tps | no | How to rank the providers that serve the model before trying them: cost (cheapest first, the default), ttft (fastest first token) or tps (most tokens per second). | |
zdr | body | boolean | no | Only use providers that delete prompts right away (zero data retention). | |
no_training | body | boolean | no | Only use providers that don't train on prompts. | |
provider | body | object | no | The upstream's shorthand for provider routing, such as {"sort": "tps"}. | |
providerOptions | body | object | no | Passed to the upstream, except gateway.models, which Phantom replaces with the policy's fallbacks or drops. | |
router_debug | body | boolean | no | When true, returns phantom-1's score for each model and the one it picked in x-phantom-route-scores header and response body. |
| Status | Meaning |
|---|---|
| 200 | The upstream's chat completion, passed through. |
| 400 | The body is not JSON, sort, zdr or no_training has a bad value (invalid_prefs), or the route policy could not route (route_required: auto with x-phantom-route: off, on a key with no credit too, or no model in the policy can take the request). |
| 401 | No Bearer key, phantom-1:free included (missing_api_key; the message says where to buy credit: /checkout, or POST /v1/purchase/x402 with pay.sh), a key Phantom does not know (invalid_api_key), or an expired or deactivated key (api_key_expired). |
| 402 | Sent only after the request itself checks out: a body that is not JSON, an invalid router or sort, zdr or no_training, or a model Phantom does not carry is a 400 or 404 whatever the key holds. |
| 404 | The model is not a chat model in the catalog (model_not_found), or it was retired (model_retired, which names the closest current model). |
| 429 | The key's per-minute spend cap is reached (spend_rate_exceeded). |
| 502 | Phantom has no upstream key configured, or the upstream could not be reached. |
| 503 | The upstream refused Phantom's own account (its credit or budget is used up, or its key is rejected), or Phantom could not load its model list (upstream_unavailable). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"id": "chatcmpl_1",
"object": "chat.completion",
"created": 1,
"model": "deepseek/deepseek-v4.1-flash-1017",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 10,
"completion_tokens": 5,
"total_tokens": 15
},
"phantom": {
"cost_usd": 0.000003,
"provider": null,
"attempts": 1,
"fallback": false
}
}Sample error (402)
{
"error": {
"message": "Not enough credit ($0.0000 left). Top up at https://phantom.codes/checkout.",
"type": "insufficient_quota",
"code": "insufficient_quota"
}
}Streaming request
curl -N https://phantom.codes/v1/chat/completions \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"messages": [{"role": "user", "content": "Hello"}],
"stream": true
}'Streaming response
data: {"choices":[{"delta":{"content":"Hello"}}], ...}
data: {"choices":[{"delta":{"content":"!"}}], ...}
data: {"choices":[], "usage":{"prompt_tokens":8, "completion_tokens":2}, ...}
event: phantom.receipt
data: {"receipt":"<base64url payload>.<base64url signature>", ..., "choices":[]}
data: [DONE]/v1/responsesCreate a response (Responses API)
Auth: API key
OpenAI's Responses API, for Codex CLI and responses.create. Routing, holds and receipts work as on chat. Phantom keeps no conversation: store is always off, and previous_response_id is a 400, so send the whole conversation in input. Add stream: true to stream.
Request
curl https://phantom.codes/v1/responses \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"input": "Write a haiku about receipts."
}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
x-phantom-session | header | string | no | Your own conversation id. | |
x-claude-code-session-id | header | string | no | Claude Code's own session id, which it sends on every request. | |
x-claude-code-agent-id | header | string | no | Sent by Claude Code from its helper agents (such as Explore), never from the main agent. | |
x-openai-subagent | header | string | no | Codex's helper kind. | |
x-codex-turn-metadata | header | string | no | Codex's turn metadata, as JSON. | |
x-codex-parent-thread-id | header | string | no | The Codex thread a helper thread started from. | |
x-phantom-agent | header | string | no | The coding agent a request came through: claude-code, codex, cursor, gemini-cli or coding-agent. | |
x-phantom-route | header | string | no | Send off to skip the key's route policy for this request. | |
x-phantom-escalate | header | string | no | Send 1 when the current model isn't managing the task. | |
x-phantom-free | header | string | no | Send off on a key with no credit to get a 402 instead of having phantom-1 run as phantom-1:free, on free models only. | |
x-openai-api-key | header | string | no | Your own OpenAI API key. | |
x-anthropic-api-key | header | string | no | Your own Anthropic API key. | |
x-gateway-api-key | header | string | no | Your own Vercel AI Gateway API key. | |
router | body | one of phantom-1, phantom-1:free, phantom-1:private | no | The router to pick the model: phantom-1, phantom-1:free or phantom-1:private (see GET /v1/routers). | |
model | body | string | no | "phantom-1" | A chat model id from GET /v1/models; phantom-1 to let phantom-1 pick its standard or frontier model (a key with no credit runs it as phantom-1:free); or auto to route by the key's route policy (phantom-1 when the key has none). |
input | body | string | yes | The prompt, or an array of input items (messages, function call outputs). | |
instructions | body | string | no | The system prompt. | |
tools | body | array of object | no | Tool definitions. | |
stream | body | boolean | no | false | Answer as a server-sent event stream. |
max_output_tokens | body | integer | no | Your output limit. | |
store | body | boolean | no | Always sent as false. | |
previous_response_id | body | string | no | Refused with 400. | |
sort | body | one of cost, ttft, tps | no | How to rank the providers that serve the model: cost (the default), ttft (fastest first token) or tps (most tokens per second). | |
zdr | body | boolean | no | Only use providers that delete prompts right away. | |
no_training | body | boolean | no | Only use providers that don't train on prompts. | |
providerOptions | body | object | no | Passed to the upstream, except gateway.models, which is dropped. |
| Status | Meaning |
|---|---|
| 200 | The upstream's response, passed through, plus phantom. |
| 400 | The body is not JSON, input is missing, previous_response_id is set, sort, zdr or no_training has a bad value, or the route policy could not route. |
| 401 | No Bearer key (the message says where to buy credit: /checkout, or POST /v1/purchase/x402 with pay.sh), a key Phantom does not know, or an expired or deactivated key. |
| 402 | Sent only after the request itself checks out (a body that is not JSON, an invalid router, a missing input or a model Phantom does not carry is a 400 or 404 whatever the key holds). |
| 404 | The model is not a chat model in the catalog, or it was retired. |
| 429 | The key's per-minute spend cap is reached. |
| 502 | Phantom has no upstream key configured, or the upstream could not be reached. |
| 503 | The upstream refused Phantom's own account (its credit or budget is used up, or its key is rejected), or Phantom could not load its model list (upstream_unavailable). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"id": "resp_1",
"object": "response",
"status": "completed",
"model": "deepseek/deepseek-v4.1-flash-1017",
"output": [
{
"type": "message",
"id": "msg_1",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "ok",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 85,
"output_tokens": 16,
"total_tokens": 101,
"input_tokens_details": {
"cached_tokens": 0
},
"output_tokens_details": {
"reasoning_tokens": 0
}
},
"phantom": {
"cost_usd": 0.000015,
"provider": null,
"attempts": 1,
"fallback": false
}
}Sample error (402)
{
"error": {
"message": "Not enough credit ($0.0000 left). Top up at https://phantom.codes/checkout.",
"type": "insufficient_quota",
"code": "insufficient_quota"
}
}/v1/messagesCreate a message (Anthropic)
Auth: API key
The Anthropic-compatible Messages endpoint. It takes your key in x-api-key or Authorization: Bearer. Claude Code: ANTHROPIC_BASE_URL=https://phantom.codes, ANTHROPIC_AUTH_TOKEN set to your key, and ENABLE_TOOL_SEARCH=true if you run MCP servers. Takes any model id, including auto; an Anthropic-style id such as claude-sonnet-5-5 maps to anthropic/claude-sonnet-5.5.
Request
curl https://phantom.codes/v1/messages \
-H "x-api-key: $PHANTOM_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-5-5",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Hello"}]
}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
anthropic-version | header | string | no | Anthropic API version, forwarded to the upstream. | |
anthropic-beta | header | string | no | Anthropic beta flags (prompt caching, long context and the like), forwarded to the upstream unchanged. | |
x-phantom-session | header | string | no | Your own conversation id. | |
x-claude-code-session-id | header | string | no | Claude Code's own session id, which it sends on every request. | |
x-claude-code-agent-id | header | string | no | Sent by Claude Code from its helper agents (such as Explore), never from the main agent. | |
x-openai-subagent | header | string | no | Codex's helper kind. | |
x-codex-turn-metadata | header | string | no | Codex's turn metadata, as JSON. | |
x-codex-parent-thread-id | header | string | no | The Codex thread a helper thread started from. | |
x-phantom-agent | header | string | no | The coding agent a request came through: claude-code, codex, cursor, gemini-cli or coding-agent. | |
x-phantom-route | header | string | no | Send off to skip the key's route policy for this request. | |
x-phantom-escalate | header | string | no | Send 1 when the current model isn't managing the task. | |
x-phantom-free | header | string | no | Send off on a key with no credit to get a 402 instead of having phantom-1 run as phantom-1:free, on free models only. | |
x-openai-api-key | header | string | no | Your own OpenAI API key. | |
x-anthropic-api-key | header | string | no | Your own Anthropic API key. | |
x-gateway-api-key | header | string | no | Your own Vercel AI Gateway API key. | |
router | body | one of phantom-1, phantom-1:free, phantom-1:private | no | The router to pick the model: phantom-1, phantom-1:free or phantom-1:private (see GET /v1/routers). | |
model | body | string | no | Required unless the request sends router. | |
messages | body | array of object | yes | The conversation, in Anthropic's format. | |
max_tokens | body | integer | no | Your output limit. | |
stream | body | boolean | no | false | Answer as a server-sent event stream. |
system | body | string | no | The system prompt. | |
tools | body | array of object | no | Tool definitions. | |
thinking | body | object | no | Extended thinking. | |
models | body | array of string | no | Dropped. | |
sort | body | one of cost, ttft, tps | no | How to rank the providers that serve the model: cost (the default), ttft (fastest first token) or tps (most tokens per second). | |
zdr | body | boolean | no | Only use providers that delete prompts right away. | |
no_training | body | boolean | no | Only use providers that don't train on prompts. | |
providerOptions | body | object | no | Passed to the upstream, except gateway.models, which is dropped. |
| Status | Meaning |
|---|---|
| 200 | The upstream's Anthropic message, passed through. |
| 400 | The body is not JSON, model or messages is missing, sort, zdr or no_training has a bad value, or the route policy could not route (for example auto with x-phantom-route: off, or no model in the policy can take the request). |
| 401 | No key in x-api-key or Authorization (the message says where to buy credit: /checkout, or POST /v1/purchase/x402 with pay.sh), a key Phantom does not know, or an expired or deactivated key. |
| 402 | Sent only after the request itself checks out (a body that is not JSON, a missing model or messages, an invalid router or a model Phantom does not carry is a 400 or 404 whatever the key holds). |
| 404 | The model is not a chat model in the catalog, or it was retired (the error names the closest current model). |
| 429 | The key's per-minute spend cap is reached. |
| 502 | Phantom has no upstream key configured, or the upstream could not be reached. |
| 503 | The upstream refused Phantom's own account (its credit or budget is used up, or its key is rejected), or Phantom could not load its model list (upstream_unavailable). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"id": "msg_1",
"type": "message",
"role": "assistant",
"model": "anthropic/claude-sonnet-5.5",
"content": [
{
"type": "text",
"text": "Hello"
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"usage": {
"input_tokens": 10,
"output_tokens": 5
},
"phantom": {
"cost_usd": 0.000035,
"provider": null,
"attempts": 1,
"fallback": false
}
}Sample error (402)
{
"type": "error",
"error": {
"type": "billing_error",
"message": "Not enough credit ($0.0000 left). Top up at https://phantom.codes/checkout."
}
}/v1/embeddingsCreate embedding vectors for text input
Auth: API key
Request
curl https://phantom.codes/v1/embeddings \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"input": "The quick brown fox"
}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
input | body | array of string | yes | The text to embed: a string, an array of strings, or pre-split token ids (an array of numbers, or an array of such arrays). | |
router | body | one of phantom-1, phantom-1:free, phantom-1:private | no | A router's name in place of model. | |
model | body | string | no | "phantom-1" | phantom-1 runs openai/text-embedding-3-small. |
dimensions | body | integer | no | Length of each vector, for models that support it. |
| Status | Meaning |
|---|---|
| 200 | The upstream's response, passed through unchanged, in OpenAI's embeddings format. |
| 400 | The body is not JSON, or input is missing or empty. |
| 401 | No key (missing_api_key), or a key that does not start with sk- (invalid_api_key). |
| 402 | The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the estimate (insufficient_balance). |
| 404 | The model is not an embedding model in the catalog (model_not_found), or it was retired (model_retired, which names the closest current model; the request is not rerouted). |
| 429 | The key's per-minute spend cap is reached (spend_rate_exceeded). |
| 502 | The upstream answered with a 5xx status, or the call failed (upstream_unavailable). |
| 503 | Phantom has no upstream key configured (upstream_unavailable). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"object": "list",
"model": "openai/text-embedding-3-small",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [
0.25,
-0.5
]
}
],
"usage": {
"prompt_tokens": 3000,
"total_tokens": 3000
}
}Sample error (402)
{
"error": {
"message": "Insufficient balance or inactive API key",
"type": "insufficient_quota",
"code": "insufficient_balance"
}
}/v1/rerankRerank documents by relevance to a query
Auth: API key
Request
curl https://phantom.codes/v1/rerank \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"query": "capital of France",
"documents": ["Paris is the capital.", "Berlin is in Germany."],
"top_n": 2
}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
query | body | string | yes | The text to score the documents against. | |
documents | body | array of string | yes | The documents to score. | |
router | body | one of phantom-1, phantom-1:free, phantom-1:private | no | A router's name in place of model. | |
model | body | string | no | "phantom-1" | phantom-1 runs voyage/rerank-3. |
top_n | body | integer | no | Return only the best top_n results. |
| Status | Meaning |
|---|---|
| 200 | The upstream's rerank response, passed through unchanged. |
| 400 | The body is not JSON, query is missing or empty, or documents is missing or empty. |
| 401 | No key (missing_api_key), or a key that does not start with sk- (invalid_api_key). |
| 402 | The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the estimate (insufficient_balance). |
| 404 | The model is not a reranking model in the catalog (model_not_found), or it was retired (model_retired, which names the closest current model; the request is not rerouted). |
| 429 | The key's per-minute spend cap is reached (spend_rate_exceeded). |
| 502 | The upstream answered with a 5xx status, or the call failed (upstream_unavailable). |
| 503 | Phantom has no upstream key configured (upstream_unavailable). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"model": "voyage/rerank-3",
"results": [
{
"index": 0,
"relevance_score": 0.9
}
]
}Sample error (402)
{
"error": {
"message": "Insufficient balance or inactive API key",
"type": "insufficient_quota",
"code": "insufficient_balance"
}
}/v1/images/generationsGenerate images from a text prompt
Auth: API key
Request
curl https://phantom.codes/v1/images/generations \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "an isometric server room",
"n": 1,
"size": "1024x1024",
"response_format": "url"
}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
prompt | body | string | yes | What to draw. | |
router | body | one of phantom-1, phantom-1:free, phantom-1:private | no | A router's name in place of model. | |
model | body | string | no | "phantom-1" | phantom-1 runs bfl/flux-pro-1.1. |
n | body | integer | no | 1 | How many images. |
size | body | string | no | "1024x1024" | Image size, sent to the upstream unchanged. |
response_format | body | string | no | "url" | How images come back, sent to the upstream unchanged. |
| Status | Meaning |
|---|---|
| 200 | The upstream's response, passed through unchanged. |
| 400 | The body is not JSON, or prompt is missing or not a string. |
| 401 | No key (missing_api_key), or a key that does not start with sk- (invalid_api_key). |
| 402 | The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the price (insufficient_balance). |
| 404 | The model is not an image model in the catalog (model_not_found), or it was retired (model_retired, which names the closest current model; the request is not rerouted). |
| 429 | The key's per-minute spend cap is reached (spend_rate_exceeded). |
| 502 | The upstream answered with a 5xx status, returned no data array, or the call failed (upstream_unavailable). |
| 503 | Phantom has no upstream key configured (upstream_unavailable). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"created": 1,
"data": [
{
"url": "https://upstream.example/img.png"
}
]
}Sample error (402)
{
"error": {
"message": "Insufficient balance or inactive API key",
"type": "insufficient_quota",
"code": "insufficient_balance"
}
}/v1/video/generationsStart a video generation job, paid up front
Auth: API key
Answers 202 with a job id. Poll it with GET /v1/video/generations/{id}. A job that fails is refunded when you poll.
Request
curl https://phantom.codes/v1/video/generations \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"prompt": "a drone shot over a canyon",
"seconds": 5,
"aspect_ratio": "16:9"
}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
prompt | body | string | yes | What the video shows. | |
router | body | one of phantom-1, phantom-1:free, phantom-1:private | no | A router's name in place of model. | |
model | body | string | no | "phantom-1" | phantom-1 runs alibaba/wan-v2.7-t2v. |
seconds | body | integer | no | 5 | Length in whole seconds. |
duration | body | number | no | Same as seconds, read only when seconds is absent. | |
resolution | body | string | no | Saved with the job and nothing more. | |
size | body | string | no | Same as resolution, read only when resolution is absent. | |
aspect_ratio | body | string | no | Width to height, such as 16:9. | |
generate_audio | body | boolean | no | Ask the model for a soundtrack. |
| Status | Meaning |
|---|---|
| 202 | The job started and the key was charged. |
| 400 | The body is not JSON, prompt is missing, empty or not a string, or seconds (or duration) is a length the model does not make (invalid_seconds; the message lists the lengths). |
| 401 | No key (missing_api_key), or a key that does not start with sk- (invalid_api_key). |
| 402 | The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the video (insufficient_balance). |
| 404 | The model is not a video model in the catalog (model_not_found), or it was retired (model_retired, which names the closest current model; the request is not rerouted). |
| 429 | The key's per-minute spend cap is reached (spend_rate_exceeded). |
| 502 | The job did not start, so nothing is billed, or it started but could not be saved and the charge was refunded (upstream_unavailable). |
| 503 | Phantom has no upstream key configured (upstream_unavailable), or the model has no published per-second rate (model_unpriced). |
Every field, with full descriptions, is in the API reference.
Sample response (202)
{
"id": "vid_7c8025957b42cd3c7a37d038",
"object": "video.generation",
"status": "queued",
"model": "alibaba/wan-v2.7-t2v",
"seconds": 4,
"cost_usd": 0.4,
"poll_url": "/v1/video/generations/vid_7c8025957b42cd3c7a37d038"
}Sample error (402)
{
"error": {
"message": "Insufficient balance for a 4s video ($0.4000).",
"type": "insufficient_quota",
"code": "insufficient_balance"
}
}/v1/video/generations/{id}Poll a video generation job for its result
Auth: API key
status is pending while the upstream works, completed with the video URL and receipt, or failed and refunded.
Request
curl https://phantom.codes/v1/video/generations/vid_123 \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
id | path | string | yes | The job id from the start call (vid_...). |
| Status | Meaning |
|---|---|
| 200 | The job's state. |
| 401 | No key (missing_api_key), or a key that does not start with sk- (invalid_api_key). |
| 404 | No job with this id for this key (job_not_found). |
| 502 | The upstream could not be reached for the status, and the job stays running (upstream_unavailable). |
| 503 | The upstream refused Phantom's own account (its credit or budget is used up, or its key is rejected), so the status could not be read (upstream_unavailable). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"id": "vid_7c8025957b42cd3c7a37d038",
"object": "video.generation",
"status": "completed",
"model": "alibaba/wan-v2.7-t2v",
"seconds": 4,
"cost_usd": 0.4,
"data": [
{
"url": "https://video.example/clip.mp4"
}
]
}Sample error (404)
{
"error": {
"message": "No video job 'vid_9' for this API key.",
"type": "invalid_request_error",
"code": "job_not_found"
}
}/v1/audio/speechGenerate speech audio from text
Auth: API key
Request
curl https://phantom.codes/v1/audio/speech \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "phantom-1",
"input": "Hello from Phantom AI",
"voice": "alloy"
}' --output speech.mp3Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
input | body | string | yes | The text to speak. | |
router | body | one of phantom-1, phantom-1:free, phantom-1:private | no | A router's name in place of model. | |
model | body | string | no | "phantom-1" | phantom-1 runs openai/tts-1. |
voice | body | string | no | The voice to use, passed to the upstream when set. | |
response_format | body | string | no | The audio format, passed to the upstream as the output format when set. | |
speed | body | number | no | Playback speed, passed to the upstream when set and not zero. |
| Status | Meaning |
|---|---|
| 200 | The audio. |
| 400 | The body is not JSON, or input is missing, empty or not a string. |
| 401 | No key (missing_api_key), or a key that does not start with sk- (invalid_api_key). |
| 402 | The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the cost (insufficient_balance). |
| 404 | The model is not a speech model in the catalog (model_not_found), or it was retired (model_retired, which names the closest current model; the request is not rerouted). |
| 429 | The key's per-minute spend cap is reached (spend_rate_exceeded). |
| 502 | The upstream call failed or returned no audio (upstream_unavailable). |
| 503 | Phantom has no upstream key configured (upstream_unavailable), or the model has no published per-character rate (model_unpriced). |
Every field, with full descriptions, is in the API reference.
/v1/audio/transcriptionsTranscribe speech audio into text
Auth: API key
Send as multipart/form-data.
Request
curl https://phantom.codes/v1/audio/transcriptions \ -H "Authorization: Bearer $PHANTOM_KEY" \ -F file=@audio.mp3 \ -F model=openai/whisper-1
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The transcript. |
| 400 | The body is not a multipart form, or it has no file. |
| 401 | No key (missing_api_key), or a key that does not start with sk- (invalid_api_key). |
| 402 | The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the held amount (insufficient_balance). |
| 404 | The model is not a transcription model in the catalog (model_not_found), or it was retired (model_retired, which names the closest current model; the request is not rerouted). |
| 429 | The key's per-minute spend cap is reached (spend_rate_exceeded). |
| 502 | The upstream call failed (upstream_unavailable). |
| 503 | Phantom has no upstream key configured (upstream_unavailable). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"text": "hello there",
"language": "en",
"duration": 4
}Sample error (402)
{
"error": {
"message": "Insufficient balance or inactive API key",
"type": "insufficient_quota",
"code": "insufficient_balance"
}
}/v1/models/statusCheck whether a model is answering right now
Auth: None
Whether a model is answering now: up, degraded or down, with each provider's uptime, speed and price. For phantom-1, job picks which of its models (chat, vision, embedding, rerank, image, video, speech, transcription). No key required.
Request
curl "https://phantom.codes/v1/models/status?model=phantom-1&job=chat"
Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
model | query | string | yes | A model id from GET /v1/models, or phantom-1. | |
job | query | one of chat, vision, embedding, rerank, image, video, speech, transcription | no | "chat" | For phantom-1: which of its models to check. |
| Status | Meaning |
|---|---|
| 200 | The model's status. |
| 400 | model is missing, or job is not one of the listed values. |
| 404 | The upstream has no such model, or could not be reached (model_not_found). |
Every field, with full descriptions, is in the API reference.
/v1/modelsList models with their prices and limits
Auth: None
No key required.
Request
curl https://phantom.codes/v1/models
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The catalog. |
Every field, with full descriptions, is in the API reference.
/v1Describe the API and where its docs are
Auth: None
Lists the main routes. No key required.
Request
curl https://phantom.codes/v1 -H "Accept: application/json"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The service description. |
| 307 | The request accepts text/html: a redirect to /docs. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"status": "ok",
"name": "Phantom AI",
"description": "AI for autonomous agents. An API key your agent can buy itself.",
"base_url": "https://phantom.codes/v1",
"documentation": "https://phantom.codes/docs",
"endpoints": {
"chat": "/v1/chat/completions",
"models": "/v1/models",
"embeddings": "/v1/embeddings",
"images": "/v1/images/generations",
"audio": "/v1/audio/speech",
"transcriptions": "/v1/audio/transcriptions",
"rerank": "/v1/rerank",
"video": "/v1/video/generations"
},
"key_lifecycle": {
"purchase": "/v1/purchase/solana",
"purchase_status": "/v1/purchase/{payment_id}/status",
"balance": "/v1/key/balance",
"budget": "/v1/key/budget",
"rotate": "/v1/key/rotate",
"burn": "/v1/key"
}
}Keys
/v1/key/balanceRead the key's balance and expiry
Auth: API key
Request
curl https://phantom.codes/v1/key/balance \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The key's balance. |
| 401 | No Bearer key in Authorization (Missing or invalid Authorization header), or a key Phantom does not know (invalid_key). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"active": true,
"kind": "credit",
"credit_balance_usd": 5,
"credit_spent_usd": 0.000003,
"expires_at": "2026-12-17T01:38:50.236Z"
}Sample error (401)
{
"error": "invalid_key"
}/v1/key/budgetRead the key's budget and spend-rate caps
Auth: API key
Spent this period, days left, and whether spending is on_pace or ahead.
Request
curl https://phantom.codes/v1/key/budget \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The caps and pace. |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"budget_usd": null,
"period_days": null,
"spent_this_period_usd": 0.000003,
"period_started": "2026-11-17T01:38:50.406Z",
"exhausted": false,
"period_ends": null,
"days_left": null,
"allowed_so_far_usd": null,
"daily_allowance_usd": null,
"pace": null,
"rate_usd_per_min": null,
"spent_this_minute_usd": 0.000003,
"rate_exceeded": false
}Sample error (401)
{
"error": "invalid_key"
}/v1/key/budgetTighten the key's budget and spend-rate caps
Auth: API key
Add or lower a cap per period (budget_usd) or a per-minute cap (rate_usd_per_min). period_days sets the period length; null means one month. With the key alone a cap can only get tighter: raising or removing one, or shortening the period, answers 403, and the workspace does it under Edit controls on /keys. A budget added to a key with none starts a new period; a lowered one keeps what was spent. Rotating a key keeps both caps. What each cap answers: Spending and limits, above.
Request
curl -X PATCH https://phantom.codes/v1/key/budget \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{"budget_usd": 20, "period_days": 30, "rate_usd_per_min": 0.10}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
budget_usd | body | number or null | no | Spend cap per window in US dollars, above zero, and no more than the key's current cap. | |
period_days | body | integer or null | no | Window length in whole days, no shorter than the current window while the key has a budget. | |
rate_usd_per_min | body | number or null | no | Per-minute spend cap in US dollars, above zero, and no more than the key's current cap. |
| Status | Meaning |
|---|---|
| 200 | The caps after the change. |
| 400 | Bad JSON, none of the three fields, or a value out of range. |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
| 403 | The change would raise or remove a cap, or shorten the budget's window. |
| 409 | The key's caps changed while the request ran, such as the workspace lowering one. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"budget_usd": 20,
"period_days": 30,
"spent_this_period_usd": 0,
"period_started": "2026-11-17T01:38:50.428Z",
"exhausted": false,
"period_ends": "2026-12-17T01:38:50.428Z",
"days_left": 30,
"allowed_so_far_usd": 0,
"daily_allowance_usd": 0.666666,
"pace": "on_pace",
"rate_usd_per_min": 0.1,
"spent_this_minute_usd": 0.000003,
"rate_exceeded": false
}Sample error (401)
{
"error": "invalid_key"
}/v1/key/routeRead the key's route policy for model auto
Auth: API key
The route policy that picks a model for model "auto".
Request
curl https://phantom.codes/v1/key/route \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The policy, or null when the key has none or the stored one no longer passes the checks. |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"route_policy": {
"models": [
"deepseek/deepseek-v4.1-flash-1017",
"anthropic/claude-sonnet-5.5"
],
"applies_to": "auto",
"rules": [
{
"if": {
"pace": "ahead"
},
"use": "cheapest"
}
],
"on_empty": "stop",
"fallback_on_error": false,
"stick_minutes": 5,
"stick_by_prompt": true
}
}Sample error (401)
{
"error": "invalid_key"
}/v1/key/routeReplace the route policy
Auth: API key
Replace the route policy. models: 1 to 10 ids. Rules run in order; the first match picks the model, else models[0]. Conditions: pace, budget_left_pct_below, days_left_below, has_tools, input_tokens_over, reasoning_requested. use: a model from models, cheapest, first or next. Optional: applies_to (auto, all), on_empty (stop, cheapest), fallback_on_error.
Request
curl -X PUT https://phantom.codes/v1/key/route \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{"models": ["anthropic/claude-sonnet-5.5", "phantom-1"],
"rules": [{"if": {"pace": "ahead"}, "use": "cheapest"}]}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
models | body | array of string | yes | The models this key may route to, up to 10 ids of up to 200 characters. | |
applies_to | body | one of auto, all | no | "auto" | auto: only model: "auto" requests are routed. |
rules | body | array of object | no | Up to 20 rules, tried in order. | |
on_empty | body | one of stop, cheapest | no | "stop" | Once the budget is used up. |
fallback_on_error | body | boolean | no | false | When true, the policy's other chat models go to the upstream as fallbacks if the picked model fails. |
stick_minutes | body | integer | no | 5 | Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm. |
stick_by_prompt | body | boolean | no | true | Without x-phantom-session, recognise a conversation by a hash of its opening messages, held in memory only. |
sort | body | one of cost, ttft, tps | no | Default provider ranking for this key's chat and messages requests: cost, ttft (fastest first token) or tps (most tokens per second). | |
zdr | body | boolean | no | Send this key's requests only to providers that delete prompts right away. | |
no_training | body | boolean | no | Send this key's requests only to providers that don't train on prompts. | |
sensitivity | body | one of balanced, conservative, strict | no | "balanced" | How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there. |
| Status | Meaning |
|---|---|
| 200 | The policy as stored, with defaults filled in. |
| 400 | The body is not a JSON object, the policy fails the checks (Invalid route policy: ... lists each problem), or it could not be saved (the key is inactive, or the write failed). |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"route_policy": {
"models": [
"deepseek/deepseek-v4.1-flash-1017",
"anthropic/claude-sonnet-5.5"
],
"applies_to": "auto",
"rules": [
{
"if": {
"pace": "ahead"
},
"use": "cheapest"
}
],
"on_empty": "stop",
"fallback_on_error": false,
"stick_minutes": 5,
"stick_by_prompt": true
}
}Sample error (401)
{
"error": "invalid_key"
}/v1/key/routeUpdate part of the route policy
Auth: API key
Updates the top-level fields you send and keeps the rest.
Request
curl -X PATCH https://phantom.codes/v1/key/route \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{"on_empty": "cheapest"}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
models | body | array of string | no | The models this key may route to, up to 10 ids of up to 200 characters. | |
applies_to | body | one of auto, all | no | "auto" | auto: only model: "auto" requests are routed. |
rules | body | array of object | no | Up to 20 rules, tried in order. | |
on_empty | body | one of stop, cheapest | no | "stop" | Once the budget is used up. |
fallback_on_error | body | boolean | no | false | When true, the policy's other chat models go to the upstream as fallbacks if the picked model fails. |
stick_minutes | body | integer | no | 5 | Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm. |
stick_by_prompt | body | boolean | no | true | Without x-phantom-session, recognise a conversation by a hash of its opening messages, held in memory only. |
sort | body | one of cost, ttft, tps | no | Default provider ranking for this key's chat and messages requests: cost, ttft (fastest first token) or tps (most tokens per second). | |
zdr | body | boolean | no | Send this key's requests only to providers that delete prompts right away. | |
no_training | body | boolean | no | Send this key's requests only to providers that don't train on prompts. | |
sensitivity | body | one of balanced, conservative, strict | no | "balanced" | How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there. |
| Status | Meaning |
|---|---|
| 200 | The policy as stored, with defaults filled in. |
| 400 | The body is not a JSON object, the merged policy fails the checks, or it could not be saved. |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"route_policy": {
"models": [
"deepseek/deepseek-v4.1-flash-1017",
"anthropic/claude-sonnet-5.5"
],
"applies_to": "auto",
"rules": [
{
"if": {
"pace": "ahead"
},
"use": "cheapest"
}
],
"on_empty": "stop",
"fallback_on_error": false,
"stick_minutes": 5,
"stick_by_prompt": true
}
}Sample error (401)
{
"error": "invalid_key"
}/v1/key/routeClear the key's route policy for model auto
Auth: API key
Remove the route policy.
Request
curl -X DELETE https://phantom.codes/v1/key/route \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The policy is cleared. |
| 400 | The policy could not be cleared (the key is inactive, or the write failed). |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"route_policy": null
}Sample error (401)
{
"error": "invalid_key"
}/v1/key/route/testTest which model a request would be routed to
Auth: API key
Shows the model a chat request would run on now, and the rule that picked it. No charge, and no model is called to pick it.
Request
curl -X POST https://phantom.codes/v1/key/route/test \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{"model": "auto", "messages": [{"role": "user", "content": "hi"}]}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
x-phantom-session | header | string | no | Your own conversation id. | |
x-claude-code-session-id | header | string | no | Claude Code's own session id, which it sends on every request. | |
x-claude-code-agent-id | header | string | no | Sent by Claude Code from its helper agents (such as Explore), never from the main agent. | |
x-openai-subagent | header | string | no | Codex's helper kind. | |
x-codex-turn-metadata | header | string | no | Codex's turn metadata, as JSON. | |
x-codex-parent-thread-id | header | string | no | The Codex thread a helper thread started from. | |
x-phantom-route | header | string | no | Send off to skip the key's route policy for this request. | |
x-phantom-free | header | string | no | Send off on a key with no credit to get a 402 instead of having phantom-1 run as phantom-1:free, on free models only. | |
x-phantom-escalate | header | string | no | Send 1 when the current model isn't managing the task. | |
model | body | string | yes | The model to request, auto, or a router: phantom-1, phantom-1:private or phantom-1:free. | |
messages | body | array of object | no | Chat messages. | |
tools | body | array of object | no | Tool definitions. | |
functions | body | array of object | no | Older form of tools, treated the same. | |
zdr | body | boolean | no | Only providers that delete prompts right away, for phantom-1 and auto. | |
no_training | body | boolean | no | Only providers that do not train on prompts, for phantom-1, phantom-1:private and auto. | |
max_tokens | body | integer | no | Output estimate for price comparisons (500 when absent, at most 4000). | |
max_completion_tokens | body | integer | no | Read before max_tokens for the output estimate. | |
reasoning_effort | body | string | no | Any value but none makes reasoning_requested true. | |
reasoning | body | object | no | An object makes reasoning_requested true unless it sets enabled: false or effort: "none". |
| Status | Meaning |
|---|---|
| 200 | The decision. |
| 400 | Bad JSON, no model, auto with x-phantom-route: off (on any key, one with no credit included), auto on a key whose route policy has no model that can take the request, a zdr, no_training or sort the chat route would refuse, or a request no model of phantom-1:private or phantom-1:free can take. |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"model": "deepseek/deepseek-v4.1-flash-1017",
"reason": "default",
"routed": true,
"fallbacks": []
}Sample error (400)
{
"error": "model is required, for example \"auto\"."
}/v1/key/lineupRead the models each phantom-1 tier may use
Auth: API key
The model each phantom-1 tier runs on this key, and the models each tier can run, with prices.
Request
curl https://phantom.codes/v1/key/lineup \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The lineup, the model each tier runs, and each tier's suggested models with prices. |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample error (401)
{
"error": "invalid_key"
}/v1/key/lineupSet the models each phantom-1 tier may use
Auth: API key
Pick the model for Standard or Frontier from that tier's choices. A tier left out or null runs its default. fallbacks names the model to try when a tier's model fails. phantom-1:private ignores the lineup. The Phantom CLI does the same with phantom lineup. How a lineup works.
Request
curl -X PUT https://phantom.codes/v1/key/lineup \
-H "Authorization: Bearer $PHANTOM_KEY" \
-H "Content-Type: application/json" \
-d '{"frontier": "anthropic/claude-opus-5.5",
"fallbacks": {"standard": "anthropic/claude-haiku-5.5"}}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
standard | body | string or null | no | The model every task starts on. | |
frontier | body | string or null | no | The model hard steps move up to. | |
fallbacks | body | object or null | no | The fallback model for each tier you name. |
| Status | Meaning |
|---|---|
| 200 | The lineup as stored, and the model each tier runs. |
| 400 | The body is not a JSON object, names an unknown tier (economy included: phantom-1 has two tiers, Standard and Frontier, and Economy is no longer a lineup setting), a model or fallback that the catalog doesn't list, isn't a chat model, can't call tools, can't read images or holds under 128,000 tokens (the message says which), or a fallback equal to the tier's own model (Invalid lineup: ...), or could not be saved. |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample error (400)
{
"error": "Invalid lineup: frontier: x/not-a-pick isn't a model Phantom lists. GET /v1/models lists them."
}/v1/key/lineupReset the phantom-1 lineup to the defaults
Auth: API key
Go back to the default model in every tier.
Request
curl -X DELETE https://phantom.codes/v1/key/lineup \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The lineup is cleared. |
| 400 | The lineup could not be cleared (the key is inactive, or the write failed). |
| 401 | No Bearer key, or a key Phantom does not know, has revoked or has expired. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"lineup": null,
"tiers": {
"standard": {
"model": "deepseek/deepseek-v4.1-flash-1017",
"name": "DeepSeek V4.1 Flash 1017"
},
"frontier": {
"model": "anthropic/claude-sonnet-5.5",
"name": "Claude Sonnet 5.5"
}
}
}Sample error (401)
{
"error": "invalid_key"
}/v1/keyRevoke the calling key; its workspace keeps credit
Auth: API key
Can't be undone. Deletes the key. Its workspace keeps the credit. 409 while a request on it is running.
Request
curl -X DELETE https://phantom.codes/v1/key \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The key is revoked. |
| 401 | No Bearer key in Authorization. |
| 404 | No active key matches the credential. |
| 409 | Credit is held for a request still running on this key (key_busy). |
| 500 | The database write failed. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"revoked": true,
"forfeited_usd": 0
}Sample error (404)
{
"error": "No active key for that credential."
}/v1/key/rotateRotate the key: new secret, same settings
Auth: API key
Issues a new key with the same balance, expiry and caps. The old key stops working at once, so update every client that uses it right after.
Request
curl -X POST https://phantom.codes/v1/key/rotate \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The new key. |
| 400 | The key is unknown or inactive, or the database write failed. |
| 401 | No Bearer key in Authorization. |
| 409 | Credit is held for a request still running on this key (key_busy). |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"api_key": "sk-phantom-...",
"rotated_at": "2026-11-17T01:38:50.639Z"
}Sample error (400)
{
"error": "Failed to rotate key or key inactive"
}/v1/privacyFetch what is stored about you
Auth: API key or session cookie
Shows what is linked to your key or account. Send a key, a session cookie, or both.
Request
curl https://phantom.codes/v1/privacy \ -H "Authorization: Bearer $PHANTOM_KEY"
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The report. |
| 401 | A key Phantom does not know, has revoked or has expired (invalid_key), or neither a key nor a session came with the request. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"tier": "anonymous",
"key": {
"identity": null,
"identity_linkable": false,
"prompts_stored": 0,
"usage_rows": 0,
"zdr_requests": 0,
"payment_linkable": false
},
"account": null,
"invariants": {
"prompts_written_by_api": false,
"key_has_identity_column": false,
"payment_to_key_join_exists": true,
"identity_to_key_join_exists": true
}
}Sample error (401)
{
"error": "invalid_key"
}Credit
Each purchase route takes target_api_key to add the credit to a key you already have; without it, the purchase makes a new key.
/v1/bundlesPurchase limits and presets
Auth: None
Request
curl https://phantom.codes/v1/bundles
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | Limits and presets. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"data": [
{
"name": "$1",
"price_usd": 1,
"credit_usd": 1,
"validity_days": 365
},
{
"name": "$5",
"price_usd": 5,
"credit_usd": 5,
"validity_days": 365
},
{
"name": "$10",
"price_usd": 10,
"credit_usd": 10,
"validity_days": 365
},
{
"name": "$25",
"price_usd": 25,
"credit_usd": 25,
"validity_days": 365
},
{
"name": "$50",
"price_usd": 50,
"credit_usd": 50,
"validity_days": 365
}
],
"custom": {
"min_usd": 0.1,
"max_usd": 10000,
"card_min_usd": 5,
"markup_percent": 0,
"bonus_tiers": [
{
"min_usd": 500,
"bonus_percent": 2
},
{
"min_usd": 100,
"bonus_percent": 1
}
],
"card_fixed_fee_free_from_usd": 50,
"card_fee_bps": 290,
"card_fee_percent": 2.986612,
"card_fee_fixed_usd": 0.30896,
"validity_days": {
"min": 1,
"max": 3650,
"default": 365
}
}
}/v1/coinsList the coins a crypto payment accepts
Auth: None
Request
curl https://phantom.codes/v1/coins
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The accepted coins. |
Every field, with full descriptions, is in the API reference.
/v1/purchase/x402Create a quote for Stripe-backed x402 credit
Auth: None
For agents paying with pay.sh. Returns a quote: payment_url, the price and a recovery code, shown once. Then pay the quote.
Request
curl https://phantom.codes/v1/purchase/x402 \
-H "Content-Type: application/json" \
-d '{"amount_usd": 1, "target_api_key": "sk-phantom-..."}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
amount_usd | body | number | yes | The price in whole cents, paid in USDC. | |
validity_days | body | integer | no | 365 | How long a new key stays valid; a top-up extends the key to at least this. |
target_api_key | body | string | no | A Phantom key to add the credit to instead of issuing a new one. | |
workspace_id | body | string | no | Optional authorized workspace that receives the credit. |
| Status | Meaning |
|---|---|
| 200 | Quote and recovery credential; save the credential privately before paying. |
| 400 | Invalid quote: an amount out of range or not in whole cents, a target_api_key that cannot take credit, or both target_api_key and workspace_id. |
| 401 | Workspace authorization required. |
| 403 | Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token. |
| 429 | Added by proxy.ts: too many requests from your address in the current window. |
| 500 | Quote could not be stored. |
| 503 | Stripe x402 is off, or the deposit address has no USDC token account and the server could not create one. |
Every field, with full descriptions, is in the API reference.
/v1/purchase/{id}/x402Pay a quote with Solana MPP or x402 into Stripe
Auth: None. Paid with a 402 payment.
Pays the quote in Solana USDC (MPP or x402) into Stripe. The first call answers 402; pay pays it and sends the request again. Stripe confirms the transfer, and its webhook adds the credit. Poll /v1/purchase/{id}/status until it says completed.
Request
pay curl -X POST https://phantom.codes/v1/purchase/pay_123/x402
Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
id | path | string | yes | Identifier from the x402 purchase quote. | |
payment-signature | header | string | no | Signed x402 payment authorization supplied by a compatible payment client. |
| Status | Meaning |
|---|---|
| 200 | Payment received; credit may still be pending Stripe verification. |
| 400 | Malformed settlement. |
| 402 | Pay this challenge using a compatible Solana MPP or x402 client. |
| 404 | Quote not found. |
| 409 | Expired quote or conflicting transfer. |
| 429 | Added by proxy.ts: too many requests from your address in the current window. |
| 503 | Unavailable, the deposit address cannot receive USDC (no challenge is sent), or verification pending; poll the purchase before paying again. |
Every field, with full descriptions, is in the API reference.
/v1/purchase/solanaStart a USDC payment on Solana for prepaid credit
Auth: None
Pay with USDC from a Solana wallet, to Stripe's deposit address. coin: usdc. Returns the recipient, the exact amount, a reference to attach to the transfer, and a Solana Pay link. Poll /v1/purchase/{id}/status, which finds the transfer and records it with Stripe; Stripe's webhook adds the credit. SOL and USDT answer 400.
Request
curl https://phantom.codes/v1/purchase/solana \
-H "Content-Type: application/json" \
-d '{"amount_usd": 5, "coin": "usdc"}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
coin | body | one of usdc, usdcsol | no | "usdc" | The coin to pay with. |
amount_usd | body | number | no | The price in US dollars, within the limits from GET /v1/bundles. | |
validity_days | body | integer | no | 365 | Days a new key stays valid, a whole number. |
bundle | body | one of test, small, medium, large, whale | no | An old preset name, used only when amount_usd is missing. | |
target_api_key | body | string | no | A key you hold, to add the credit to it rather than get a new key. |
| Status | Meaning |
|---|---|
| 200 | The payment is created and waiting for the transfer. |
| 400 | The body is not a JSON object, coin is SOL, USDT or unknown, the amount or validity is out of range, or target_api_key is not an active key. |
| 429 | Added by proxy.ts: too many requests from your address in the current window. |
| 500 | The payment could not be saved. |
| 503 | USDC on Solana is off right now. |
Every field, with full descriptions, is in the API reference.
/v1/purchase/cardStart a card payment for prepaid credit
Auth: None
Pay by card. The card also pays Stripe's 2.9% + $0.30 fee, so $20 charges $20.91. From $50 Phantom pays the fixed part, so $50 charges $51.50. 1% bonus credit from $100, 2% from $500, on card, Solana and x402. With target_api_key, the payment is linked to that key.
Request
curl https://phantom.codes/v1/purchase/card \
-H "Content-Type: application/json" \
-d '{"amount_usd": 25, "validity_days": 365, "target_api_key": "sk-phantom-..."}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
amount_usd | body | number | no | The price in US dollars, before Stripe's card fee. | |
validity_days | body | integer | no | 365 | Days a new key stays valid, a whole number. |
bundle | body | one of test, small, medium, large, whale | no | An old preset name, used only when amount_usd is missing. | |
target_api_key | body | string | no | A key you hold, to add the credit to it rather than get a new key. | |
hosted | body | boolean | no | false | Return a Stripe-hosted checkout_url instead of a client_secret, for callers with no card form, such as the Phantom CLI. |
| Status | Meaning |
|---|---|
| 200 | The payment is created and waiting for the card. |
| 400 | The body is not a JSON object, the amount or validity is out of range, the amount is under the card minimum, or target_api_key is not an active key. |
| 429 | Added by proxy.ts: too many requests from your address in the current window. |
| 500 | Stripe or the database failed. |
| 503 | Card checkout is off because no Stripe key is set. |
Every field, with full descriptions, is in the API reference.
/v1/purchase/stripe-cryptoStart a crypto payment on Stripe's page
Auth: None
Pay with crypto on Stripe's page. Returns checkout_url, a page on crypto.stripe.com where you pick the coin and network: USDC on Solana, Base, Ethereum, Polygon or Tempo, or USDP or USDG. You pay the price, rounded up to the cent, from $1.00. Poll /v1/purchase/{id}/status with the recovery code; Stripe's webhook adds the credit once the payment succeeds.
Request
curl https://phantom.codes/v1/purchase/stripe-crypto \
-H "Content-Type: application/json" \
-d '{"amount_usd": 10}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
amount_usd | body | number | no | The price in US dollars, from $1.00 and within the limits from GET /v1/bundles. | |
validity_days | body | integer | no | 365 | Days a new key stays valid, a whole number. |
bundle | body | one of test, small, medium, large, whale | no | An old preset name, used only when amount_usd is missing. | |
target_api_key | body | string | no | A key you hold, to add the credit to it rather than get a new key. |
| Status | Meaning |
|---|---|
| 200 | The payment is created and waiting on Stripe's page. |
| 400 | The body is not a JSON object, the amount or validity is out of range, the amount is under $1.00, or target_api_key is not an active key. |
| 429 | Added by proxy.ts: too many requests from your address in the current window. |
| 503 | Crypto payments are off right now, or Stripe could not start the payment. |
Every field, with full descriptions, is in the API reference.
/v1/purchase/{id}/statusPoll a purchase and collect its key once paid
Auth: Recovery code in x-phantom-recovery-code, once paid
Returns the key once paid. Send the recovery code in the x-phantom-recovery-code header.
Request
curl https://phantom.codes/v1/purchase/pay_123/status \ -H "x-phantom-recovery-code: 5xXj_4..."
Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
id | path | string | yes | The payment_id from the purchase call. | |
x-phantom-recovery-code | header | string | no | The recovery code shown at checkout. |
| Status | Meaning |
|---|---|
| 200 | The purchase's state. |
| 400 | No payment id in the path. |
| 404 | No payment has that id. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"status": "pending",
"topped_up": false,
"recovery_required": true,
"credit_usd": 5,
"expires_at": "2026-11-17T02:40:15.596Z",
"pay_currency": null,
"pay_amount": null
}Sample error (404)
{
"error": "Payment not found"
}/v1/purchase/recoverRecover a purchased key from its recovery code
Auth: Recovery code in the body
Request
curl https://phantom.codes/v1/purchase/recover \
-H "Content-Type: application/json" \
-d '{"recovery_code": "5xXj_4..."}'Parameters and responses
| Name | In | Type | Required | Default | What it does |
|---|---|---|---|---|---|
recovery_code | body | string | yes | The recovery code. |
| Status | Meaning |
|---|---|
| 200 | The purchase is paid. |
| 400 | The body is not a JSON object, or recovery_code is missing, not a string, or too short. |
| 404 | No paid purchase has that code. |
| 429 | Added by proxy.ts: too many requests from your address in the current window. |
Every field, with full descriptions, is in the API reference.
Sample response (200)
{
"api_key": "sk-phantom-...",
"credit_usd": 5,
"workspace_id": "f22db223-06b8-4a1b-bc3f-55a50e7c1cc5",
"recovery": {
"version": 1,
"workspace_id": "f22db223-06b8-4a1b-bc3f-55a50e7c1cc5",
"management_credential": "..."
}
}Sample error (404)
{
"error": "No completed payment for that code"
}Account
/v1/account/grantRead the account's past grant and referrals
Auth: Session cookie
Historical grant status. New grants are no longer available. Needs a session cookie.
Request
curl https://phantom.codes/v1/account/grant \ -H "Cookie: better-auth.session_token=..."
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The grant status. |
| 401 | Not signed in. |
| 500 | The session or database read failed. |
Every field, with full descriptions, is in the API reference.
/v1/accountErase the signed-in account and its links
Auth: Session cookie
Deletes grants and referrals and signs you out. API keys keep working: to stop one, call DELETE /v1/key with it, or rotate it.
Request
curl -X DELETE https://phantom.codes/v1/account \ -H "Cookie: better-auth.session_token=..."
Parameters and responses
| Status | Meaning |
|---|---|
| 200 | The data is erased and the sessions ended. |
| 401 | Not signed in. |
| 403 | Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token. |
Every field, with full descriptions, is in the API reference.
Response headers
x-phantom-request-id: req_4f1c9ab2d0e7
x-phantom-content-logged: false
x-phantom-receipt: <base64url payload>.<base64url signature>
# every priced call, except a stream
x-phantom-cost-usd: 0.000420
x-phantom-balance-usd: 1.028916
# chat, messages, responses
x-phantom-upstream-model: deepseek/deepseek-v4.1-flash-1017
x-phantom-upstream-request-id: ...A stream's headers leave before it is billed, so its cost and receipt come in its last event (Receipts).
Generation parameters
| Parameter | Behavior |
|---|---|
reasoning_effort | Passed to the model provider as you sent it. |
thinking | Passed on as you sent it, with one exception on /v1/messages: when budget_tokens is not below the output cap, Phantom lowers it to one under the cap, and drops thinking when that leaves less than 1024. |
max_tokens, max_completion_tokens | Phantom sends the provider a lower number when your balance can't pay for yours, or when yours is over the model's output limit. The cap it used is the one that bounds your spend. |
params_hash | The receipt's params_hash covers temperature, top_p, max_tokens, max_completion_tokens, reasoning_effort, thinking and how many tools you sent, exactly as you sent them. It is a hash of your values, not of the lowered max_tokens or budget_tokens Phantom may send the provider. The receipt's token counts show what the call used. |
model_served | The model name in the provider's response. The receipt check flags it when it differs from model_requested. |