Skip to content

Menu

Docs menu

One request: your agent or code sends it to Phantom, which picks the model and holds the cost (sets aside the most the call could cost). The model answers, and the answer comes back with its cost and a signed receipt (proof of what ran and what it cost) in the headers.

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

  1. Install the Phantom CLI.
npm i -g @phantomcodes/cli

Or 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.sh
  1. phantom setup: Sign in and connect your coding agents. Until you add credit, phantom-1 runs free.
  2. 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!"}]
  }'

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

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.

Privacy controls: the name, where you set it and what it does
ControlWhereWhat it does
zdr: truerequest bodyzdr 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: truerequest bodyOnly providers that don't train on prompts, on the same terms.
x-phantom-free: offrequest headerOn 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 headerYour own OpenAI key, which Phantom never stores, logs or returns. How it bills.
x-anthropic-api-key: sk-ant-...request headerYour own Anthropic key, which Phantom never stores, logs or returns. How it bills.
x-gateway-api-key: vck_...request headerYour 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-loggedresponse headerfalse 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

Calls refused for money: the cause, status, code and what to do
CauseStatusCodeWhat to do
Out of credit402insufficient_quotaAdd 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 budget402budget_exceededThe 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 cap429spend_rate_exceededThe key spent its per-minute cap. Wait the seconds in Retry-After.
Past the free daily limit429noneWait 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-receipt

Check 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.

The x-phantom-receipt header, a whole curl -i response, or a stream’s phantom.receipt event.

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

GET/v1/receipts/key

Read 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
StatusMeaning
200The 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"
}
POST/v1/receipts/anchor

Write 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
NameInTypeRequiredDefaultWhat it does
receiptbodystringyesThe x-phantom-receipt value, as received.
StatusMeaning
200The receipt is anchored, now or earlier.
400Bad JSON, no receipt, or a receipt that does not verify against this deployment's signing key.
401No Bearer key in Authorization, or a key Phantom does not know (Key cannot be charged: not_found.).
402The key cannot pay the fee: inactive, expired, insufficient_balance, budget_exceeded or spend_rate_exceeded, as Key cannot be charged: <reason>.
502The Solana transaction did not land.
503This deployment has no Solana signer configured for anchoring.

Every field, with full descriptions, is in the API reference.

GET/v1/receipts/anchor

Look 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
NameInTypeRequiredDefaultWhat it does
leafquerystringyesSHA-256 of the compact receipt, 64 hex characters.
StatusMeaning
200The anchor, or anchored: false with the hash and network when there is none.
400leaf is missing or not 64 hex characters.

Every field, with full descriptions, is in the API reference.


Model calls

POST/v1/chat/completions

Create 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
NameInTypeRequiredDefaultWhat it does
x-phantom-sessionheaderstringnoYour own conversation id.
x-claude-code-session-idheaderstringnoClaude Code's own session id, which it sends on every request.
x-claude-code-agent-idheaderstringnoSent by Claude Code from its helper agents (such as Explore), never from the main agent.
x-openai-subagentheaderstringnoCodex's helper kind.
x-codex-turn-metadataheaderstringnoCodex's turn metadata, as JSON.
x-codex-parent-thread-idheaderstringnoThe Codex thread a helper thread started from.
x-phantom-agentheaderstringnoThe coding agent a request came through: claude-code, codex, cursor, gemini-cli or coding-agent.
x-phantom-routeheaderstringnoSend off to skip the key's route policy for this request.
x-phantom-escalateheaderstringnoSend 1 when the current model isn't managing the task.
x-phantom-freeheaderstringnoSend 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-keyheaderstringnoYour own OpenAI API key.
x-anthropic-api-keyheaderstringnoYour own Anthropic API key.
x-gateway-api-keyheaderstringnoYour own Vercel AI Gateway API key.
x-phantom-route-debugheaderstringnoSend 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.
routerbodyone of phantom-1, phantom-1:free, phantom-1:privatenoThe router to pick the model: phantom-1, phantom-1:free or phantom-1:private (see GET /v1/routers).
modelbodystringno"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).
messagesbodyarray of objectyesThe conversation, in OpenAI's format.
streambodybooleannofalseAnswer as a server-sent event stream.
stream_optionsbodyobjectnoPassed through, with include_usage forced to true on streams so the usage frame always arrives.
max_tokensbodyintegernoYour output limit.
max_completion_tokensbodyintegernoRead before max_tokens when both are set.
nbodyintegernoAlways sent as 1.
toolsbodyarray of objectnoTool definitions.
functionsbodyarray of objectnoLegacy function definitions.
sortbodyone of cost, ttft, tpsnoHow 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).
zdrbodybooleannoOnly use providers that delete prompts right away (zero data retention).
no_trainingbodybooleannoOnly use providers that don't train on prompts.
providerbodyobjectnoThe upstream's shorthand for provider routing, such as {"sort": "tps"}.
providerOptionsbodyobjectnoPassed to the upstream, except gateway.models, which Phantom replaces with the policy's fallbacks or drops.
router_debugbodybooleannoWhen true, returns phantom-1's score for each model and the one it picked in x-phantom-route-scores header and response body.
StatusMeaning
200The upstream's chat completion, passed through.
400The 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).
401No 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).
402Sent 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.
404The model is not a chat model in the catalog (model_not_found), or it was retired (model_retired, which names the closest current model).
429The key's per-minute spend cap is reached (spend_rate_exceeded).
502Phantom has no upstream key configured, or the upstream could not be reached.
503The 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]
POST/v1/responses

Create 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
NameInTypeRequiredDefaultWhat it does
x-phantom-sessionheaderstringnoYour own conversation id.
x-claude-code-session-idheaderstringnoClaude Code's own session id, which it sends on every request.
x-claude-code-agent-idheaderstringnoSent by Claude Code from its helper agents (such as Explore), never from the main agent.
x-openai-subagentheaderstringnoCodex's helper kind.
x-codex-turn-metadataheaderstringnoCodex's turn metadata, as JSON.
x-codex-parent-thread-idheaderstringnoThe Codex thread a helper thread started from.
x-phantom-agentheaderstringnoThe coding agent a request came through: claude-code, codex, cursor, gemini-cli or coding-agent.
x-phantom-routeheaderstringnoSend off to skip the key's route policy for this request.
x-phantom-escalateheaderstringnoSend 1 when the current model isn't managing the task.
x-phantom-freeheaderstringnoSend 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-keyheaderstringnoYour own OpenAI API key.
x-anthropic-api-keyheaderstringnoYour own Anthropic API key.
x-gateway-api-keyheaderstringnoYour own Vercel AI Gateway API key.
routerbodyone of phantom-1, phantom-1:free, phantom-1:privatenoThe router to pick the model: phantom-1, phantom-1:free or phantom-1:private (see GET /v1/routers).
modelbodystringno"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).
inputbodystringyesThe prompt, or an array of input items (messages, function call outputs).
instructionsbodystringnoThe system prompt.
toolsbodyarray of objectnoTool definitions.
streambodybooleannofalseAnswer as a server-sent event stream.
max_output_tokensbodyintegernoYour output limit.
storebodybooleannoAlways sent as false.
previous_response_idbodystringnoRefused with 400.
sortbodyone of cost, ttft, tpsnoHow to rank the providers that serve the model: cost (the default), ttft (fastest first token) or tps (most tokens per second).
zdrbodybooleannoOnly use providers that delete prompts right away.
no_trainingbodybooleannoOnly use providers that don't train on prompts.
providerOptionsbodyobjectnoPassed to the upstream, except gateway.models, which is dropped.
StatusMeaning
200The upstream's response, passed through, plus phantom.
400The 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.
401No 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.
402Sent 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).
404The model is not a chat model in the catalog, or it was retired.
429The key's per-minute spend cap is reached.
502Phantom has no upstream key configured, or the upstream could not be reached.
503The 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"
  }
}
POST/v1/messages

Create 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
NameInTypeRequiredDefaultWhat it does
anthropic-versionheaderstringnoAnthropic API version, forwarded to the upstream.
anthropic-betaheaderstringnoAnthropic beta flags (prompt caching, long context and the like), forwarded to the upstream unchanged.
x-phantom-sessionheaderstringnoYour own conversation id.
x-claude-code-session-idheaderstringnoClaude Code's own session id, which it sends on every request.
x-claude-code-agent-idheaderstringnoSent by Claude Code from its helper agents (such as Explore), never from the main agent.
x-openai-subagentheaderstringnoCodex's helper kind.
x-codex-turn-metadataheaderstringnoCodex's turn metadata, as JSON.
x-codex-parent-thread-idheaderstringnoThe Codex thread a helper thread started from.
x-phantom-agentheaderstringnoThe coding agent a request came through: claude-code, codex, cursor, gemini-cli or coding-agent.
x-phantom-routeheaderstringnoSend off to skip the key's route policy for this request.
x-phantom-escalateheaderstringnoSend 1 when the current model isn't managing the task.
x-phantom-freeheaderstringnoSend 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-keyheaderstringnoYour own OpenAI API key.
x-anthropic-api-keyheaderstringnoYour own Anthropic API key.
x-gateway-api-keyheaderstringnoYour own Vercel AI Gateway API key.
routerbodyone of phantom-1, phantom-1:free, phantom-1:privatenoThe router to pick the model: phantom-1, phantom-1:free or phantom-1:private (see GET /v1/routers).
modelbodystringnoRequired unless the request sends router.
messagesbodyarray of objectyesThe conversation, in Anthropic's format.
max_tokensbodyintegernoYour output limit.
streambodybooleannofalseAnswer as a server-sent event stream.
systembodystringnoThe system prompt.
toolsbodyarray of objectnoTool definitions.
thinkingbodyobjectnoExtended thinking.
modelsbodyarray of stringnoDropped.
sortbodyone of cost, ttft, tpsnoHow to rank the providers that serve the model: cost (the default), ttft (fastest first token) or tps (most tokens per second).
zdrbodybooleannoOnly use providers that delete prompts right away.
no_trainingbodybooleannoOnly use providers that don't train on prompts.
providerOptionsbodyobjectnoPassed to the upstream, except gateway.models, which is dropped.
StatusMeaning
200The upstream's Anthropic message, passed through.
400The 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).
401No 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.
402Sent 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).
404The model is not a chat model in the catalog, or it was retired (the error names the closest current model).
429The key's per-minute spend cap is reached.
502Phantom has no upstream key configured, or the upstream could not be reached.
503The 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."
  }
}
POST/v1/embeddings

Create 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
NameInTypeRequiredDefaultWhat it does
inputbodyarray of stringyesThe text to embed: a string, an array of strings, or pre-split token ids (an array of numbers, or an array of such arrays).
routerbodyone of phantom-1, phantom-1:free, phantom-1:privatenoA router's name in place of model.
modelbodystringno"phantom-1"phantom-1 runs openai/text-embedding-3-small.
dimensionsbodyintegernoLength of each vector, for models that support it.
StatusMeaning
200The upstream's response, passed through unchanged, in OpenAI's embeddings format.
400The body is not JSON, or input is missing or empty.
401No key (missing_api_key), or a key that does not start with sk- (invalid_api_key).
402The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the estimate (insufficient_balance).
404The 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).
429The key's per-minute spend cap is reached (spend_rate_exceeded).
502The upstream answered with a 5xx status, or the call failed (upstream_unavailable).
503Phantom 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"
  }
}
POST/v1/rerank

Rerank 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
NameInTypeRequiredDefaultWhat it does
querybodystringyesThe text to score the documents against.
documentsbodyarray of stringyesThe documents to score.
routerbodyone of phantom-1, phantom-1:free, phantom-1:privatenoA router's name in place of model.
modelbodystringno"phantom-1"phantom-1 runs voyage/rerank-3.
top_nbodyintegernoReturn only the best top_n results.
StatusMeaning
200The upstream's rerank response, passed through unchanged.
400The body is not JSON, query is missing or empty, or documents is missing or empty.
401No key (missing_api_key), or a key that does not start with sk- (invalid_api_key).
402The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the estimate (insufficient_balance).
404The 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).
429The key's per-minute spend cap is reached (spend_rate_exceeded).
502The upstream answered with a 5xx status, or the call failed (upstream_unavailable).
503Phantom 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"
  }
}
POST/v1/images/generations

Generate 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
NameInTypeRequiredDefaultWhat it does
promptbodystringyesWhat to draw.
routerbodyone of phantom-1, phantom-1:free, phantom-1:privatenoA router's name in place of model.
modelbodystringno"phantom-1"phantom-1 runs bfl/flux-pro-1.1.
nbodyintegerno1How many images.
sizebodystringno"1024x1024"Image size, sent to the upstream unchanged.
response_formatbodystringno"url"How images come back, sent to the upstream unchanged.
StatusMeaning
200The upstream's response, passed through unchanged.
400The body is not JSON, or prompt is missing or not a string.
401No key (missing_api_key), or a key that does not start with sk- (invalid_api_key).
402The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the price (insufficient_balance).
404The 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).
429The key's per-minute spend cap is reached (spend_rate_exceeded).
502The upstream answered with a 5xx status, returned no data array, or the call failed (upstream_unavailable).
503Phantom 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"
  }
}
POST/v1/video/generations

Start 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
NameInTypeRequiredDefaultWhat it does
promptbodystringyesWhat the video shows.
routerbodyone of phantom-1, phantom-1:free, phantom-1:privatenoA router's name in place of model.
modelbodystringno"phantom-1"phantom-1 runs alibaba/wan-v2.7-t2v.
secondsbodyintegerno5Length in whole seconds.
durationbodynumbernoSame as seconds, read only when seconds is absent.
resolutionbodystringnoSaved with the job and nothing more.
sizebodystringnoSame as resolution, read only when resolution is absent.
aspect_ratiobodystringnoWidth to height, such as 16:9.
generate_audiobodybooleannoAsk the model for a soundtrack.
StatusMeaning
202The job started and the key was charged.
400The 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).
401No key (missing_api_key), or a key that does not start with sk- (invalid_api_key).
402The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the video (insufficient_balance).
404The 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).
429The key's per-minute spend cap is reached (spend_rate_exceeded).
502The job did not start, so nothing is billed, or it started but could not be saved and the charge was refunded (upstream_unavailable).
503Phantom 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"
  }
}
GET/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
NameInTypeRequiredDefaultWhat it does
idpathstringyesThe job id from the start call (vid_...).
StatusMeaning
200The job's state.
401No key (missing_api_key), or a key that does not start with sk- (invalid_api_key).
404No job with this id for this key (job_not_found).
502The upstream could not be reached for the status, and the job stays running (upstream_unavailable).
503The 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"
  }
}
POST/v1/audio/speech

Generate 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.mp3
Parameters and responses
NameInTypeRequiredDefaultWhat it does
inputbodystringyesThe text to speak.
routerbodyone of phantom-1, phantom-1:free, phantom-1:privatenoA router's name in place of model.
modelbodystringno"phantom-1"phantom-1 runs openai/tts-1.
voicebodystringnoThe voice to use, passed to the upstream when set.
response_formatbodystringnoThe audio format, passed to the upstream as the output format when set.
speedbodynumbernoPlayback speed, passed to the upstream when set and not zero.
StatusMeaning
200The audio.
400The body is not JSON, or input is missing, empty or not a string.
401No key (missing_api_key), or a key that does not start with sk- (invalid_api_key).
402The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the cost (insufficient_balance).
404The 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).
429The key's per-minute spend cap is reached (spend_rate_exceeded).
502The upstream call failed or returned no audio (upstream_unavailable).
503Phantom 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.

POST/v1/audio/transcriptions

Transcribe 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
StatusMeaning
200The transcript.
400The body is not a multipart form, or it has no file.
401No key (missing_api_key), or a key that does not start with sk- (invalid_api_key).
402The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the held amount (insufficient_balance).
404The 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).
429The key's per-minute spend cap is reached (spend_rate_exceeded).
502The upstream call failed (upstream_unavailable).
503Phantom 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"
  }
}
GET/v1/models/status

Check 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
NameInTypeRequiredDefaultWhat it does
modelquerystringyesA model id from GET /v1/models, or phantom-1.
jobqueryone of chat, vision, embedding, rerank, image, video, speech, transcriptionno"chat"For phantom-1: which of its models to check.
StatusMeaning
200The model's status.
400model is missing, or job is not one of the listed values.
404The upstream has no such model, or could not be reached (model_not_found).

Every field, with full descriptions, is in the API reference.

GET/v1/models

List models with their prices and limits

Auth: None

No key required.

Request

curl https://phantom.codes/v1/models
Parameters and responses
StatusMeaning
200The catalog.

Every field, with full descriptions, is in the API reference.

GET/v1

Describe 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
StatusMeaning
200The service description.
307The 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

GET/v1/key/balance

Read 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
StatusMeaning
200The key's balance.
401No 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"
}
GET/v1/key/budget

Read 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
StatusMeaning
200The caps and pace.
401No 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"
}
PATCH/v1/key/budget

Tighten 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
NameInTypeRequiredDefaultWhat it does
budget_usdbodynumber or nullnoSpend cap per window in US dollars, above zero, and no more than the key's current cap.
period_daysbodyinteger or nullnoWindow length in whole days, no shorter than the current window while the key has a budget.
rate_usd_per_minbodynumber or nullnoPer-minute spend cap in US dollars, above zero, and no more than the key's current cap.
StatusMeaning
200The caps after the change.
400Bad JSON, none of the three fields, or a value out of range.
401No Bearer key, or a key Phantom does not know, has revoked or has expired.
403The change would raise or remove a cap, or shorten the budget's window.
409The 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"
}
GET/v1/key/route

Read 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
StatusMeaning
200The policy, or null when the key has none or the stored one no longer passes the checks.
401No 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"
}
PUT/v1/key/route

Replace 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
NameInTypeRequiredDefaultWhat it does
modelsbodyarray of stringyesThe models this key may route to, up to 10 ids of up to 200 characters.
applies_tobodyone of auto, allno"auto"auto: only model: "auto" requests are routed.
rulesbodyarray of objectnoUp to 20 rules, tried in order.
on_emptybodyone of stop, cheapestno"stop"Once the budget is used up.
fallback_on_errorbodybooleannofalseWhen true, the policy's other chat models go to the upstream as fallbacks if the picked model fails.
stick_minutesbodyintegerno5Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm.
stick_by_promptbodybooleannotrueWithout x-phantom-session, recognise a conversation by a hash of its opening messages, held in memory only.
sortbodyone of cost, ttft, tpsnoDefault provider ranking for this key's chat and messages requests: cost, ttft (fastest first token) or tps (most tokens per second).
zdrbodybooleannoSend this key's requests only to providers that delete prompts right away.
no_trainingbodybooleannoSend this key's requests only to providers that don't train on prompts.
sensitivitybodyone of balanced, conservative, strictno"balanced"How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there.
StatusMeaning
200The policy as stored, with defaults filled in.
400The 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).
401No 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"
}
PATCH/v1/key/route

Update 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
NameInTypeRequiredDefaultWhat it does
modelsbodyarray of stringnoThe models this key may route to, up to 10 ids of up to 200 characters.
applies_tobodyone of auto, allno"auto"auto: only model: "auto" requests are routed.
rulesbodyarray of objectnoUp to 20 rules, tried in order.
on_emptybodyone of stop, cheapestno"stop"Once the budget is used up.
fallback_on_errorbodybooleannofalseWhen true, the policy's other chat models go to the upstream as fallbacks if the picked model fails.
stick_minutesbodyintegerno5Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm.
stick_by_promptbodybooleannotrueWithout x-phantom-session, recognise a conversation by a hash of its opening messages, held in memory only.
sortbodyone of cost, ttft, tpsnoDefault provider ranking for this key's chat and messages requests: cost, ttft (fastest first token) or tps (most tokens per second).
zdrbodybooleannoSend this key's requests only to providers that delete prompts right away.
no_trainingbodybooleannoSend this key's requests only to providers that don't train on prompts.
sensitivitybodyone of balanced, conservative, strictno"balanced"How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there.
StatusMeaning
200The policy as stored, with defaults filled in.
400The body is not a JSON object, the merged policy fails the checks, or it could not be saved.
401No 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"
}
DELETE/v1/key/route

Clear 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
StatusMeaning
200The policy is cleared.
400The policy could not be cleared (the key is inactive, or the write failed).
401No 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"
}
POST/v1/key/route/test

Test 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
NameInTypeRequiredDefaultWhat it does
x-phantom-sessionheaderstringnoYour own conversation id.
x-claude-code-session-idheaderstringnoClaude Code's own session id, which it sends on every request.
x-claude-code-agent-idheaderstringnoSent by Claude Code from its helper agents (such as Explore), never from the main agent.
x-openai-subagentheaderstringnoCodex's helper kind.
x-codex-turn-metadataheaderstringnoCodex's turn metadata, as JSON.
x-codex-parent-thread-idheaderstringnoThe Codex thread a helper thread started from.
x-phantom-routeheaderstringnoSend off to skip the key's route policy for this request.
x-phantom-freeheaderstringnoSend 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-escalateheaderstringnoSend 1 when the current model isn't managing the task.
modelbodystringyesThe model to request, auto, or a router: phantom-1, phantom-1:private or phantom-1:free.
messagesbodyarray of objectnoChat messages.
toolsbodyarray of objectnoTool definitions.
functionsbodyarray of objectnoOlder form of tools, treated the same.
zdrbodybooleannoOnly providers that delete prompts right away, for phantom-1 and auto.
no_trainingbodybooleannoOnly providers that do not train on prompts, for phantom-1, phantom-1:private and auto.
max_tokensbodyintegernoOutput estimate for price comparisons (500 when absent, at most 4000).
max_completion_tokensbodyintegernoRead before max_tokens for the output estimate.
reasoning_effortbodystringnoAny value but none makes reasoning_requested true.
reasoningbodyobjectnoAn object makes reasoning_requested true unless it sets enabled: false or effort: "none".
StatusMeaning
200The decision.
400Bad 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.
401No 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\"."
}
GET/v1/key/lineup

Read 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
StatusMeaning
200The lineup, the model each tier runs, and each tier's suggested models with prices.
401No 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"
}
PUT/v1/key/lineup

Set 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
NameInTypeRequiredDefaultWhat it does
standardbodystring or nullnoThe model every task starts on.
frontierbodystring or nullnoThe model hard steps move up to.
fallbacksbodyobject or nullnoThe fallback model for each tier you name.
StatusMeaning
200The lineup as stored, and the model each tier runs.
400The 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.
401No 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."
}
DELETE/v1/key/lineup

Reset 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
StatusMeaning
200The lineup is cleared.
400The lineup could not be cleared (the key is inactive, or the write failed).
401No 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"
}
DELETE/v1/key

Revoke 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
StatusMeaning
200The key is revoked.
401No Bearer key in Authorization.
404No active key matches the credential.
409Credit is held for a request still running on this key (key_busy).
500The 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."
}
POST/v1/key/rotate

Rotate 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
StatusMeaning
200The new key.
400The key is unknown or inactive, or the database write failed.
401No Bearer key in Authorization.
409Credit 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"
}
GET/v1/privacy

Fetch 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
StatusMeaning
200The report.
401A 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.

GET/v1/bundles

Purchase limits and presets

Auth: None

Request

curl https://phantom.codes/v1/bundles
Parameters and responses
StatusMeaning
200Limits 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
    }
  }
}
GET/v1/coins

List the coins a crypto payment accepts

Auth: None

Request

curl https://phantom.codes/v1/coins
Parameters and responses
StatusMeaning
200The accepted coins.

Every field, with full descriptions, is in the API reference.

POST/v1/purchase/x402

Create 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
NameInTypeRequiredDefaultWhat it does
amount_usdbodynumberyesThe price in whole cents, paid in USDC.
validity_daysbodyintegerno365How long a new key stays valid; a top-up extends the key to at least this.
target_api_keybodystringnoA Phantom key to add the credit to instead of issuing a new one.
workspace_idbodystringnoOptional authorized workspace that receives the credit.
StatusMeaning
200Quote and recovery credential; save the credential privately before paying.
400Invalid 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.
401Workspace authorization required.
403Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.
429Added by proxy.ts: too many requests from your address in the current window.
500Quote could not be stored.
503Stripe 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.

POST/v1/purchase/{id}/x402

Pay 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
NameInTypeRequiredDefaultWhat it does
idpathstringyesIdentifier from the x402 purchase quote.
payment-signatureheaderstringnoSigned x402 payment authorization supplied by a compatible payment client.
StatusMeaning
200Payment received; credit may still be pending Stripe verification.
400Malformed settlement.
402Pay this challenge using a compatible Solana MPP or x402 client.
404Quote not found.
409Expired quote or conflicting transfer.
429Added by proxy.ts: too many requests from your address in the current window.
503Unavailable, 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.

POST/v1/purchase/solana

Start 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
NameInTypeRequiredDefaultWhat it does
coinbodyone of usdc, usdcsolno"usdc"The coin to pay with.
amount_usdbodynumbernoThe price in US dollars, within the limits from GET /v1/bundles.
validity_daysbodyintegerno365Days a new key stays valid, a whole number.
bundlebodyone of test, small, medium, large, whalenoAn old preset name, used only when amount_usd is missing.
target_api_keybodystringnoA key you hold, to add the credit to it rather than get a new key.
StatusMeaning
200The payment is created and waiting for the transfer.
400The 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.
429Added by proxy.ts: too many requests from your address in the current window.
500The payment could not be saved.
503USDC on Solana is off right now.

Every field, with full descriptions, is in the API reference.

POST/v1/purchase/card

Start 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
NameInTypeRequiredDefaultWhat it does
amount_usdbodynumbernoThe price in US dollars, before Stripe's card fee.
validity_daysbodyintegerno365Days a new key stays valid, a whole number.
bundlebodyone of test, small, medium, large, whalenoAn old preset name, used only when amount_usd is missing.
target_api_keybodystringnoA key you hold, to add the credit to it rather than get a new key.
hostedbodybooleannofalseReturn a Stripe-hosted checkout_url instead of a client_secret, for callers with no card form, such as the Phantom CLI.
StatusMeaning
200The payment is created and waiting for the card.
400The 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.
429Added by proxy.ts: too many requests from your address in the current window.
500Stripe or the database failed.
503Card checkout is off because no Stripe key is set.

Every field, with full descriptions, is in the API reference.

POST/v1/purchase/stripe-crypto

Start 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
NameInTypeRequiredDefaultWhat it does
amount_usdbodynumbernoThe price in US dollars, from $1.00 and within the limits from GET /v1/bundles.
validity_daysbodyintegerno365Days a new key stays valid, a whole number.
bundlebodyone of test, small, medium, large, whalenoAn old preset name, used only when amount_usd is missing.
target_api_keybodystringnoA key you hold, to add the credit to it rather than get a new key.
StatusMeaning
200The payment is created and waiting on Stripe's page.
400The 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.
429Added by proxy.ts: too many requests from your address in the current window.
503Crypto payments are off right now, or Stripe could not start the payment.

Every field, with full descriptions, is in the API reference.

GET/v1/purchase/{id}/status

Poll 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
NameInTypeRequiredDefaultWhat it does
idpathstringyesThe payment_id from the purchase call.
x-phantom-recovery-codeheaderstringnoThe recovery code shown at checkout.
StatusMeaning
200The purchase's state.
400No payment id in the path.
404No 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"
}
POST/v1/purchase/recover

Recover 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
NameInTypeRequiredDefaultWhat it does
recovery_codebodystringyesThe recovery code.
StatusMeaning
200The purchase is paid.
400The body is not a JSON object, or recovery_code is missing, not a string, or too short.
404No paid purchase has that code.
429Added 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

GET/v1/account/grant

Read 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
StatusMeaning
200The grant status.
401Not signed in.
500The session or database read failed.

Every field, with full descriptions, is in the API reference.

DELETE/v1/account

Erase 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
StatusMeaning
200The data is erased and the sessions ended.
401Not signed in.
403Added 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

ParameterBehavior
reasoning_effortPassed to the model provider as you sent it.
thinkingPassed 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_tokensPhantom 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_hashThe 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_servedThe model name in the provider's response. The receipt check flags it when it differs from model_requested.