{
  "openapi": "3.1.0",
  "info": {
    "title": "Phantom API",
    "version": "0.1.0",
    "description": "Phantom is an OpenAI-compatible API. You buy credit and spend it with a key. Point an OpenAI SDK at `https://phantom.codes/v1`, or an Anthropic SDK at `https://phantom.codes`.\n\n**Paths.** Every route answers on both `/v1/...` and `/api/v1/...`. This reference lists the `/v1` form.\n\n**Keys.** Send `Authorization: Bearer sk-phantom-...`. The `/v1/messages` routes also take `x-api-key`. Phantom keeps only a hash of the key, so a lost key can be recovered only with the recovery code from checkout.\n\n**Money.** Amounts in JSON are US dollars (`_usd` fields). Internally everything is counted in millionths of a dollar, so a dollar figure has at most six decimal places.\n\n**Receipts.** Priced calls return `x-phantom-receipt`, a signed record of what was served. A chat stream sends it as an `event: phantom.receipt` frame ahead of `data: [DONE]`, and a `/v1/messages` stream ahead of `message_stop`.\n\n**Errors.** Inference routes answer in OpenAI's error format, `/v1/messages` in Anthropic's, and the key and purchase routes mostly as `{\"error\": \"...\"}`. Each operation lists its statuses."
  },
  "servers": [
    {
      "url": "https://phantom.codes"
    }
  ],
  "tags": [
    {
      "name": "Inference",
      "description": "Model calls. Each needs an API key with credit, and each is billed from what the upstream reports."
    },
    {
      "name": "Service",
      "description": "Status, version and what this API offers."
    },
    {
      "name": "Receipts",
      "description": "The receipt signing key, and writing a receipt's hash to Solana."
    },
    {
      "name": "Keys",
      "description": "Balance, spend caps, routing policy, lineup, rotation and revocation for the calling key."
    },
    {
      "name": "Purchases",
      "description": "Buying a key, or credit for a key you hold, by card or on Solana."
    },
    {
      "name": "Account",
      "description": "Account management and historical grant and referral records."
    }
  ],
  "paths": {
    "/api/health": {
      "get": {
        "operationId": "getApiHealth",
        "summary": "Check that the API and database are up",
        "description": "Runs one query against the database and reports whether it answered. Needs no key.",
        "tags": [
          "Service"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The database answered.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "description": "`ok` when the database answered, `degraded` when it did not.",
                      "enum": [
                        "ok",
                        "degraded"
                      ]
                    },
                    "database": {
                      "type": "string",
                      "description": "Whether the database answered a `SELECT 1`.",
                      "enum": [
                        "connected",
                        "disconnected"
                      ]
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "Server time of the check.",
                      "format": "date-time"
                    },
                    "service": {
                      "type": "string",
                      "description": "Always `phantom-api`.",
                      "enum": [
                        "phantom-api"
                      ]
                    }
                  },
                  "required": [
                    "status",
                    "database",
                    "timestamp",
                    "service"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "The database did not answer.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "description": "`ok` when the database answered, `degraded` when it did not.",
                      "enum": [
                        "ok",
                        "degraded"
                      ]
                    },
                    "database": {
                      "type": "string",
                      "description": "Whether the database answered a `SELECT 1`.",
                      "enum": [
                        "connected",
                        "disconnected"
                      ]
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "Server time of the check.",
                      "format": "date-time"
                    },
                    "service": {
                      "type": "string",
                      "description": "Always `phantom-api`.",
                      "enum": [
                        "phantom-api"
                      ]
                    },
                    "error": {
                      "type": "string",
                      "description": "A fixed message. The driver's own error text is logged without the host or user, and never sent."
                    }
                  },
                  "required": [
                    "status",
                    "database",
                    "timestamp",
                    "service",
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/api/version": {
      "get": {
        "operationId": "getApiVersion",
        "summary": "Fetch build and retention info",
        "description": "Names the commit serving the request and states what the API stores. Needs no key.",
        "tags": [
          "Service"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The build and its retention statement.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string",
                      "description": "Always `phantom`.",
                      "enum": [
                        "phantom"
                      ]
                    },
                    "commit": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "The git commit of this build, from `VERCEL_GIT_COMMIT_SHA` or `GIT_COMMIT_SHA`."
                    },
                    "ref": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "The git branch of this build, from `VERCEL_GIT_COMMIT_REF`."
                    },
                    "environment": {
                      "type": "string",
                      "description": "`VERCEL_ENV` (`production`, `preview`), else `NODE_ENV`, else `development`."
                    },
                    "source": {
                      "type": "object",
                      "description": "The source is proprietary: `public` is always `false` and both links are `null`.",
                      "properties": {
                        "public": {
                          "type": "boolean",
                          "description": "Always `false`."
                        },
                        "url": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Always `null`."
                        },
                        "commit_url": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "Always `null`."
                        },
                        "note": {
                          "type": "string",
                          "description": "Says the source is not published."
                        }
                      },
                      "required": [
                        "public",
                        "url",
                        "commit_url",
                        "note"
                      ]
                    },
                    "retention": {
                      "type": "object",
                      "description": "What the `/v1` routes store.",
                      "properties": {
                        "api": {
                          "type": "object",
                          "description": "The statement for API-key routes.",
                          "properties": {
                            "scope": {
                              "type": "string",
                              "description": "Which routes the statement covers."
                            },
                            "request_bodies": {
                              "type": "string",
                              "description": "Whether request bodies are stored."
                            },
                            "response_bodies": {
                              "type": "string",
                              "description": "Whether response bodies are stored."
                            },
                            "stored_per_request": {
                              "type": "array",
                              "description": "The rows written per request, with their columns.",
                              "items": {
                                "type": "string",
                                "description": "A table and its columns."
                              }
                            },
                            "identity_collected": {
                              "type": "string",
                              "description": "What identity the API collects."
                            },
                            "caveat": {
                              "type": "string",
                              "description": "What the upstream model provider sees."
                            }
                          },
                          "required": [
                            "scope",
                            "request_bodies",
                            "response_bodies",
                            "stored_per_request",
                            "identity_collected",
                            "caveat"
                          ]
                        }
                      },
                      "required": [
                        "api"
                      ]
                    }
                  },
                  "required": [
                    "service",
                    "commit",
                    "ref",
                    "environment",
                    "source",
                    "retention"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. Always `no-store`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/claude-code/v1/models": {
      "get": {
        "operationId": "getClaudeCodeV1Models",
        "summary": "List models for Claude Code",
        "description": "The models Claude Code lists in its `/model` picker when you set `ANTHROPIC_BASE_URL=https://phantom.codes/claude-code` and `CLAUDE_CODE_ENABLE_GATEWAY_MODEL_DISCOVERY=1`. Claude Code keeps only ids that contain `claude` or `anthropic`, so each id here starts with `claude-code/`. Phantom drops the prefix again when you send the id as `model`. Lists `phantom-1` first, then current chat models, newest first, leaving out models a newer one from the same maker replaces. Needs no key.",
        "tags": [
          "Inference"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The models, in the shape of Anthropic's model list. Empty when the upstream could not be reached.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "description": "Always `list`.",
                      "enum": [
                        "list"
                      ]
                    },
                    "data": {
                      "type": "array",
                      "description": "One entry per model.",
                      "items": {
                        "type": "object",
                        "description": "A model.",
                        "properties": {
                          "type": {
                            "type": "string",
                            "description": "Always `model`.",
                            "enum": [
                              "model"
                            ]
                          },
                          "id": {
                            "type": "string",
                            "description": "The id to send as `model`.",
                            "examples": [
                              "claude-code/phantom-1"
                            ]
                          },
                          "display_name": {
                            "type": "string",
                            "description": "The name the picker shows."
                          },
                          "description": {
                            "type": "string",
                            "description": "A short description."
                          },
                          "created_at": {
                            "type": "string",
                            "description": "When the upstream published the model, as an ISO 8601 time."
                          }
                        },
                        "required": [
                          "type",
                          "id",
                          "display_name",
                          "created_at"
                        ]
                      }
                    },
                    "has_more": {
                      "type": "boolean",
                      "description": "Always `false`."
                    }
                  },
                  "required": [
                    "object",
                    "data",
                    "has_more"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=300, stale-while-revalidate=3600`: the CDN keeps the answer for 5 minutes.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/codex/v1/models": {
      "get": {
        "operationId": "getCodexV1Models",
        "summary": "List the models Codex can use on Phantom",
        "description": "The models Codex reads when its provider's `base_url` is `https://phantom.codes/codex/v1`. Codex expects its own list format (`{\"models\": [...]}`), and without it falls back to generic settings for every model. Lists only `phantom-1`, `phantom-1:free` and the current Standard and Frontier models (a short list, because each entry carries Codex's own default prompt, about 21 KB). Any other model id still works when named by hand; Codex then warns that it has no metadata for it and uses generic settings. Each entry carries the model's context window, whether it takes images, its reasoning levels and the prompt. Needs no key.",
        "tags": [
          "Inference"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The models. Empty when the upstream could not be reached.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "models": {
                      "type": "array",
                      "description": "One entry per listed model, in the format of Codex's `ModelInfo`. Fields not listed here hold the values Codex uses for a model from another provider.",
                      "items": {
                        "type": "object",
                        "description": "A model.",
                        "properties": {
                          "slug": {
                            "type": "string",
                            "description": "The id to send as `model`.",
                            "examples": [
                              "phantom-1"
                            ]
                          },
                          "display_name": {
                            "type": "string",
                            "description": "The name Codex shows."
                          },
                          "description": {
                            "type": "string",
                            "description": "A short description."
                          },
                          "context_window": {
                            "type": "integer",
                            "description": "Context window in tokens. Left out when the upstream publishes none."
                          },
                          "input_modalities": {
                            "type": "array",
                            "description": "`text`, plus `image` when the model reads images.",
                            "items": {
                              "type": "string",
                              "description": "An input kind."
                            }
                          },
                          "base_instructions": {
                            "type": "string",
                            "description": "The system prompt Codex uses for the model: Codex's own default prompt, the same for every entry. Codex refuses the whole list when an entry has none."
                          },
                          "default_reasoning_level": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "`medium` for reasoning models, else null."
                          }
                        },
                        "required": [
                          "slug",
                          "display_name",
                          "description",
                          "input_modalities",
                          "base_instructions",
                          "default_reasoning_level"
                        ],
                        "additionalProperties": true
                      }
                    }
                  },
                  "required": [
                    "models"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=300, stale-while-revalidate=3600`: the CDN keeps the answer for 5 minutes.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/cursor/v1/chat/completions": {
      "post": {
        "operationId": "postCursorV1ChatCompletions",
        "summary": "Create a chat completion from Cursor",
        "description": "The chat completions API for Cursor. Set Cursor's OpenAI base URL to `https://phantom.codes/cursor/v1`. Cursor can send tool definitions without the `function` wrapper, and Responses-style `input` and `instructions` in place of `messages`. Phantom rewrites those into a standard request, then handles it exactly as `POST /v1/chat/completions`: same auth, billing, headers, receipts and errors. A standard request passes unchanged.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "x-phantom-session",
            "in": "header",
            "required": false,
            "description": "Your own conversation id. phantom-1 keeps a conversation's routing state under it: paid chat starts each task on standard and can move it to frontier on any request, tool calls included. Anthropic messages containing only `tool_result` blocks continue the same user message. Other routing (`auto` with a key policy) can keep one model for the session while `stick_minutes` lasts. Only the first 200 characters count. Without this header, Phantom uses Claude Code's `x-claude-code-session-id` when it arrives, and otherwise groups requests by prompt or conversation opening, depending on the route. Phantom stores a salted hash with the selected model and expiry, and keeps provider affinity for the session so its prompt cache stays warm.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-session-id",
            "in": "header",
            "required": false,
            "description": "Claude Code's own session id, which it sends on every request. When `x-phantom-session` is missing, Phantom uses this the same way: the first 200 characters, hashed under the key.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-agent-id",
            "in": "header",
            "required": false,
            "description": "Sent by Claude Code from its helper agents (such as Explore), never from the main agent. phantom-1 runs a helper's request on Standard. Phantom reads only whether the header has a value.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-subagent",
            "in": "header",
            "required": false,
            "description": "Codex's helper kind. phantom-1 runs `collab_spawn`, `thread_spawn` and `review` on Standard; other kinds, such as `compact`, route as usual.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-turn-metadata",
            "in": "header",
            "required": false,
            "description": "Codex's turn metadata, as JSON. phantom-1 reads only `subagent_kind`, `thread_source` and `parent_thread_id`, to tell a helper's request apart as with `x-openai-subagent`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-parent-thread-id",
            "in": "header",
            "required": false,
            "description": "The Codex thread a helper thread started from. With `thread_source` set to `subagent` in `x-codex-turn-metadata`, it marks a helper's request.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-agent",
            "in": "header",
            "required": false,
            "description": "The coding agent a request came through: `claude-code`, `codex`, `cursor`, `gemini-cli` or `coding-agent`. Phantom sets it when you call an agent's base path (`https://phantom.codes/codex/v1`). Any other value is ignored.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route",
            "in": "header",
            "required": false,
            "description": "Send `off` to skip the key's route policy for this request. The request runs on the model it names; `model: \"auto\"` is refused with a 400.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-escalate",
            "in": "header",
            "required": false,
            "description": "Send `1` when the current model isn't managing the task. phantom-1 moves this request one tier up, from standard to frontier. It picks again on the next request, so send the header on each request that should stay up, tool calls included. A key's route policy moves it to the policy's last model. Phantom can't tell a weak answer from a good one, so escalation is your call.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-free",
            "in": "header",
            "required": false,
            "description": "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. A key with credit never runs a free model on phantom-1, so there the header changes nothing.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-api-key",
            "in": "header",
            "required": false,
            "description": "Your own OpenAI API key. On a call an OpenAI model serves, it is tried first, and a call it served costs nothing on Phantom: OpenAI bills you. If OpenAI refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-anthropic-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Anthropic API key. On a call an Anthropic model serves, it is tried first, and a call it served costs nothing on Phantom: Anthropic bills you. If Anthropic refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-gateway-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Vercel AI Gateway API key. The call runs on it in place of Phantom's key, so your Gateway account pays for it and Phantom charges $0: nothing is held, and a key with no credit runs `phantom-1` on paid models rather than as `phantom-1:free`. The key's budget and spend-rate cap still apply. If the Gateway refuses the key you get a `401` (`invalid_gateway_key`), or a `402` (`gateway_key_no_credit`) when its account is out of credit; the call never falls back to Phantom's key. Provider keys sent with it run inside your Gateway account. Phantom never stores, logs or returns the key. `phantom-1:free` ignores it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route-debug",
            "in": "header",
            "required": false,
            "description": "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`. For debugging only; the format may change.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "A chat completions request, in OpenAI's format or Cursor's.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "router": {
                    "type": "string",
                    "description": "The router to pick the model: `phantom-1`, `phantom-1:free` or `phantom-1:private` (see `GET /v1/routers`). Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`. Phantom removes it before calling the upstream.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "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). Renamed ids resolve to the current one. `phantom-1` with an image routes like any request, on a tier whose model can read images. `phantom-1:free` runs only free models, at $0, and needs no credit. `phantom-1:private` routes between models with zero data retention and no training on every provider, and requires both on every call. The retired `phantom-1:zdr` answers 400 `router_retired`.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "messages": {
                    "type": "array",
                    "description": "The conversation, in OpenAI's format. Needed unless you send `input`.",
                    "examples": [
                      [
                        {
                          "role": "user",
                          "content": "Hello"
                        }
                      ]
                    ],
                    "items": {
                      "type": "object",
                      "description": "A message.",
                      "additionalProperties": true
                    }
                  },
                  "stream": {
                    "type": "boolean",
                    "description": "Answer as a server-sent event stream.",
                    "default": false
                  },
                  "stream_options": {
                    "type": "object",
                    "description": "Passed through, with `include_usage` forced to `true` on streams so the usage frame always arrives.",
                    "additionalProperties": true
                  },
                  "max_tokens": {
                    "type": "integer",
                    "description": "Your output limit. Phantom sends the smallest of this, what the balance buys after the prompt, and the model's output cap, shrunk to what the hold covers."
                  },
                  "max_completion_tokens": {
                    "type": "integer",
                    "description": "Read before `max_tokens` when both are set. When sent, Phantom replaces it with the same limit it sends as `max_tokens`."
                  },
                  "n": {
                    "type": "integer",
                    "description": "Always sent as 1. One completion per request."
                  },
                  "tools": {
                    "type": "array",
                    "description": "Tool definitions. A flat `{name, description, parameters}` is wrapped as `{type: \"function\", function: {...}}`.",
                    "items": {
                      "type": "object",
                      "description": "A tool.",
                      "additionalProperties": true
                    }
                  },
                  "functions": {
                    "type": "array",
                    "description": "Legacy function definitions. Count toward the prompt estimate.",
                    "items": {
                      "type": "object",
                      "description": "A function.",
                      "additionalProperties": true
                    }
                  },
                  "sort": {
                    "type": "string",
                    "description": "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). Overrides the key's route policy. Phantom removes it before calling the upstream.",
                    "enum": [
                      "cost",
                      "ttft",
                      "tps"
                    ],
                    "examples": [
                      "ttft"
                    ]
                  },
                  "zdr": {
                    "type": "boolean",
                    "description": "Only use providers that delete prompts right away (zero data retention). Off by default. Overrides the key's route policy. With it on, phantom-1 skips its free model. Phantom removes it before calling the upstream."
                  },
                  "no_training": {
                    "type": "boolean",
                    "description": "Only use providers that don't train on prompts. Phantom removes it before calling the upstream."
                  },
                  "provider": {
                    "type": "object",
                    "description": "The upstream's shorthand for provider routing, such as `{\"sort\": \"tps\"}`. `order`, `only` and `sort` pass through, and when it sets `sort`, Phantom sends no default sort. Phantom drops what it sets itself (`caching`, `has`, `models`, `tags`, and a `false` `zeroDataRetention` or `disallowPromptTraining`) and what costs more than the hold (`serviceTier`, `speed`, `sharedRequestType`, `inferenceRegion`, `cache_ttl`).",
                    "additionalProperties": true
                  },
                  "providerOptions": {
                    "type": "object",
                    "description": "Passed to the upstream, except `gateway.models`, which Phantom replaces with the policy's fallbacks or drops. `gateway.order` still chooses among providers of the same model. Your `gateway` settings win over `sort`. They can't turn off `zdr` or `no_training`. `order` (providers to try first), `only` (the only providers allowed) and `sort` all pass through. Phantom also drops `serviceTier`, `speed` and `sharedRequestType` from `gateway` and from the options of every provider (`openai`, `google`, `vertex`, `xai`, `anthropic`), and a top-level `service_tier` or `speed`, so a call runs at the standard tier. It also drops `inferenceRegion` (a pinned region costs more), `inference_geo`, `cache_ttl` and, on chat, `web_search_options` (a search the hold cannot count), and the `ttl` of any `cache_control` or `cacheControl` (a one-hour cache costs 2x input to write, against the 1.25x Phantom bills), so a call uses the upstream's own region choice and the five-minute cache.",
                    "additionalProperties": true
                  },
                  "router_debug": {
                    "type": "boolean",
                    "description": "When true, returns phantom-1's score for each model and the one it picked in `x-phantom-route-scores` header and response body. Phantom removes it before calling the upstream."
                  },
                  "input": {
                    "type": "array",
                    "description": "Responses-style input items, turned into `messages` when `messages` is missing. A string counts as one user message.",
                    "items": {
                      "type": "object",
                      "description": "An input item.",
                      "additionalProperties": true
                    }
                  },
                  "instructions": {
                    "type": "string",
                    "description": "With `input`: sent as a system message first."
                  }
                },
                "additionalProperties": true
              },
              "example": {
                "model": "phantom-1",
                "messages": [
                  {
                    "role": "user",
                    "content": "Hello"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upstream's chat completion, passed through. Other statuses from the upstream also come back as the upstream sent them; nothing is billed then.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The completion id."
                    },
                    "object": {
                      "type": "string",
                      "description": "`chat.completion`."
                    },
                    "created": {
                      "type": "integer",
                      "description": "Unix time, in seconds, the upstream made the completion."
                    },
                    "model": {
                      "type": "string",
                      "description": "The model the upstream reports running. Billing uses this model's rate when the catalog carries it."
                    },
                    "choices": {
                      "type": "array",
                      "description": "The completion. One choice, since `n` is forced to 1.",
                      "items": {
                        "type": "object",
                        "description": "A choice.",
                        "additionalProperties": true
                      }
                    },
                    "usage": {
                      "type": "object",
                      "description": "What Phantom bills from. When the token counts are missing, Phantom estimates them.",
                      "properties": {
                        "prompt_tokens": {
                          "type": "integer",
                          "description": "Input tokens."
                        },
                        "completion_tokens": {
                          "type": "integer",
                          "description": "Output tokens."
                        },
                        "cost": {
                          "type": "number",
                          "description": "What the upstream charged, in US dollars. Billed as-is unless it is more than 100 times the catalog price."
                        }
                      },
                      "additionalProperties": true
                    },
                    "phantom": {
                      "type": "object",
                      "description": "Added by Phantom: what this call cost and how it was served.",
                      "properties": {
                        "cost_usd": {
                          "type": "number",
                          "description": "What this call was charged, in US dollars. Same as `x-phantom-cost-usd`."
                        },
                        "provider": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The provider that answered, or null when the upstream did not say."
                        },
                        "attempts": {
                          "type": "integer",
                          "description": "Provider attempts across every model tried. 1 when the first try worked."
                        },
                        "fallback": {
                          "type": "boolean",
                          "description": "`true` when a provider or model failed and another one answered."
                        }
                      }
                    }
                  }
                },
                "example": {
                  "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
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "With `stream: true`: the upstream's `data: {chunk}` lines, passed through, ending with `data: [DONE]`. Right before the chunk that holds `data: [DONE]`, Phantom inserts `event: phantom.receipt` with `data: {\"receipt\":\"<compact receipt>\",\"phantom\":{...}}`, where `phantom` has the same fields as in a non-streaming answer. That receipt's `output_hash` covers the text you received. Without a signing key the event carries `phantom` only."
                }
              }
            },
            "headers": {
              "x-phantom-request-id": {
                "description": "Phantom's id for this request (`req_` + 24 hex characters). The same value is `request_id` in the receipt. Also sent when the upstream refuses the call and its error is passed through.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-router": {
                "description": "The router that picked the model: `phantom-1`, `phantom-1:free` or `phantom-1:private`. Sent when the request named a router in `router` or `model`, or sent `model: \"auto\"` on a key with no route policy. The body's `model` names the model that ran. Also sent with a passed-through upstream error. The body adds `router` with the same name, and in a stream the `phantom.receipt` event carries it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-routed": {
                "description": "Present only when the key's route policy picked the model: the model id, then `; reason=` and what decided it. A rule shows as `<condition>:<value>`; other reasons are `default` (the policy's first model), `requested`, `cache` (kept on the conversation's model) and `on_empty` (past the budget, the cheapest model). A `phantom-1` call never sends it; see `x-phantom-route-receipt`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-receipt": {
                "description": "Sent on routed `phantom-1` calls: the model you asked for, the tier and model that ran, how sure phantom-1 was when the pick gives a confidence, and a short reason label. Reason labels may change. Sent on routed phantom-1 calls: names requested model, served tier, underlying model, confidence when the pick gives one, and reason.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-scores": {
                "description": "phantom-1's score for each model and the one it picked. Sent only when you ask with `x-phantom-route-debug: 1` or `router_debug: true`. For debugging only; the format may change. Sent when x-phantom-route-debug: 1 or router_debug: true is requested: returns phantom-1's score for each model and the one it picked.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-model": {
                "description": "The model id Phantom sent to the upstream. On chat and messages, the receipt's `model_served` holds the id the upstream reported running. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-request-id": {
                "description": "The upstream's own request id, copied from its `x-request-id` response header when it sends one. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. Non-streaming answers only. `model_requested` is the id you sent after renames (`auto` stays `auto`), `model_served` is the `model` field of the upstream's answer, and `reasoning_tokens` comes from `usage.completion_tokens_details`. A stream carries the receipt in the body instead.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cached-tokens": {
                "description": "Prompt tokens the upstream served from its cache, billed at the cached rate. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars. Non-streaming answers only. A stream carries it in the `phantom.receipt` event.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-provider": {
                "description": "The provider that answered, such as `anthropic`, `bedrock` or `azure`. Left out when the upstream does not say. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-fallback": {
                "description": "`true` when a provider or model failed and another one answered the call, `false` when the first try worked. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. Non-streaming answers only. A stream's headers leave before it is billed.",
                "schema": {
                  "type": "string"
                }
              },
              "cache-control": {
                "description": "Caching rules for the response. Streams only: `no-cache`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "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). `phantom-1:free` answers `free_model_unfit` when no free model can take the request (images, tools, long context). `phantom-1:private` answers `private_model_unfit` when none of its zero-data-retention models can take the request. With `zdr` on, `zdr_unavailable` means no provider of the model has zero data retention; nothing ran and nothing is billed. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "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`). A call can't pay for itself with x402 or MPP. Or the Vercel AI Gateway refused the key in `x-gateway-api-key` (`invalid_gateway_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "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. Then: the key is past its spend cap and its policy did not move the request to its cheapest model (`budget_exceeded`), or it holds less than $0.001, cannot pay for the prompt alone, cannot buy 32 output tokens after it, or the hold failed (`insufficient_quota`). Or the Vercel AI Gateway account behind `x-gateway-api-key` is out of credit or past its budget (`gateway_key_no_credit`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "Not enough credit ($0.0000 left). Top up at https://phantom.codes/checkout.",
                    "type": "insufficient_quota",
                    "code": "insufficient_quota"
                  }
                }
              }
            }
          },
          "404": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`). On free models (`phantom-1:free`, and `phantom-1` or `auto` from a key with no credit), counted per workspace: 20 requests a minute (`free_rate_exceeded`) or the daily cap (`free_daily_cap`): 50 a day, 200 a day through a coding agent base path (such as `/codex/v1`), or 1,000 a day once the workspace has taken in $10 of credit. The message says how to raise the cap.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "Phantom has no upstream key configured, or the upstream could not be reached. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "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`). Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/gemini-cli/v1beta/models/{target}": {
      "post": {
        "operationId": "postGeminiCliV1betaModelsTarget",
        "summary": "Gemini CLI: generate, stream or count tokens",
        "description": "Google's Gemini API, for Gemini CLI. Set `GOOGLE_GEMINI_BASE_URL=https://phantom.codes/gemini-cli` and `GEMINI_API_KEY` to your Phantom key, and pick a model such as `phantom-1`; `phantom setup` does this for you.\n\n`<model>:generateContent` and `<model>:streamGenerateContent?alt=sse` turn the request into a chat request and handle it exactly as `POST /v1/chat/completions` (same auth, billing, limits and receipts), then answer in Google's format. Gemini CLI's own background calls name bare Google models such as `gemini-3.5-flash-lite`: Phantom runs every bare `gemini-*` name on `phantom-1`, so they work on a key with no credit too. To run a Google model, name it with its maker, as in `google/<model>`.\n\n`<model>:countTokens` answers an estimate (about four characters a token) and needs no key.\n\nLeft out on the way: Google's own tools (Search, code execution), `topK`, safety settings and thinking settings. A stream sends text and thinking as they arrive and each tool call whole in the last chunk, with the finish reason and usage; Phantom's `phantom.receipt` event is not sent.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "googleKey": []
          },
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "target",
            "in": "path",
            "required": true,
            "description": "The model, a colon, and the method: `phantom-1:streamGenerateContent`, `phantom-1:free:generateContent` or `phantom-1:countTokens`. A model id with a slash takes more than one path segment (`google/<model>:generateContent`).",
            "schema": {
              "type": "string",
              "description": "The model, a colon, and the method: `phantom-1:streamGenerateContent`, `phantom-1:free:generateContent` or `phantom-1:countTokens`. A model id with a slash takes more than one path segment (`google/<model>:generateContent`)."
            }
          },
          {
            "name": "alt",
            "in": "query",
            "required": false,
            "description": "Sent by Google's SDK with `streamGenerateContent`. The answer is an event stream whatever it says.",
            "schema": {
              "type": "string",
              "description": "Sent by Google's SDK with `streamGenerateContent`. The answer is an event stream whatever it says.",
              "enum": [
                "sse"
              ]
            }
          },
          {
            "name": "x-phantom-session",
            "in": "header",
            "required": false,
            "description": "Your own conversation id. phantom-1 keeps a conversation's routing state under it: paid chat starts each task on standard and can move it to frontier on any request, tool calls included. Anthropic messages containing only `tool_result` blocks continue the same user message. Other routing (`auto` with a key policy) can keep one model for the session while `stick_minutes` lasts. Only the first 200 characters count. Without this header, Phantom uses Claude Code's `x-claude-code-session-id` when it arrives, and otherwise groups requests by prompt or conversation opening, depending on the route. Phantom stores a salted hash with the selected model and expiry, and keeps provider affinity for the session so its prompt cache stays warm.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-session-id",
            "in": "header",
            "required": false,
            "description": "Claude Code's own session id, which it sends on every request. When `x-phantom-session` is missing, Phantom uses this the same way: the first 200 characters, hashed under the key.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-agent-id",
            "in": "header",
            "required": false,
            "description": "Sent by Claude Code from its helper agents (such as Explore), never from the main agent. phantom-1 runs a helper's request on Standard. Phantom reads only whether the header has a value.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-subagent",
            "in": "header",
            "required": false,
            "description": "Codex's helper kind. phantom-1 runs `collab_spawn`, `thread_spawn` and `review` on Standard; other kinds, such as `compact`, route as usual.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-turn-metadata",
            "in": "header",
            "required": false,
            "description": "Codex's turn metadata, as JSON. phantom-1 reads only `subagent_kind`, `thread_source` and `parent_thread_id`, to tell a helper's request apart as with `x-openai-subagent`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-parent-thread-id",
            "in": "header",
            "required": false,
            "description": "The Codex thread a helper thread started from. With `thread_source` set to `subagent` in `x-codex-turn-metadata`, it marks a helper's request.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-agent",
            "in": "header",
            "required": false,
            "description": "The coding agent a request came through: `claude-code`, `codex`, `cursor`, `gemini-cli` or `coding-agent`. Phantom sets it when you call an agent's base path (`https://phantom.codes/codex/v1`). Any other value is ignored. Set to `gemini-cli` by the base path.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route",
            "in": "header",
            "required": false,
            "description": "Send `off` to skip the key's route policy for this request. The request runs on the model it names; `model: \"auto\"` is refused with a 400.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-escalate",
            "in": "header",
            "required": false,
            "description": "Send `1` when the current model isn't managing the task. phantom-1 moves this request one tier up, from standard to frontier. It picks again on the next request, so send the header on each request that should stay up, tool calls included. A key's route policy moves it to the policy's last model. Phantom can't tell a weak answer from a good one, so escalation is your call.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-free",
            "in": "header",
            "required": false,
            "description": "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. A key with credit never runs a free model on phantom-1, so there the header changes nothing.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-api-key",
            "in": "header",
            "required": false,
            "description": "Your own OpenAI API key. On a call an OpenAI model serves, it is tried first, and a call it served costs nothing on Phantom: OpenAI bills you. If OpenAI refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-anthropic-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Anthropic API key. On a call an Anthropic model serves, it is tried first, and a call it served costs nothing on Phantom: Anthropic bills you. If Anthropic refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-gateway-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Vercel AI Gateway API key. The call runs on it in place of Phantom's key, so your Gateway account pays for it and Phantom charges $0: nothing is held, and a key with no credit runs `phantom-1` on paid models rather than as `phantom-1:free`. The key's budget and spend-rate cap still apply. If the Gateway refuses the key you get a `401` (`invalid_gateway_key`), or a `402` (`gateway_key_no_credit`) when its account is out of credit; the call never falls back to Phantom's key. Provider keys sent with it run inside your Gateway account. Phantom never stores, logs or returns the key. `phantom-1:free` ignores it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route-debug",
            "in": "header",
            "required": false,
            "description": "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`. For debugging only; the format may change.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-goog-api-key",
            "in": "header",
            "required": false,
            "description": "A Phantom API key, the way Google's SDK and Gemini CLI send it. Phantom passes it on as `Authorization: Bearer`.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "A Gemini `GenerateContentRequest`. `countTokens` also takes one wrapped in `generateContentRequest`.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "contents": {
                    "type": "array",
                    "description": "The conversation. `role` is `user` or `model`.",
                    "items": {
                      "type": "object",
                      "description": "One message.",
                      "properties": {
                        "role": {
                          "type": "string",
                          "description": "`user` or `model`."
                        },
                        "parts": {
                          "type": "array",
                          "description": "`text` (a part with `thought: true` is left out), `inlineData` (an image is sent as an image, anything else as a file), `fileData` (sent as an image URL), `functionCall` on a `model` message, and `functionResponse` on a `user` message, matched to its call by `id`.",
                          "items": {
                            "type": "object",
                            "description": "One part.",
                            "additionalProperties": true
                          }
                        }
                      },
                      "required": [
                        "parts"
                      ]
                    }
                  },
                  "systemInstruction": {
                    "type": "object",
                    "description": "Sent as a system message first: the text of its `parts`.",
                    "additionalProperties": true
                  },
                  "tools": {
                    "type": "array",
                    "description": "Each `functionDeclarations` entry becomes a function tool. `parametersJsonSchema` is used as it is; `parameters` (Google's schema, upper-case types) is turned into JSON Schema.",
                    "items": {
                      "type": "object",
                      "description": "A tool.",
                      "additionalProperties": true
                    }
                  },
                  "toolConfig": {
                    "type": "object",
                    "description": "`functionCallingConfig.mode`: `AUTO`, `ANY` (with one `allowedFunctionNames` entry, that tool) or `NONE`.",
                    "additionalProperties": true
                  },
                  "generationConfig": {
                    "type": "object",
                    "description": "`temperature`, `topP`, `maxOutputTokens`, `stopSequences`, and `responseMimeType: \"application/json\"` with `responseSchema` or `responseJsonSchema` are kept. The rest is left out.",
                    "additionalProperties": true
                  },
                  "generateContentRequest": {
                    "type": "object",
                    "description": "`countTokens` only: the request to count.",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "contents"
                ],
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "A Gemini `GenerateContentResponse`, or `{totalTokens}` for `countTokens`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "candidates": {
                      "type": "array",
                      "description": "One candidate: `content.parts` (thinking as `text` with `thought: true`, the answer as `text`, tool calls as `functionCall`), `finishReason` (`STOP`, `MAX_TOKENS`, `SAFETY` or `OTHER`) and `index`.",
                      "items": {
                        "type": "object",
                        "description": "A candidate.",
                        "additionalProperties": true
                      }
                    },
                    "usageMetadata": {
                      "type": "object",
                      "description": "`promptTokenCount`, `candidatesTokenCount` (the answer without thinking), `thoughtsTokenCount`, `cachedContentTokenCount` and `totalTokenCount`, from the chat call's usage.",
                      "additionalProperties": true
                    },
                    "modelVersion": {
                      "type": "string",
                      "description": "The model that ran."
                    },
                    "responseId": {
                      "type": "string",
                      "description": "The upstream's id for the call."
                    },
                    "totalTokens": {
                      "type": "integer",
                      "description": "`countTokens` only: the estimate."
                    }
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "With `streamGenerateContent`: `data:` frames, each a `GenerateContentResponse`. The last one carries the tool calls, `finishReason` and `usageMetadata`."
                }
              }
            },
            "headers": {
              "x-phantom-request-id": {
                "description": "Phantom's id for this request (`req_` + 24 hex characters). The same value is `request_id` in the receipt. Also sent when the upstream refuses the call and its error is passed through.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-router": {
                "description": "The router that picked the model: `phantom-1`, `phantom-1:free` or `phantom-1:private`. Sent when the request named a router in `router` or `model`, or sent `model: \"auto\"` on a key with no route policy. The body's `model` names the model that ran. Also sent with a passed-through upstream error. The body adds `router` with the same name, and in a stream the `phantom.receipt` event carries it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-routed": {
                "description": "Present only when the key's route policy picked the model: the model id, then `; reason=` and what decided it. A rule shows as `<condition>:<value>`; other reasons are `default` (the policy's first model), `requested`, `cache` (kept on the conversation's model) and `on_empty` (past the budget, the cheapest model). A `phantom-1` call never sends it; see `x-phantom-route-receipt`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-receipt": {
                "description": "Sent on routed `phantom-1` calls: the model you asked for, the tier and model that ran, how sure phantom-1 was when the pick gives a confidence, and a short reason label. Reason labels may change. Sent on routed phantom-1 calls: names requested model, served tier, underlying model, confidence when the pick gives one, and reason.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-scores": {
                "description": "phantom-1's score for each model and the one it picked. Sent only when you ask with `x-phantom-route-debug: 1` or `router_debug: true`. For debugging only; the format may change. Sent when x-phantom-route-debug: 1 or router_debug: true is requested: returns phantom-1's score for each model and the one it picked.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-model": {
                "description": "The model id Phantom sent to the upstream. On chat and messages, the receipt's `model_served` holds the id the upstream reported running. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-request-id": {
                "description": "The upstream's own request id, copied from its `x-request-id` response header when it sends one. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. Non-streaming answers only. `model_requested` is the id you sent after renames (`auto` stays `auto`), `model_served` is the `model` field of the upstream's answer, and `reasoning_tokens` comes from `usage.completion_tokens_details`. A stream carries the receipt in the body instead.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cached-tokens": {
                "description": "Prompt tokens the upstream served from its cache, billed at the cached rate. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars. Non-streaming answers only. A stream carries it in the `phantom.receipt` event.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-provider": {
                "description": "The provider that answered, such as `anthropic`, `bedrock` or `azure`. Left out when the upstream does not say. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-fallback": {
                "description": "`true` when a provider or model failed and another one answered the call, `false` when the first try worked. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. Non-streaming answers only. A stream's headers leave before it is billed.",
                "schema": {
                  "type": "string"
                }
              },
              "cache-control": {
                "description": "Caching rules for the response. Streams only: `no-cache`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "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). `phantom-1:free` answers `free_model_unfit` when no free model can take the request (images, tools, long context). `phantom-1:private` answers `private_model_unfit` when none of its zero-data-retention models can take the request. With `zdr` on, `zdr_unavailable` means no provider of the model has zero data retention; nothing ran and nothing is billed. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleError"
                }
              }
            }
          },
          "401": {
            "description": "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`). A call can't pay for itself with x402 or MPP. Or the Vercel AI Gateway refused the key in `x-gateway-api-key` (`invalid_gateway_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleError"
                }
              }
            }
          },
          "402": {
            "description": "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. Then: the key is past its spend cap and its policy did not move the request to its cheapest model (`budget_exceeded`), or it holds less than $0.001, cannot pay for the prompt alone, cannot buy 32 output tokens after it, or the hold failed (`insufficient_quota`). Or the Vercel AI Gateway account behind `x-gateway-api-key` is out of credit or past its budget (`gateway_key_no_credit`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleError"
                }
              }
            }
          },
          "404": {
            "description": "The path names no method Phantom serves, or the model is not a chat model in the catalog.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`). On free models (`phantom-1:free`, and `phantom-1` or `auto` from a key with no credit), counted per workspace: 20 requests a minute (`free_rate_exceeded`) or the daily cap (`free_daily_cap`): 50 a day, 200 a day through a coding agent base path (such as `/codex/v1`), or 1,000 a day once the workspace has taken in $10 of credit. The message says how to raise the cap.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "Phantom has no upstream key configured, or the upstream could not be reached. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleError"
                }
              }
            }
          },
          "503": {
            "description": "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`). Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/GoogleError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1": {
      "get": {
        "operationId": "getV1",
        "summary": "Describe the API and where its docs are",
        "description": "A JSON description of the API and the paths of its main routes. Needs no key. A browser that asks for HTML is sent to `/docs` instead.\n\n**Accept:** When it contains `text/html`, the answer is a 307 redirect to `/docs`.",
        "tags": [
          "Service"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The service description.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "description": "Always `ok`.",
                      "enum": [
                        "ok"
                      ]
                    },
                    "name": {
                      "type": "string",
                      "description": "Service name."
                    },
                    "description": {
                      "type": "string",
                      "description": "One line about the service."
                    },
                    "base_url": {
                      "type": "string",
                      "description": "`https://phantom.codes/v1`.",
                      "format": "uri"
                    },
                    "documentation": {
                      "type": "string",
                      "description": "Link to the docs.",
                      "format": "uri"
                    },
                    "endpoints": {
                      "type": "object",
                      "description": "Inference route paths by name.",
                      "properties": {
                        "chat": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "models": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "embeddings": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "images": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "audio": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "transcriptions": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "rerank": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "video": {
                          "type": "string",
                          "description": "A route path."
                        }
                      }
                    },
                    "key_lifecycle": {
                      "type": "object",
                      "description": "Paths for buying and managing a key, by name.",
                      "properties": {
                        "purchase": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "purchase_status": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "balance": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "budget": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "rotate": {
                          "type": "string",
                          "description": "A route path."
                        },
                        "burn": {
                          "type": "string",
                          "description": "A route path."
                        }
                      }
                    }
                  },
                  "required": [
                    "status",
                    "name",
                    "description",
                    "base_url",
                    "documentation",
                    "endpoints",
                    "key_lifecycle"
                  ]
                },
                "example": {
                  "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"
                  }
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=300, stale-while-revalidate=3600`: the CDN keeps the JSON answer for 5 minutes. The redirect is never kept.",
                "schema": {
                  "type": "string"
                }
              },
              "vary": {
                "description": "The request headers the answer depends on. A shared cache keeps one copy of the answer per value of each. `Accept`: the CDN keeps one copy per `Accept` value, so a browser still gets the redirect.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "307": {
            "description": "The request accepts `text/html`: a redirect to `/docs`."
          }
        }
      },
      "options": {
        "operationId": "optionsV1",
        "summary": "Preflight",
        "description": "Answers a browser preflight request with no body.",
        "tags": [
          "Service"
        ],
        "security": [],
        "responses": {
          "204": {
            "description": "No content."
          }
        }
      }
    },
    "/v1/account": {
      "delete": {
        "operationId": "deleteV1Account",
        "summary": "Erase the signed-in account and its links",
        "description": "Deletes grants, referrals and workspace ownership, disables automatic reload, and ends sessions, including this browser's workspace session: the `phantom_workspace` cookie is cleared. Paid keys and balance remain accessible with the guest recovery files returned here; save them before leaving. Neon Auth retains the sign-in identity, and the hashed grant ledger remains as historical payment records.",
        "tags": [
          "Account"
        ],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "The data is erased and the sessions ended.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deleted": {
                      "type": "boolean",
                      "description": "Always `true`.",
                      "enum": [
                        true
                      ]
                    },
                    "identity_removed": {
                      "type": "boolean",
                      "description": "Always `false`: the email address stays with the sign-in provider.",
                      "enum": [
                        false
                      ]
                    },
                    "recovery_files": {
                      "type": "array",
                      "description": "Private guest recovery files for detached workspaces. Save each file before leaving."
                    }
                  },
                  "required": [
                    "deleted",
                    "identity_removed"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for recovery credentials.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/account/grant": {
      "get": {
        "operationId": "getV1AccountGrant",
        "summary": "Read the account's past grant and referrals",
        "description": "Historical grants and referral earnings for the signed-in account. New grants are no longer issued.",
        "tags": [
          "Account"
        ],
        "security": [
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "The grant status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user_id": {
                      "type": "string",
                      "description": "The signed-in user's id."
                    },
                    "claimed": {
                      "type": "boolean",
                      "description": "This account has a grant row."
                    },
                    "claimed_at": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "When the grant was claimed, or `null`."
                    },
                    "grant_amount_usd": {
                      "type": "number",
                      "description": "Always zero: new grants are no longer available."
                    },
                    "referral_stats": {
                      "type": "object",
                      "description": "Referrals this account made. Zeros when the read fails.",
                      "properties": {
                        "total_referrals": {
                          "type": "integer",
                          "description": "Referrals recorded."
                        },
                        "total_bonus_usd": {
                          "type": "number",
                          "description": "Referrer bonuses recorded, in US dollars. A recorded bonus counts even when the referrer had no active grant key to receive it."
                        }
                      },
                      "required": [
                        "total_referrals",
                        "total_bonus_usd"
                      ]
                    }
                  },
                  "required": [
                    "user_id",
                    "claimed",
                    "claimed_at",
                    "grant_amount_usd",
                    "referral_stats"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Not signed in.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "500": {
            "description": "The session or database read failed. `error` carries the message.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postV1AccountGrant",
        "summary": "Claim a grant (ended; answers 410)",
        "description": "Grant issuance and referral rewards have ended. Existing balances and grant history are unchanged.",
        "tags": [
          "Account"
        ],
        "security": [],
        "responses": {
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "410": {
            "description": "The grant program has ended.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/audio/speech": {
      "post": {
        "operationId": "postV1AudioSpeech",
        "summary": "Generate speech audio from text",
        "description": "Turns text into audio in OpenAI's speech format and returns the raw audio bytes. Phantom prices the call per input character at the model's published rate, holds that cost on the key, and calls the upstream through the AI SDK. It bills only once audio is in hand. A failed call, or an empty audio file, bills nothing and returns the hold.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "input": {
                    "type": "string",
                    "description": "The text to speak. Must be a non-empty string. Its length in characters sets the price.",
                    "examples": [
                      "Hello from Phantom."
                    ]
                  },
                  "router": {
                    "type": "string",
                    "description": "A router's name in place of `model`. Here it runs the model that router names for this endpoint, as `model: \"phantom-1\"` does. Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "`phantom-1` runs `openai/tts-1`. A speech model id from `GET /v1/models`. Aliases resolve to the catalog id.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "voice": {
                    "type": "string",
                    "description": "The voice to use, passed to the upstream when set.",
                    "examples": [
                      "alloy"
                    ]
                  },
                  "response_format": {
                    "type": "string",
                    "description": "The audio format, passed to the upstream as the output format when set.",
                    "examples": [
                      "mp3"
                    ]
                  },
                  "speed": {
                    "type": "number",
                    "description": "Playback speed, passed to the upstream when set and not zero."
                  }
                },
                "required": [
                  "input"
                ]
              },
              "example": {
                "model": "phantom-1",
                "input": "Hello from Phantom.",
                "voice": "alloy"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The audio. The media type is what the upstream reports, `audio/mpeg` when it reports none.",
            "content": {
              "audio/mpeg": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            },
            "headers": {
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. On this route `model_served` is the model id Phantom sent, `prompt_tokens` is the number of input characters, `upstream_request_id` is `null`, and `output_hash` covers the audio's byte count and media type rather than the audio itself.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The body is not JSON, or `input` is missing, empty or not a string. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "No key (`missing_api_key`), or a key that does not start with `sk-` (`invalid_api_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the cost (`insufficient_balance`). Also sent when the hold could not be placed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "The upstream call failed or returned no audio (`upstream_unavailable`). Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Phantom has no upstream key configured (`upstream_unavailable`), or the model has no published per-character rate (`model_unpriced`). Also sent when the upstream refuses Phantom's own account (its credit or budget is used up, or its key is rejected), or when Phantom can't load its model list. Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/audio/transcriptions": {
      "post": {
        "operationId": "postV1AudioTranscriptions",
        "summary": "Transcribe speech audio into text",
        "description": "Turns an audio file into text, taking OpenAI's multipart form. Phantom guesses the length of the audio from its size (16,000 bytes per second, which errs long), holds the cost of that length on the key, and calls the upstream through the AI SDK. It then bills the duration the model reports, or the held amount when the model reports none. Models priced per second bill per second; token-priced models bill 25 input tokens per second of audio. A failed call bills nothing and returns the hold.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "file": {
                    "type": "string",
                    "description": "The audio file.",
                    "format": "binary"
                  },
                  "router": {
                    "type": "string",
                    "description": "A router's name in place of `model`. Here it runs the model that router names for this endpoint, as `model: \"phantom-1\"` does. Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "`phantom-1` runs `microsoft/mai-transcribe-2`. A transcription model id from `GET /v1/models`. Aliases resolve to the catalog id.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  }
                },
                "required": [
                  "file"
                ]
              },
              "example": {
                "model": "phantom-1"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The transcript.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "text": {
                      "type": "string",
                      "description": "The transcribed text."
                    },
                    "language": {
                      "type": "string",
                      "description": "The spoken language, when the model reports it."
                    },
                    "duration": {
                      "type": "number",
                      "description": "Length of the audio in seconds, when the model reports it."
                    },
                    "segments": {
                      "type": "array",
                      "description": "Timed pieces of the transcript, when the model returns any.",
                      "items": {
                        "type": "object",
                        "description": "One segment.",
                        "properties": {
                          "text": {
                            "type": "string",
                            "description": "The text of this segment."
                          },
                          "startSecond": {
                            "type": "number",
                            "description": "Where it starts, in seconds."
                          },
                          "endSecond": {
                            "type": "number",
                            "description": "Where it ends, in seconds."
                          }
                        }
                      }
                    }
                  },
                  "required": [
                    "text"
                  ]
                },
                "example": {
                  "text": "hello there",
                  "language": "en",
                  "duration": 4
                }
              }
            },
            "headers": {
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. On this route `model_served` is the model id Phantom sent, the token counts are 0, `upstream_request_id` is `null`, `input_hash` covers the model id and the reported duration rather than your file, and `output_hash` covers the transcript text.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The body is not a multipart form, or it has no `file`. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "No key (`missing_api_key`), or a key that does not start with `sk-` (`invalid_api_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the held amount (`insufficient_balance`). Also sent when the hold could not be placed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "Insufficient balance or inactive API key",
                    "type": "insufficient_quota",
                    "code": "insufficient_balance"
                  }
                }
              }
            }
          },
          "404": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "The upstream call failed (`upstream_unavailable`). Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Phantom has no upstream key configured (`upstream_unavailable`). Also sent when the upstream refuses Phantom's own account (its credit or budget is used up, or its key is rejected), or when Phantom can't load its model list. Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/device": {
      "post": {
        "operationId": "postV1AuthDevice",
        "summary": "Start a Phantom CLI device login",
        "description": "Starts a device login ([RFC 8628](https://www.rfc-editor.org/rfc/rfc8628)), the way `phantom login --card` signs in to a card account. Show the user `user_code` and send them to `verification_uri`, where they sign in and approve the code. Then poll `POST /v1/auth/device/token` with `device_code` every `interval` seconds. Needs no API key. Limited to 20 a minute per client address, counted together with the polls of `POST /v1/auth/device/token`.",
        "tags": [
          "Keys"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "client_name": {
                    "type": "string",
                    "description": "What the CLI calls itself, shown on the approval page and used as the key name. Up to 60 characters. Defaults to `CLI login`.",
                    "examples": [
                      "phantom on laptop"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The login started.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "device_code": {
                      "type": "string",
                      "description": "Secret. Poll with it; Phantom keeps only its hash."
                    },
                    "user_code": {
                      "type": "string",
                      "description": "The code the user checks on the approval page, as `XXXX-XXXX`.",
                      "examples": [
                        "BCDF-GHJK"
                      ]
                    },
                    "verification_uri": {
                      "type": "string",
                      "description": "The approval page, on the site the request went to. A request to a Phantom preview gets that preview's page; any other host gets phantom.codes.",
                      "format": "uri",
                      "examples": [
                        "https://phantom.codes/device"
                      ]
                    },
                    "verification_uri_complete": {
                      "type": "string",
                      "description": "The approval page with the code filled in.",
                      "format": "uri",
                      "examples": [
                        "https://phantom.codes/device?code=BCDF-GHJK"
                      ]
                    },
                    "expires_in": {
                      "type": "integer",
                      "description": "Seconds until both codes stop working.",
                      "examples": [
                        600
                      ]
                    },
                    "interval": {
                      "type": "integer",
                      "description": "Seconds to wait between polls.",
                      "examples": [
                        5
                      ]
                    }
                  },
                  "required": [
                    "device_code",
                    "user_code",
                    "verification_uri",
                    "verification_uri_complete",
                    "expires_in",
                    "interval"
                  ]
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "More than 20 requests in a minute from this address to `/v1/auth/device` and `/v1/auth/device/token` together.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/auth/device/token": {
      "post": {
        "operationId": "postV1AuthDeviceToken",
        "summary": "Poll a Phantom CLI device login for its key",
        "description": "Polls a login started with `POST /v1/auth/device`. Answers `400` with an RFC 8628 error until the user approves the code on `/device`. On the first poll after approval, Phantom makes an account key named after the client and returns it; Phantom keeps only its hash, and a later poll with the same code gets `invalid_grant`. Needs no API key.",
        "tags": [
          "Keys"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "device_code": {
                    "type": "string",
                    "description": "The `device_code` from `POST /v1/auth/device`."
                  }
                },
                "required": [
                  "device_code"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Approved. The key, returned once.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_key": {
                      "type": "string",
                      "description": "An account key that spends from the account balance. Shown once."
                    },
                    "key_name": {
                      "type": "string",
                      "description": "Its name on the account page: the `client_name` the login started with."
                    }
                  },
                  "required": [
                    "api_key",
                    "key_name"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `no-store`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Not approved yet, polled too often, expired, denied, or already used.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "`authorization_pending`: not approved yet, poll again. `slow_down`: polled sooner than `interval`; add 5 seconds to it. `expired_token`: the code expired, start over. `access_denied`: the user denied it. `invalid_grant`: unknown device code, or it was already used. `invalid_request`: no `device_code`.",
                      "enum": [
                        "authorization_pending",
                        "slow_down",
                        "expired_token",
                        "access_denied",
                        "invalid_grant",
                        "invalid_request"
                      ]
                    },
                    "error_description": {
                      "type": "string",
                      "description": "The same, in words."
                    }
                  },
                  "required": [
                    "error",
                    "error_description"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `no-store`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "More than 20 requests in a minute from this address to `/v1/auth/device` and `/v1/auth/device/token` together (they share one count).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/bundles": {
      "get": {
        "operationId": "getV1Bundles",
        "summary": "Purchase limits and presets",
        "description": "The amounts you can pay, the margin and card fee, and how long a key can stay valid. The presets are shortcut amounts for the checkout page; any amount inside the limits is accepted. Needs no key.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Limits and presets.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "data": {
                      "type": "array",
                      "description": "Preset amounts, smallest first.",
                      "items": {
                        "type": "object",
                        "description": "A preset.",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "The price as a label, such as `$5`.",
                            "examples": [
                              "$5"
                            ]
                          },
                          "price_usd": {
                            "type": "number",
                            "description": "What you pay, before any card fee.",
                            "examples": [
                              5
                            ]
                          },
                          "credit_usd": {
                            "type": "number",
                            "description": "Credit the key receives: the price divided by `1 + markup_percent / 100`, plus the bonus for its tier in `bonus_tiers`. Equal to the price for every preset while `markup_percent` is 0.",
                            "examples": [
                              5
                            ]
                          },
                          "validity_days": {
                            "type": "integer",
                            "description": "Days the key stays valid, the default validity."
                          }
                        },
                        "required": [
                          "name",
                          "price_usd",
                          "credit_usd",
                          "validity_days"
                        ]
                      }
                    },
                    "custom": {
                      "type": "object",
                      "description": "Limits for any amount.",
                      "properties": {
                        "min_usd": {
                          "type": "number",
                          "description": "Smallest price accepted on any payment method."
                        },
                        "max_usd": {
                          "type": "number",
                          "description": "Largest price accepted on any payment method."
                        },
                        "card_min_usd": {
                          "type": "number",
                          "description": "Smallest price accepted by card."
                        },
                        "markup_percent": {
                          "type": "number",
                          "description": "Margin taken from the price before credit is issued. Credit is the price divided by `1 + markup_percent / 100`. Currently 0."
                        },
                        "bonus_tiers": {
                          "type": "array",
                          "description": "Bonus credit on a bigger purchase, the same on card, Solana and x402. The credit is the price plus `bonus_percent` of it once the price reaches `min_usd`. Largest tier first.",
                          "items": {
                            "type": "object",
                            "description": "One tier.",
                            "properties": {
                              "min_usd": {
                                "type": "number",
                                "description": "The price this tier starts at.",
                                "examples": [
                                  100
                                ]
                              },
                              "bonus_percent": {
                                "type": "number",
                                "description": "Extra credit, as a percent of the price.",
                                "examples": [
                                  1
                                ]
                              }
                            },
                            "required": [
                              "min_usd",
                              "bonus_percent"
                            ]
                          }
                        },
                        "card_fixed_fee_free_from_usd": {
                          "type": "number",
                          "description": "From this price Phantom pays Stripe's fixed fee, so the card total leaves it out. Below it the total includes the fixed fee.",
                          "examples": [
                            50
                          ]
                        },
                        "card_fee_bps": {
                          "type": "integer",
                          "description": "Stripe's percentage on a card charge, in basis points (290 is 2.9%). Stripe takes it from the whole charge, so the card total is `ceil((price_cents + fixed_cents) / (1 - card_fee_bps / 10000))` cents, where `fixed_cents` is 30 below `card_fixed_fee_free_from_usd` and 0 from it.",
                          "examples": [
                            290
                          ]
                        },
                        "card_fee_percent": {
                          "type": "number",
                          "description": "For older clients: the percentage that, with `card_fee_fixed_usd`, reproduces the card total as `price * (1 + card_fee_percent / 100) + card_fee_fixed_usd`, within a cent. It is not Stripe's own rate; use `card_fee_bps`.",
                          "examples": [
                            2.986612
                          ]
                        },
                        "card_fee_fixed_usd": {
                          "type": "number",
                          "description": "For older clients: the fixed amount in the formula under `card_fee_percent`, in US dollars. From `card_fixed_fee_free_from_usd` the card total has no fixed amount, so that formula comes out about 31 cents too high.",
                          "examples": [
                            0.30896
                          ]
                        },
                        "validity_days": {
                          "type": "object",
                          "description": "How long a key can stay valid.",
                          "properties": {
                            "min": {
                              "type": "integer",
                              "description": "Fewest days."
                            },
                            "max": {
                              "type": "integer",
                              "description": "Most days."
                            },
                            "default": {
                              "type": "integer",
                              "description": "Days used when the purchase names none."
                            }
                          },
                          "required": [
                            "min",
                            "max",
                            "default"
                          ]
                        }
                      },
                      "required": [
                        "min_usd",
                        "max_usd",
                        "card_min_usd",
                        "markup_percent",
                        "bonus_tiers",
                        "card_fixed_fee_free_from_usd",
                        "card_fee_bps",
                        "card_fee_percent",
                        "card_fee_fixed_usd",
                        "validity_days"
                      ]
                    }
                  },
                  "required": [
                    "data",
                    "custom"
                  ]
                },
                "example": {
                  "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
                    }
                  }
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=300, stale-while-revalidate=3600`: the CDN keeps the answer for 5 minutes.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/chat/completions": {
      "post": {
        "operationId": "postV1ChatCompletions",
        "summary": "Create a chat completion",
        "description": "OpenAI's chat completions API, streaming or not. Phantom checks the key, runs its route policy (which picks the model for `model: \"auto\"`), estimates the prompt from the messages and tool definitions, and holds the worst-case cost on the key. It sets `max_tokens` to the output the hold covers, calls the upstream, and bills the cost the upstream reports in `usage.cost`, or the catalog rate for the reported tokens, at the rate of the model the upstream says it served. Every price includes Phantom's 5% markup on the upstream's rate, the same rates `GET /v1/models` lists. A refused or failed call bills nothing and returns the hold.\n\nA stream bills when it ends: finished, cut off by an error, or abandoned by you. When the usage frame never arrived, the prompt and output tokens fall back to estimates (about four characters per token, tool-call arguments included).\n\nWith the policy's `fallback_on_error` on, the upstream tries the policy's other models in the same call when the routed one fails. Phantom always asks the upstream to add prompt-cache markers where a provider needs them (`caching: \"auto\"`), and tries the cheapest provider of the model first (`sort: \"cost\"`) unless you set `sort`.\n\n`sort`, `zdr` and `no_training` choose providers; the key's route policy can set them too, and the request wins.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "x-phantom-session",
            "in": "header",
            "required": false,
            "description": "Your own conversation id. phantom-1 keeps a conversation's routing state under it: paid chat starts each task on standard and can move it to frontier on any request, tool calls included. Anthropic messages containing only `tool_result` blocks continue the same user message. Other routing (`auto` with a key policy) can keep one model for the session while `stick_minutes` lasts. Only the first 200 characters count. Without this header, Phantom uses Claude Code's `x-claude-code-session-id` when it arrives, and otherwise groups requests by prompt or conversation opening, depending on the route. Phantom stores a salted hash with the selected model and expiry, and keeps provider affinity for the session so its prompt cache stays warm.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-session-id",
            "in": "header",
            "required": false,
            "description": "Claude Code's own session id, which it sends on every request. When `x-phantom-session` is missing, Phantom uses this the same way: the first 200 characters, hashed under the key.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-agent-id",
            "in": "header",
            "required": false,
            "description": "Sent by Claude Code from its helper agents (such as Explore), never from the main agent. phantom-1 runs a helper's request on Standard. Phantom reads only whether the header has a value.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-subagent",
            "in": "header",
            "required": false,
            "description": "Codex's helper kind. phantom-1 runs `collab_spawn`, `thread_spawn` and `review` on Standard; other kinds, such as `compact`, route as usual.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-turn-metadata",
            "in": "header",
            "required": false,
            "description": "Codex's turn metadata, as JSON. phantom-1 reads only `subagent_kind`, `thread_source` and `parent_thread_id`, to tell a helper's request apart as with `x-openai-subagent`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-parent-thread-id",
            "in": "header",
            "required": false,
            "description": "The Codex thread a helper thread started from. With `thread_source` set to `subagent` in `x-codex-turn-metadata`, it marks a helper's request.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-agent",
            "in": "header",
            "required": false,
            "description": "The coding agent a request came through: `claude-code`, `codex`, `cursor`, `gemini-cli` or `coding-agent`. Phantom sets it when you call an agent's base path (`https://phantom.codes/codex/v1`). Any other value is ignored.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route",
            "in": "header",
            "required": false,
            "description": "Send `off` to skip the key's route policy for this request. The request runs on the model it names; `model: \"auto\"` is refused with a 400.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-escalate",
            "in": "header",
            "required": false,
            "description": "Send `1` when the current model isn't managing the task. phantom-1 moves this request one tier up, from standard to frontier. It picks again on the next request, so send the header on each request that should stay up, tool calls included. A key's route policy moves it to the policy's last model. Phantom can't tell a weak answer from a good one, so escalation is your call.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-free",
            "in": "header",
            "required": false,
            "description": "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. A key with credit never runs a free model on phantom-1, so there the header changes nothing.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-api-key",
            "in": "header",
            "required": false,
            "description": "Your own OpenAI API key. On a call an OpenAI model serves, it is tried first, and a call it served costs nothing on Phantom: OpenAI bills you. If OpenAI refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-anthropic-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Anthropic API key. On a call an Anthropic model serves, it is tried first, and a call it served costs nothing on Phantom: Anthropic bills you. If Anthropic refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-gateway-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Vercel AI Gateway API key. The call runs on it in place of Phantom's key, so your Gateway account pays for it and Phantom charges $0: nothing is held, and a key with no credit runs `phantom-1` on paid models rather than as `phantom-1:free`. The key's budget and spend-rate cap still apply. If the Gateway refuses the key you get a `401` (`invalid_gateway_key`), or a `402` (`gateway_key_no_credit`) when its account is out of credit; the call never falls back to Phantom's key. Provider keys sent with it run inside your Gateway account. Phantom never stores, logs or returns the key. `phantom-1:free` ignores it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route-debug",
            "in": "header",
            "required": false,
            "description": "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`. For debugging only; the format may change.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "An OpenAI chat completions request. Fields not listed go to the upstream unchanged.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "router": {
                    "type": "string",
                    "description": "The router to pick the model: `phantom-1`, `phantom-1:free` or `phantom-1:private` (see `GET /v1/routers`). Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`. Phantom removes it before calling the upstream.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "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). Renamed ids resolve to the current one. `phantom-1` with an image routes like any request, on a tier whose model can read images. `phantom-1:free` runs only free models, at $0, and needs no credit. `phantom-1:private` routes between models with zero data retention and no training on every provider, and requires both on every call. The retired `phantom-1:zdr` answers 400 `router_retired`.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "messages": {
                    "type": "array",
                    "description": "The conversation, in OpenAI's format. Counts toward the prompt estimate, the route policy's conditions, and routing memory. phantom-1 picks a tier for each new user message and keeps it through tool calls; key policies can keep a model by conversation opening.",
                    "examples": [
                      [
                        {
                          "role": "user",
                          "content": "Hello"
                        }
                      ]
                    ],
                    "items": {
                      "type": "object",
                      "description": "A message.",
                      "additionalProperties": true
                    }
                  },
                  "stream": {
                    "type": "boolean",
                    "description": "Answer as a server-sent event stream.",
                    "default": false
                  },
                  "stream_options": {
                    "type": "object",
                    "description": "Passed through, with `include_usage` forced to `true` on streams so the usage frame always arrives.",
                    "additionalProperties": true
                  },
                  "max_tokens": {
                    "type": "integer",
                    "description": "Your output limit. Phantom sends the smallest of this, what the balance buys after the prompt, and the model's output cap, shrunk to what the hold covers."
                  },
                  "max_completion_tokens": {
                    "type": "integer",
                    "description": "Read before `max_tokens` when both are set. When sent, Phantom replaces it with the same limit it sends as `max_tokens`."
                  },
                  "n": {
                    "type": "integer",
                    "description": "Always sent as 1. One completion per request."
                  },
                  "tools": {
                    "type": "array",
                    "description": "Tool definitions. Count toward the prompt estimate. Phantom forwards function and custom tools, `namespace`, `local_shell`, `apply_patch`, a `shell` with `environment.type: \"local\"`, `tool_search*`, `mcp`, `mcp_toolset`, `bash_*`, `text_editor_*`, `computer_*`, `memory_*`, and the search and fetch tools below. It drops every other tool type without an error, including any it does not know, because a server tool can bill per call. A `web_search*` tool adds the model's price per search, or $0.01 when the upstream lists none, times its `max_uses` to the hold, so a key needs that much more balance. Phantom sets `max_uses` to 5 when you send none and lowers it to 10 when you send more. A `web_fetch*` tool gets `max_uses` the same way and a `max_content_tokens` of at most 20,000, and the hold adds those tokens at the model's input rate. OpenAI's `web_search`, `web_search_preview` and their dated variants have no `max_uses`: on `/v1/responses` Phantom sets `max_tool_calls` to the same count, and on the other routes it drops them. On `phantom-1:free`, and on `phantom-1` from a key with no credit, Phantom drops every `web_search*` tool: each search costs money even on a free model.",
                    "items": {
                      "type": "object",
                      "description": "A tool.",
                      "additionalProperties": true
                    }
                  },
                  "functions": {
                    "type": "array",
                    "description": "Legacy function definitions. Count toward the prompt estimate.",
                    "items": {
                      "type": "object",
                      "description": "A function.",
                      "additionalProperties": true
                    }
                  },
                  "sort": {
                    "type": "string",
                    "description": "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). Overrides the key's route policy. Phantom removes it before calling the upstream.",
                    "enum": [
                      "cost",
                      "ttft",
                      "tps"
                    ],
                    "examples": [
                      "ttft"
                    ]
                  },
                  "zdr": {
                    "type": "boolean",
                    "description": "Only use providers that delete prompts right away (zero data retention). Off by default. Overrides the key's route policy. With it on, phantom-1 skips its free model. Phantom removes it before calling the upstream."
                  },
                  "no_training": {
                    "type": "boolean",
                    "description": "Only use providers that don't train on prompts. Phantom removes it before calling the upstream."
                  },
                  "provider": {
                    "type": "object",
                    "description": "The upstream's shorthand for provider routing, such as `{\"sort\": \"tps\"}`. `order`, `only` and `sort` pass through, and when it sets `sort`, Phantom sends no default sort. Phantom drops what it sets itself (`caching`, `has`, `models`, `tags`, and a `false` `zeroDataRetention` or `disallowPromptTraining`) and what costs more than the hold (`serviceTier`, `speed`, `sharedRequestType`, `inferenceRegion`, `cache_ttl`).",
                    "additionalProperties": true
                  },
                  "providerOptions": {
                    "type": "object",
                    "description": "Passed to the upstream, except `gateway.models`, which Phantom replaces with the policy's fallbacks or drops. `gateway.order` still chooses among providers of the same model. Your `gateway` settings win over `sort`. They can't turn off `zdr` or `no_training`. `order` (providers to try first), `only` (the only providers allowed) and `sort` all pass through. Phantom also drops `serviceTier`, `speed` and `sharedRequestType` from `gateway` and from the options of every provider (`openai`, `google`, `vertex`, `xai`, `anthropic`), and a top-level `service_tier` or `speed`, so a call runs at the standard tier. It also drops `inferenceRegion` (a pinned region costs more), `inference_geo`, `cache_ttl` and, on chat, `web_search_options` (a search the hold cannot count), and the `ttl` of any `cache_control` or `cacheControl` (a one-hour cache costs 2x input to write, against the 1.25x Phantom bills), so a call uses the upstream's own region choice and the five-minute cache.",
                    "additionalProperties": true
                  },
                  "router_debug": {
                    "type": "boolean",
                    "description": "When true, returns phantom-1's score for each model and the one it picked in `x-phantom-route-scores` header and response body. Phantom removes it before calling the upstream."
                  }
                },
                "required": [
                  "messages"
                ],
                "additionalProperties": true
              },
              "example": {
                "model": "phantom-1",
                "messages": [
                  {
                    "role": "user",
                    "content": "Hello"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upstream's chat completion, passed through. Other statuses from the upstream also come back as the upstream sent them; nothing is billed then.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The completion id."
                    },
                    "object": {
                      "type": "string",
                      "description": "`chat.completion`."
                    },
                    "created": {
                      "type": "integer",
                      "description": "Unix time, in seconds, the upstream made the completion."
                    },
                    "model": {
                      "type": "string",
                      "description": "The model the upstream reports running. Billing uses this model's rate when the catalog carries it."
                    },
                    "choices": {
                      "type": "array",
                      "description": "The completion. One choice, since `n` is forced to 1.",
                      "items": {
                        "type": "object",
                        "description": "A choice.",
                        "additionalProperties": true
                      }
                    },
                    "usage": {
                      "type": "object",
                      "description": "What Phantom bills from. When the token counts are missing, Phantom estimates them.",
                      "properties": {
                        "prompt_tokens": {
                          "type": "integer",
                          "description": "Input tokens."
                        },
                        "completion_tokens": {
                          "type": "integer",
                          "description": "Output tokens."
                        },
                        "cost": {
                          "type": "number",
                          "description": "What the upstream charged, in US dollars. Billed as-is unless it is more than 100 times the catalog price."
                        }
                      },
                      "additionalProperties": true
                    },
                    "phantom": {
                      "type": "object",
                      "description": "Added by Phantom: what this call cost and how it was served.",
                      "properties": {
                        "cost_usd": {
                          "type": "number",
                          "description": "What this call was charged, in US dollars. Same as `x-phantom-cost-usd`."
                        },
                        "provider": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The provider that answered, or null when the upstream did not say."
                        },
                        "attempts": {
                          "type": "integer",
                          "description": "Provider attempts across every model tried. 1 when the first try worked."
                        },
                        "fallback": {
                          "type": "boolean",
                          "description": "`true` when a provider or model failed and another one answered."
                        }
                      }
                    }
                  }
                },
                "example": {
                  "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
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "With `stream: true`: the upstream's `data: {chunk}` lines, passed through, ending with `data: [DONE]`. Right before the chunk that holds `data: [DONE]`, Phantom inserts `event: phantom.receipt` with `data: {\"receipt\":\"<compact receipt>\",\"phantom\":{...}}`, where `phantom` has the same fields as in a non-streaming answer. That receipt's `output_hash` covers the text you received. Without a signing key the event carries `phantom` only."
                }
              }
            },
            "headers": {
              "x-phantom-request-id": {
                "description": "Phantom's id for this request (`req_` + 24 hex characters). The same value is `request_id` in the receipt. Also sent when the upstream refuses the call and its error is passed through.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-router": {
                "description": "The router that picked the model: `phantom-1`, `phantom-1:free` or `phantom-1:private`. Sent when the request named a router in `router` or `model`, or sent `model: \"auto\"` on a key with no route policy. The body's `model` names the model that ran. Also sent with a passed-through upstream error. The body adds `router` with the same name, and in a stream the `phantom.receipt` event carries it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-routed": {
                "description": "Present only when the key's route policy picked the model: the model id, then `; reason=` and what decided it. A rule shows as `<condition>:<value>`; other reasons are `default` (the policy's first model), `requested`, `cache` (kept on the conversation's model) and `on_empty` (past the budget, the cheapest model). A `phantom-1` call never sends it; see `x-phantom-route-receipt`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-receipt": {
                "description": "Sent on routed `phantom-1` calls: the model you asked for, the tier and model that ran, how sure phantom-1 was when the pick gives a confidence, and a short reason label. Reason labels may change. Sent on routed phantom-1 calls: names requested model, served tier, underlying model, confidence when the pick gives one, and reason.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-scores": {
                "description": "phantom-1's score for each model and the one it picked. Sent only when you ask with `x-phantom-route-debug: 1` or `router_debug: true`. For debugging only; the format may change. Sent when x-phantom-route-debug: 1 or router_debug: true is requested: returns phantom-1's score for each model and the one it picked.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-model": {
                "description": "The model id Phantom sent to the upstream. On chat and messages, the receipt's `model_served` holds the id the upstream reported running. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-request-id": {
                "description": "The upstream's own request id, copied from its `x-request-id` response header when it sends one. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. Non-streaming answers only. `model_requested` is the id you sent after renames (`auto` stays `auto`), `model_served` is the `model` field of the upstream's answer, and `reasoning_tokens` comes from `usage.completion_tokens_details`. A stream carries the receipt in the body instead.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cached-tokens": {
                "description": "Prompt tokens the upstream served from its cache, billed at the cached rate. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars. Non-streaming answers only. A stream carries it in the `phantom.receipt` event.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-provider": {
                "description": "The provider that answered, such as `anthropic`, `bedrock` or `azure`. Left out when the upstream does not say. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-fallback": {
                "description": "`true` when a provider or model failed and another one answered the call, `false` when the first try worked. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. Non-streaming answers only. A stream's headers leave before it is billed.",
                "schema": {
                  "type": "string"
                }
              },
              "cache-control": {
                "description": "Caching rules for the response. Streams only: `no-cache`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "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). `phantom-1:free` answers `free_model_unfit` when no free model can take the request (images, tools, long context). `phantom-1:private` answers `private_model_unfit` when none of its zero-data-retention models can take the request. With `zdr` on, `zdr_unavailable` means no provider of the model has zero data retention; nothing ran and nothing is billed. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "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`). A call can't pay for itself with x402 or MPP. Or the Vercel AI Gateway refused the key in `x-gateway-api-key` (`invalid_gateway_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "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. Then: the key is past its spend cap and its policy did not move the request to its cheapest model (`budget_exceeded`), or it holds less than $0.001, cannot pay for the prompt alone, cannot buy 32 output tokens after it, or the hold failed (`insufficient_quota`). Or the Vercel AI Gateway account behind `x-gateway-api-key` is out of credit or past its budget (`gateway_key_no_credit`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "Not enough credit ($0.0000 left). Top up at https://phantom.codes/checkout.",
                    "type": "insufficient_quota",
                    "code": "insufficient_quota"
                  }
                }
              }
            }
          },
          "404": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`). On free models (`phantom-1:free`, and `phantom-1` or `auto` from a key with no credit), counted per workspace: 20 requests a minute (`free_rate_exceeded`) or the daily cap (`free_daily_cap`): 50 a day, 200 a day through a coding agent base path (such as `/codex/v1`), or 1,000 a day once the workspace has taken in $10 of credit. The message says how to raise the cap.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "Phantom has no upstream key configured, or the upstream could not be reached. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "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`). Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/coins": {
      "get": {
        "operationId": "getV1Coins",
        "summary": "List the coins a crypto payment accepts",
        "description": "The coins Phantom takes right now, each paid to Stripe: USDC on Solana (`POST /v1/purchase/solana`) and USDC on Base (`POST /v1/purchase/base`). A coin is listed only while Stripe can record its payment. SOL and USDT are no longer accepted. For any other coin or network Stripe takes, use `POST /v1/purchase/stripe-crypto`. Needs no key.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The accepted coins. Empty when the site takes no crypto right now.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "coins": {
                      "type": "array",
                      "description": "One entry per accepted coin and network.",
                      "items": {
                        "type": "object",
                        "description": "A coin on one network.",
                        "properties": {
                          "code": {
                            "type": "string",
                            "description": "The coin's code. `usdc` is the `coin` for `POST /v1/purchase/solana`; `usdc-base` is paid through `POST /v1/purchase/base`. Both are `coin` values for `POST /v1/workspaces/{id}/fund`.",
                            "enum": [
                              "usdc",
                              "usdc-base"
                            ]
                          },
                          "name": {
                            "type": "string",
                            "description": "Display name.",
                            "enum": [
                              "USDC"
                            ]
                          },
                          "network": {
                            "type": "string",
                            "description": "The network the coin is sent on.",
                            "enum": [
                              "solana",
                              "base"
                            ]
                          },
                          "pay_currency": {
                            "type": "string",
                            "description": "The code stored on the payment record.",
                            "enum": [
                              "usdcsol",
                              "usdc-base"
                            ]
                          },
                          "mint": {
                            "type": "string",
                            "description": "The token's address on that network: its mint on Solana, its contract on Base."
                          },
                          "min_usd": {
                            "type": "number",
                            "description": "Smallest price accepted, in US dollars."
                          }
                        },
                        "required": [
                          "code",
                          "name",
                          "network",
                          "pay_currency",
                          "mint",
                          "min_usd"
                        ]
                      }
                    }
                  },
                  "required": [
                    "coins"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=300, stale-while-revalidate=3600`: the CDN keeps the answer for 5 minutes.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/embeddings": {
      "post": {
        "operationId": "postV1Embeddings",
        "summary": "Create embedding vectors for text input",
        "description": "Turns text into vectors (lists of numbers) in OpenAI's embeddings format. Phantom estimates the cost from the input (about four characters per token), holds that amount on the key, calls the upstream, and then bills the tokens the upstream reports, or the estimate when it reports none. A failed call bills nothing and returns the hold.\n\nWhen the upstream refuses the request with a 4xx status, that status comes back unchanged in an OpenAI error with code `upstream_unavailable`.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "input": {
                    "type": "array",
                    "description": "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). Sent to the upstream unchanged. An empty string counts as missing.",
                    "examples": [
                      [
                        "The quick brown fox"
                      ]
                    ],
                    "items": {
                      "type": "string",
                      "description": "One string, or one token id."
                    }
                  },
                  "router": {
                    "type": "string",
                    "description": "A router's name in place of `model`. Here it runs the model that router names for this endpoint, as `model: \"phantom-1\"` does. Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "`phantom-1` runs `openai/text-embedding-3-small`. An embedding model id from `GET /v1/models`. Aliases resolve to the catalog id before pricing.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "dimensions": {
                    "type": "integer",
                    "description": "Length of each vector, for models that support it. Sent to the upstream unchanged."
                  }
                },
                "required": [
                  "input"
                ]
              },
              "example": {
                "model": "phantom-1",
                "input": [
                  "The quick brown fox"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upstream's response, passed through unchanged, in OpenAI's embeddings format.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "description": "`list`."
                    },
                    "data": {
                      "type": "array",
                      "description": "One entry per input.",
                      "items": {
                        "type": "object",
                        "description": "An embedding.",
                        "properties": {
                          "object": {
                            "type": "string",
                            "description": "`embedding`."
                          },
                          "index": {
                            "type": "integer",
                            "description": "Position of the input this vector belongs to."
                          },
                          "embedding": {
                            "type": "array",
                            "description": "The vector.",
                            "items": {
                              "type": "number",
                              "description": "One component."
                            }
                          }
                        }
                      }
                    },
                    "model": {
                      "type": "string",
                      "description": "The model that produced the vectors, as the upstream reports it."
                    },
                    "usage": {
                      "type": "object",
                      "description": "Token counts. `prompt_tokens` is what Phantom bills when present.",
                      "properties": {
                        "prompt_tokens": {
                          "type": "integer",
                          "description": "Input tokens."
                        },
                        "total_tokens": {
                          "type": "integer",
                          "description": "All tokens."
                        }
                      }
                    }
                  }
                },
                "example": {
                  "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
                  }
                }
              }
            },
            "headers": {
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. On this route `model_served` is the `model` field of the upstream's response when it has one, and `upstream_request_id` is the upstream's `x-request-id`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The body is not JSON, or `input` is missing or empty. Also a 400 from the upstream, passed through. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "No key (`missing_api_key`), or a key that does not start with `sk-` (`invalid_api_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the estimate (`insufficient_balance`). Also sent when the hold could not be placed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "Insufficient balance or inactive API key",
                    "type": "insufficient_quota",
                    "code": "insufficient_balance"
                  }
                }
              }
            }
          },
          "404": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "The upstream answered with a 5xx status, or the call failed (`upstream_unavailable`). Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Phantom has no upstream key configured (`upstream_unavailable`). Also sent when the upstream refuses Phantom's own account (its credit or budget is used up, or its key is rejected), or when Phantom can't load its model list. Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/images/generations": {
      "post": {
        "operationId": "postV1ImagesGenerations",
        "summary": "Generate images from a text prompt",
        "description": "Generates images in OpenAI's format. The price is the model's flat per-image rate times `n`. Phantom holds that amount on the key, calls the upstream, and bills it once the upstream returns image data. A failed call bills nothing and returns the hold.\n\nWhen the upstream refuses the request with a 4xx status, that status comes back unchanged in an OpenAI error with code `upstream_unavailable`.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt": {
                    "type": "string",
                    "description": "What to draw.",
                    "examples": [
                      "A lighthouse at dusk, oil painting"
                    ]
                  },
                  "router": {
                    "type": "string",
                    "description": "A router's name in place of `model`. Here it runs the model that router names for this endpoint, as `model: \"phantom-1\"` does. Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "`phantom-1` runs `bfl/flux-pro-1.1`. An image model id from `GET /v1/models`. Aliases resolve to the catalog id before pricing.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "n": {
                    "type": "integer",
                    "description": "How many images. Values outside 1 to 4 are moved to the nearest limit. You are billed for `n` images.",
                    "default": 1,
                    "minimum": 1,
                    "maximum": 4
                  },
                  "size": {
                    "type": "string",
                    "description": "Image size, sent to the upstream unchanged.",
                    "default": "1024x1024"
                  },
                  "response_format": {
                    "type": "string",
                    "description": "How images come back, sent to the upstream unchanged. OpenAI's values are `url` and `b64_json`.",
                    "default": "url"
                  }
                },
                "required": [
                  "prompt"
                ]
              },
              "example": {
                "model": "phantom-1",
                "prompt": "A lighthouse at dusk, oil painting"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upstream's response, passed through unchanged. Other fields the upstream sends, such as `created`, come through as well.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "created": {
                      "type": "integer",
                      "description": "Unix time, in seconds, the upstream made the images."
                    },
                    "data": {
                      "type": "array",
                      "description": "The images.",
                      "items": {
                        "type": "object",
                        "description": "One image.",
                        "properties": {
                          "url": {
                            "type": "string",
                            "description": "Where to download the image, with `response_format: \"url\"`."
                          },
                          "b64_json": {
                            "type": "string",
                            "description": "The image as base64, with `response_format: \"b64_json\"`."
                          }
                        },
                        "additionalProperties": true
                      }
                    }
                  },
                  "required": [
                    "data"
                  ]
                },
                "example": {
                  "created": 1,
                  "data": [
                    {
                      "url": "https://upstream.example/img.png"
                    }
                  ]
                }
              }
            },
            "headers": {
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars. Rounded to four decimal places on this route.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. On this route `model_served` is the model Phantom asked for, since the image response names none, `prompt_tokens` is 1, and `upstream_request_id` is null.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The body is not JSON, or `prompt` is missing or not a string. Also a 400 from the upstream, passed through. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "No key (`missing_api_key`), or a key that does not start with `sk-` (`invalid_api_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the price (`insufficient_balance`). Also sent when the hold could not be placed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "Insufficient balance or inactive API key",
                    "type": "insufficient_quota",
                    "code": "insufficient_balance"
                  }
                }
              }
            }
          },
          "404": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "The upstream answered with a 5xx status, returned no `data` array, or the call failed (`upstream_unavailable`). Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Phantom has no upstream key configured (`upstream_unavailable`). Also sent when the upstream refuses Phantom's own account (its credit or budget is used up, or its key is rejected), or when Phantom can't load its model list. Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/key": {
      "delete": {
        "operationId": "deleteV1Key",
        "summary": "Revoke the calling key; its workspace keeps credit",
        "description": "Turns the calling key off for good. Phantom sends the remaining credit nowhere, since moving it would link the key to another one; the response reports what was lost. Refused while credit is held for a request still running on the key.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The key is revoked.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "revoked": {
                      "type": "boolean",
                      "description": "Always `true`.",
                      "enum": [
                        true
                      ]
                    },
                    "forfeited_usd": {
                      "type": "number",
                      "description": "Always 0: the credit belongs to the key's workspace and stays there. Kept for older clients. In US dollars."
                    }
                  },
                  "required": [
                    "revoked",
                    "forfeited_usd"
                  ]
                },
                "example": {
                  "revoked": true,
                  "forfeited_usd": 0
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key in `Authorization`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "404": {
            "description": "No active key matches the credential. A key revoked earlier answers this.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                },
                "example": {
                  "error": "No active key for that credential."
                }
              }
            }
          },
          "409": {
            "description": "Credit is held for a request still running on this key (`key_busy`). Retry when it finishes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent with `key_busy`: `5`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "description": "The database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/key/balance": {
      "get": {
        "operationId": "getV1KeyBalance",
        "summary": "Read the key's balance and expiry",
        "description": "Credit left on the calling key, what it has spent, and when it expires.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The key's balance. A revoked or expired key still gets this answer, with `active: false`, so a client can tell it is dead.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "active": {
                      "type": "boolean",
                      "description": "The key can be used: it is switched on and not past `expires_at`."
                    },
                    "kind": {
                      "type": "string",
                      "description": "Key type. Keys issued today are `credit`; the other values survive only on older keys.",
                      "enum": [
                        "credit",
                        "pass",
                        "faucet"
                      ]
                    },
                    "credit_balance_usd": {
                      "type": "number",
                      "description": "Credit the key can spend now, in US dollars. Includes credit held for a request whose hold has expired."
                    },
                    "credit_spent_usd": {
                      "type": "number",
                      "description": "Total the key has spent, in US dollars."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "When the key stops working.",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "active",
                    "kind",
                    "credit_balance_usd",
                    "credit_spent_usd",
                    "expires_at"
                  ]
                },
                "example": {
                  "active": true,
                  "kind": "credit",
                  "credit_balance_usd": 5,
                  "credit_spent_usd": 0.000003,
                  "expires_at": "2026-12-17T01:38:50.236Z"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key in `Authorization` (`Missing or invalid Authorization header`), or a key Phantom does not know (`invalid_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      }
    },
    "/v1/key/budget": {
      "get": {
        "operationId": "getV1KeyBudget",
        "summary": "Read the key's budget and spend-rate caps",
        "description": "The key's spend cap, its window and how spending is pacing against it, and the per-minute cap.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The caps and pace.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "budget_usd": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "The spend cap for one window, in US dollars. `null` when the key has no cap."
                    },
                    "period_days": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Window length in days. `null` means one calendar month."
                    },
                    "spent_this_period_usd": {
                      "type": "number",
                      "description": "Spent in the current window."
                    },
                    "period_started": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "When the current window started.",
                      "format": "date-time"
                    },
                    "exhausted": {
                      "type": "boolean",
                      "description": "The cap is reached, so paid calls are refused until the window ends."
                    },
                    "period_ends": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "When the current window ends. `null` without a cap.",
                      "format": "date-time"
                    },
                    "days_left": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Whole days left in the window, at least 1. `null` without a cap."
                    },
                    "allowed_so_far_usd": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "What an even spend across the window would have used by now. `null` without a cap."
                    },
                    "daily_allowance_usd": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "What is left of the cap divided by the days left. `null` without a cap."
                    },
                    "pace": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "`ahead` when spend is past the even line plus a margin. `null` without a cap.",
                      "enum": [
                        "on_pace",
                        "ahead",
                        null
                      ]
                    },
                    "rate_usd_per_min": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "The per-minute spend cap, in US dollars. `null` when there is none."
                    },
                    "spent_this_minute_usd": {
                      "type": "number",
                      "description": "Spent in the current one-minute window."
                    },
                    "rate_exceeded": {
                      "type": "boolean",
                      "description": "The per-minute cap is reached for this minute."
                    }
                  },
                  "required": [
                    "budget_usd",
                    "period_days",
                    "spent_this_period_usd",
                    "period_started",
                    "exhausted",
                    "period_ends",
                    "days_left",
                    "allowed_so_far_usd",
                    "daily_allowance_usd",
                    "pace",
                    "rate_usd_per_min",
                    "spent_this_minute_usd",
                    "rate_exceeded"
                  ]
                },
                "example": {
                  "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
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchV1KeyBudget",
        "summary": "Tighten the key's budget and spend-rate caps",
        "description": "With the key alone, a caller can add a cap the key does not have, lower one it has, or make the budget's window longer. Raising or removing a cap, or making the window shorter, answers 403: the workspace does that, under Edit controls on /keys or with `PATCH /v1/workspaces/{id}/keys/{key}`. Send only the fields to change. A budget added to a key with none starts a new window from now with nothing spent; a lowered budget keeps its window start and what was spent in it. Every field is checked before anything is written, and the caps are written together only if they did not change while the request ran.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "description": "At least one of the fields.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "budget_usd": {
                    "type": [
                      "number",
                      "null"
                    ],
                    "description": "Spend cap per window in US dollars, above zero, and no more than the key's current cap. `null` is accepted only on a key with no cap.",
                    "examples": [
                      20
                    ]
                  },
                  "period_days": {
                    "type": [
                      "integer",
                      "null"
                    ],
                    "description": "Window length in whole days, no shorter than the current window while the key has a budget. `null` is one calendar month, which runs from 28 to 31 days, so it counts as shorter than a window of 29 days or more.",
                    "minimum": 1,
                    "maximum": 3650,
                    "examples": [
                      30
                    ]
                  },
                  "rate_usd_per_min": {
                    "type": [
                      "number",
                      "null"
                    ],
                    "description": "Per-minute spend cap in US dollars, above zero, and no more than the key's current cap. `null` is accepted only on a key with no cap.",
                    "examples": [
                      0.5
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The caps after the change.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "budget_usd": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "The spend cap for one window, in US dollars. `null` when the key has no cap."
                    },
                    "period_days": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Window length in days. `null` means one calendar month."
                    },
                    "spent_this_period_usd": {
                      "type": "number",
                      "description": "Spent in the current window."
                    },
                    "period_started": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "When the current window started.",
                      "format": "date-time"
                    },
                    "exhausted": {
                      "type": "boolean",
                      "description": "The cap is reached, so paid calls are refused until the window ends."
                    },
                    "period_ends": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "When the current window ends. `null` without a cap.",
                      "format": "date-time"
                    },
                    "days_left": {
                      "type": [
                        "integer",
                        "null"
                      ],
                      "description": "Whole days left in the window, at least 1. `null` without a cap."
                    },
                    "allowed_so_far_usd": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "What an even spend across the window would have used by now. `null` without a cap."
                    },
                    "daily_allowance_usd": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "What is left of the cap divided by the days left. `null` without a cap."
                    },
                    "pace": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "`ahead` when spend is past the even line plus a margin. `null` without a cap.",
                      "enum": [
                        "on_pace",
                        "ahead",
                        null
                      ]
                    },
                    "rate_usd_per_min": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "The per-minute spend cap, in US dollars. `null` when there is none."
                    },
                    "spent_this_minute_usd": {
                      "type": "number",
                      "description": "Spent in the current one-minute window."
                    },
                    "rate_exceeded": {
                      "type": "boolean",
                      "description": "The per-minute cap is reached for this minute."
                    }
                  },
                  "required": [
                    "budget_usd",
                    "period_days",
                    "spent_this_period_usd",
                    "period_started",
                    "exhausted",
                    "period_ends",
                    "days_left",
                    "allowed_so_far_usd",
                    "daily_allowance_usd",
                    "pace",
                    "rate_usd_per_min",
                    "spent_this_minute_usd",
                    "rate_exceeded"
                  ]
                },
                "example": {
                  "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
                }
              }
            }
          },
          "400": {
            "description": "Bad JSON, none of the three fields, or a value out of range.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          },
          "403": {
            "description": "The change would raise or remove a cap, or shorten the budget's window. Nothing is written; the message names the workspace's controls.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "The key's caps changed while the request ran, such as the workspace lowering one. Nothing is written; read them again and retry.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/key/lineup": {
      "get": {
        "operationId": "getV1KeyLineup",
        "summary": "Read the models each phantom-1 tier may use",
        "description": "The model each phantom-1 tier runs on this key, and the models each tier can run. phantom-1 picks the tier for each request; the lineup picks the model in it.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The lineup, the model each tier runs, and each tier's suggested models with prices.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "lineup": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "The tiers this key changed from the default, and the fallbacks it named. `null` when it runs every default.",
                      "examples": [
                        {
                          "frontier": "anthropic/claude-opus-5.5",
                          "fallbacks": {
                            "standard": "anthropic/claude-haiku-5.5"
                          }
                        }
                      ],
                      "properties": {
                        "standard": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The model every task starts on. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. Suggested: `deepseek/deepseek-v4.1-flash-1017`, `anthropic/claude-haiku-5.5`, `minimax/minimax-m3`, `google/gemini-3-flash`, `moonshotai/kimi-k2.7-code`, `openai/gpt-6.1-terra`. `null` or left out runs the default."
                        },
                        "frontier": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The model hard steps move up to. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. Suggested: `anthropic/claude-sonnet-5.5`, `anthropic/claude-opus-5.5`, `openai/gpt-6.2-sol`, `moonshotai/kimi-k3`, `moonshotai/kimi-k3.1-pro`, `google/gemini-4-argon`, `anthropic/claude-fable-5.2`. `null` or left out runs the default."
                        },
                        "fallbacks": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "The fallback model for each tier you name. A request that fails on the tier's model tries it next. It is billed at its own price, and a fallback the catalog does not list right now is skipped.",
                          "examples": [
                            {
                              "standard": "anthropic/claude-haiku-5.5"
                            }
                          ],
                          "properties": {
                            "standard": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "The model to try when the standard model fails. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. It must differ from the standard model. `null` or left out keeps the usual fallback: none."
                            },
                            "frontier": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "The model to try when the frontier model fails. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. It must differ from the frontier model. `null` or left out keeps the usual fallback: none."
                            }
                          }
                        }
                      }
                    },
                    "tiers": {
                      "type": "object",
                      "description": "The model each tier runs for this key: its pick, else the default. A pick the catalog does not list right now shows as the default, as a request runs it.",
                      "properties": {
                        "standard": {
                          "type": "object",
                          "description": "The model this tier runs.",
                          "properties": {
                            "model": {
                              "type": "string",
                              "description": "Model id."
                            },
                            "name": {
                              "type": "string",
                              "description": "Display name."
                            }
                          },
                          "required": [
                            "model",
                            "name"
                          ]
                        },
                        "frontier": {
                          "type": "object",
                          "description": "The model this tier runs.",
                          "properties": {
                            "model": {
                              "type": "string",
                              "description": "Model id."
                            },
                            "name": {
                              "type": "string",
                              "description": "Display name."
                            }
                          },
                          "required": [
                            "model",
                            "name"
                          ]
                        }
                      },
                      "required": [
                        "standard",
                        "frontier"
                      ]
                    },
                    "choices": {
                      "type": "object",
                      "description": "Each tier's suggested models. A tier can run any model that passes the checks, not only these.",
                      "properties": {
                        "standard": {
                          "type": "array",
                          "description": "The models this tier can run, default first.",
                          "items": {
                            "type": "object",
                            "description": "One model.",
                            "properties": {
                              "model": {
                                "type": "string",
                                "description": "Model id."
                              },
                              "name": {
                                "type": "string",
                                "description": "Display name."
                              },
                              "input_per_m": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "USD per million input tokens. `null` when the catalog does not list the model right now."
                              },
                              "output_per_m": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "USD per million output tokens. `null` when the catalog does not list the model right now."
                              },
                              "context": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Context window in tokens."
                              },
                              "default": {
                                "type": "boolean",
                                "description": "`true` for the tier's default, such as `anthropic/claude-sonnet-5.5` for frontier."
                              }
                            },
                            "required": [
                              "model",
                              "name",
                              "input_per_m",
                              "output_per_m",
                              "context",
                              "default"
                            ]
                          }
                        },
                        "frontier": {
                          "type": "array",
                          "description": "The models this tier can run, default first.",
                          "items": {
                            "type": "object",
                            "description": "One model.",
                            "properties": {
                              "model": {
                                "type": "string",
                                "description": "Model id."
                              },
                              "name": {
                                "type": "string",
                                "description": "Display name."
                              },
                              "input_per_m": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "USD per million input tokens. `null` when the catalog does not list the model right now."
                              },
                              "output_per_m": {
                                "type": [
                                  "number",
                                  "null"
                                ],
                                "description": "USD per million output tokens. `null` when the catalog does not list the model right now."
                              },
                              "context": {
                                "type": [
                                  "integer",
                                  "null"
                                ],
                                "description": "Context window in tokens."
                              },
                              "default": {
                                "type": "boolean",
                                "description": "`true` for the tier's default, such as `anthropic/claude-sonnet-5.5` for frontier."
                              }
                            },
                            "required": [
                              "model",
                              "name",
                              "input_per_m",
                              "output_per_m",
                              "context",
                              "default"
                            ]
                          }
                        }
                      },
                      "required": [
                        "standard",
                        "frontier"
                      ]
                    }
                  },
                  "required": [
                    "lineup",
                    "tiers",
                    "choices"
                  ]
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "putV1KeyLineup",
        "summary": "Set the models each phantom-1 tier may use",
        "description": "Replaces the lineup. Each field is a tier and each value a model: any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens, in either tier. A tier left out, `null`, or set to its default runs the default. `fallbacks` names a fallback model for each tier, checked the same way. A stored model the catalog stops listing runs the default.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "description": "The model for each tier you change, and the fallback for each tier you name.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "standard": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "The model every task starts on. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. Suggested: `deepseek/deepseek-v4.1-flash-1017`, `anthropic/claude-haiku-5.5`, `minimax/minimax-m3`, `google/gemini-3-flash`, `moonshotai/kimi-k2.7-code`, `openai/gpt-6.1-terra`. `null` or left out runs the default."
                  },
                  "frontier": {
                    "type": [
                      "string",
                      "null"
                    ],
                    "description": "The model hard steps move up to. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. Suggested: `anthropic/claude-sonnet-5.5`, `anthropic/claude-opus-5.5`, `openai/gpt-6.2-sol`, `moonshotai/kimi-k3`, `moonshotai/kimi-k3.1-pro`, `google/gemini-4-argon`, `anthropic/claude-fable-5.2`. `null` or left out runs the default."
                  },
                  "fallbacks": {
                    "type": [
                      "object",
                      "null"
                    ],
                    "description": "The fallback model for each tier you name. A request that fails on the tier's model tries it next. It is billed at its own price, and a fallback the catalog does not list right now is skipped.",
                    "examples": [
                      {
                        "standard": "anthropic/claude-haiku-5.5"
                      }
                    ],
                    "properties": {
                      "standard": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "description": "The model to try when the standard model fails. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. It must differ from the standard model. `null` or left out keeps the usual fallback: none."
                      },
                      "frontier": {
                        "type": [
                          "string",
                          "null"
                        ],
                        "description": "The model to try when the frontier model fails. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. It must differ from the frontier model. `null` or left out keeps the usual fallback: none."
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The lineup as stored, and the model each tier runs.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "lineup": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "The tiers this key changed from the default, and the fallbacks it named. `null` when it runs every default.",
                      "examples": [
                        {
                          "frontier": "anthropic/claude-opus-5.5",
                          "fallbacks": {
                            "standard": "anthropic/claude-haiku-5.5"
                          }
                        }
                      ],
                      "properties": {
                        "standard": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The model every task starts on. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. Suggested: `deepseek/deepseek-v4.1-flash-1017`, `anthropic/claude-haiku-5.5`, `minimax/minimax-m3`, `google/gemini-3-flash`, `moonshotai/kimi-k2.7-code`, `openai/gpt-6.1-terra`. `null` or left out runs the default."
                        },
                        "frontier": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The model hard steps move up to. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. Suggested: `anthropic/claude-sonnet-5.5`, `anthropic/claude-opus-5.5`, `openai/gpt-6.2-sol`, `moonshotai/kimi-k3`, `moonshotai/kimi-k3.1-pro`, `google/gemini-4-argon`, `anthropic/claude-fable-5.2`. `null` or left out runs the default."
                        },
                        "fallbacks": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "The fallback model for each tier you name. A request that fails on the tier's model tries it next. It is billed at its own price, and a fallback the catalog does not list right now is skipped.",
                          "examples": [
                            {
                              "standard": "anthropic/claude-haiku-5.5"
                            }
                          ],
                          "properties": {
                            "standard": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "The model to try when the standard model fails. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. It must differ from the standard model. `null` or left out keeps the usual fallback: none."
                            },
                            "frontier": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "The model to try when the frontier model fails. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. It must differ from the frontier model. `null` or left out keeps the usual fallback: none."
                            }
                          }
                        }
                      }
                    },
                    "tiers": {
                      "type": "object",
                      "description": "The model each tier runs for this key: its pick, else the default. A pick the catalog does not list right now shows as the default, as a request runs it.",
                      "properties": {
                        "standard": {
                          "type": "object",
                          "description": "The model this tier runs.",
                          "properties": {
                            "model": {
                              "type": "string",
                              "description": "Model id."
                            },
                            "name": {
                              "type": "string",
                              "description": "Display name."
                            }
                          },
                          "required": [
                            "model",
                            "name"
                          ]
                        },
                        "frontier": {
                          "type": "object",
                          "description": "The model this tier runs.",
                          "properties": {
                            "model": {
                              "type": "string",
                              "description": "Model id."
                            },
                            "name": {
                              "type": "string",
                              "description": "Display name."
                            }
                          },
                          "required": [
                            "model",
                            "name"
                          ]
                        }
                      },
                      "required": [
                        "standard",
                        "frontier"
                      ]
                    }
                  },
                  "required": [
                    "lineup",
                    "tiers"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "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.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                },
                "example": {
                  "error": "Invalid lineup: frontier: x/not-a-pick isn't a model Phantom lists. GET /v1/models lists them."
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteV1KeyLineup",
        "summary": "Reset the phantom-1 lineup to the defaults",
        "description": "Clears the lineup, so every tier runs its default.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The lineup is cleared.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "lineup": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "Always `null`.",
                      "examples": [
                        {
                          "frontier": "anthropic/claude-opus-5.5",
                          "fallbacks": {
                            "standard": "anthropic/claude-haiku-5.5"
                          }
                        }
                      ],
                      "properties": {
                        "standard": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The model every task starts on. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. Suggested: `deepseek/deepseek-v4.1-flash-1017`, `anthropic/claude-haiku-5.5`, `minimax/minimax-m3`, `google/gemini-3-flash`, `moonshotai/kimi-k2.7-code`, `openai/gpt-6.1-terra`. `null` or left out runs the default."
                        },
                        "frontier": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The model hard steps move up to. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. Suggested: `anthropic/claude-sonnet-5.5`, `anthropic/claude-opus-5.5`, `openai/gpt-6.2-sol`, `moonshotai/kimi-k3`, `moonshotai/kimi-k3.1-pro`, `google/gemini-4-argon`, `anthropic/claude-fable-5.2`. `null` or left out runs the default."
                        },
                        "fallbacks": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "The fallback model for each tier you name. A request that fails on the tier's model tries it next. It is billed at its own price, and a fallback the catalog does not list right now is skipped.",
                          "examples": [
                            {
                              "standard": "anthropic/claude-haiku-5.5"
                            }
                          ],
                          "properties": {
                            "standard": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "The model to try when the standard model fails. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. It must differ from the standard model. `null` or left out keeps the usual fallback: none."
                            },
                            "frontier": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "The model to try when the frontier model fails. Any chat model from `GET /v1/models` that calls tools, reads images and has a context window of at least 128,000 tokens. It must differ from the frontier model. `null` or left out keeps the usual fallback: none."
                            }
                          }
                        }
                      }
                    },
                    "tiers": {
                      "type": "object",
                      "description": "The model each tier runs for this key: its pick, else the default. A pick the catalog does not list right now shows as the default, as a request runs it.",
                      "properties": {
                        "standard": {
                          "type": "object",
                          "description": "The model this tier runs.",
                          "properties": {
                            "model": {
                              "type": "string",
                              "description": "Model id."
                            },
                            "name": {
                              "type": "string",
                              "description": "Display name."
                            }
                          },
                          "required": [
                            "model",
                            "name"
                          ]
                        },
                        "frontier": {
                          "type": "object",
                          "description": "The model this tier runs.",
                          "properties": {
                            "model": {
                              "type": "string",
                              "description": "Model id."
                            },
                            "name": {
                              "type": "string",
                              "description": "Display name."
                            }
                          },
                          "required": [
                            "model",
                            "name"
                          ]
                        }
                      },
                      "required": [
                        "standard",
                        "frontier"
                      ]
                    }
                  },
                  "required": [
                    "lineup",
                    "tiers"
                  ]
                },
                "example": {
                  "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"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "The lineup could not be cleared (the key is inactive, or the write failed).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      }
    },
    "/v1/key/rotate": {
      "post": {
        "operationId": "postV1KeyRotate",
        "summary": "Rotate the key: new secret, same settings",
        "description": "Issues a new key and turns the old one off in one step. The new key takes everything from the old one: balance, spend so far, expiry, spend cap and its window, per-minute cap and its window, limit, route policy and lineup. Refused while credit is held for a request still running on the key. The new key is shown once.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The new key. The old one no longer works.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_key": {
                      "type": "string",
                      "description": "The new key. Shown once.",
                      "examples": [
                        "sk-phantom-..."
                      ]
                    },
                    "rotated_at": {
                      "type": "string",
                      "description": "When the rotation happened.",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "api_key",
                    "rotated_at"
                  ]
                },
                "example": {
                  "api_key": "sk-phantom-...",
                  "rotated_at": "2026-11-17T01:38:50.639Z"
                }
              }
            }
          },
          "400": {
            "description": "The key is unknown or inactive, or the database write failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                },
                "example": {
                  "error": "Failed to rotate key or key inactive"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key in `Authorization`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Credit is held for a request still running on this key (`key_busy`). Retry when it finishes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent with `key_busy`: `5`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/key/route": {
      "get": {
        "operationId": "getV1KeyRoute",
        "summary": "Read the key's route policy for model auto",
        "description": "The rules that decide which model `model: \"auto\"` runs on this key.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The policy, or `null` when the key has none or the stored one no longer passes the checks.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "route_policy": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "The policy. `null` when the key has none.",
                      "properties": {
                        "models": {
                          "type": "array",
                          "description": "The models this key may route to, up to 10 ids of up to 200 characters. `models[0]` is the default pick for `auto`. May not hold `auto`, `cheapest`, `first` or `next`. An empty list keeps preferences only (`sort`, `zdr`, `no_training`, `sensitivity`): nothing is routed, `auto` runs phantom-1 as on a key with no policy, and `rules` or `on_empty: \"cheapest\"` are refused.",
                          "examples": [
                            [
                              "phantom-1",
                              "anthropic/claude-sonnet-5.5"
                            ]
                          ],
                          "items": {
                            "type": "string",
                            "description": "A model id from `GET /v1/models`."
                          }
                        },
                        "applies_to": {
                          "type": "string",
                          "description": "`auto`: only `model: \"auto\"` requests are routed. `all`: requests that name a model are routed too.",
                          "enum": [
                            "auto",
                            "all"
                          ],
                          "default": "auto"
                        },
                        "rules": {
                          "type": "array",
                          "description": "Up to 20 rules, tried in order. The first whose condition holds picks the model. Defaults to none.",
                          "items": {
                            "type": "object",
                            "description": "One rule. No other fields are accepted.",
                            "properties": {
                              "if": {
                                "type": "object",
                                "description": "Exactly one condition, with its value.",
                                "properties": {
                                  "pace": {
                                    "type": "string",
                                    "description": "Holds when the key's budget pace matches. Never holds without a budget.",
                                    "enum": [
                                      "on_pace",
                                      "ahead"
                                    ]
                                  },
                                  "budget_left_pct_below": {
                                    "type": "number",
                                    "description": "Holds when less than this percent of the budget is left in the window.",
                                    "minimum": 0,
                                    "maximum": 100
                                  },
                                  "days_left_below": {
                                    "type": "number",
                                    "description": "Holds when fewer than this many days are left in the budget window. Above zero."
                                  },
                                  "has_tools": {
                                    "type": "boolean",
                                    "description": "Holds when whether the request sends tools matches this value."
                                  },
                                  "input_tokens_over": {
                                    "type": "integer",
                                    "description": "Holds when the prompt is estimated at more than this many tokens.",
                                    "minimum": 0
                                  },
                                  "reasoning_requested": {
                                    "type": "boolean",
                                    "description": "Holds when whether the request asks for reasoning (`reasoning_effort` or `reasoning`) matches this value."
                                  }
                                }
                              },
                              "use": {
                                "type": "string",
                                "description": "One of `models`, or an action: `cheapest` (lowest input plus output price among `models`), `first` (`models[0]`), `next` (the model after the requested one in `models`, wrapping; `models[1]` for `auto`)."
                              }
                            },
                            "required": [
                              "if",
                              "use"
                            ]
                          }
                        },
                        "on_empty": {
                          "type": "string",
                          "description": "Once the budget is used up. `stop`: requests are refused. `cheapest`: routable requests keep running on the cheapest of `models` while the key has credit.",
                          "enum": [
                            "stop",
                            "cheapest"
                          ],
                          "default": "stop"
                        },
                        "fallback_on_error": {
                          "type": "boolean",
                          "description": "When `true`, the policy's other chat models go to the upstream as fallbacks if the picked model fails.",
                          "default": false
                        },
                        "stick_minutes": {
                          "type": "integer",
                          "description": "Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm. `0` turns it off.",
                          "default": 5,
                          "minimum": 0,
                          "maximum": 1440
                        },
                        "stick_by_prompt": {
                          "type": "boolean",
                          "description": "Without `x-phantom-session`, recognise a conversation by a hash of its opening messages, held in memory only. `false`: only the header counts.",
                          "default": true
                        },
                        "sort": {
                          "type": "string",
                          "description": "Default provider ranking for this key's chat and messages requests: `cost`, `ttft` (fastest first token) or `tps` (most tokens per second). A request's own `sort` wins.",
                          "enum": [
                            "cost",
                            "ttft",
                            "tps"
                          ]
                        },
                        "zdr": {
                          "type": "boolean",
                          "description": "Send this key's requests only to providers that delete prompts right away. phantom-1 then skips its free model. A request's own `zdr` wins."
                        },
                        "no_training": {
                          "type": "boolean",
                          "description": "Send this key's requests only to providers that don't train on prompts."
                        },
                        "sensitivity": {
                          "type": "string",
                          "description": "How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there. `balanced` waits for a second sign of trouble in a coding agent's recent steps. `conservative` moves up on one hard error and stays up longer. `strict` moves up on almost any error and stays up longest. It costs more and gives up less quality, which is the trade.",
                          "enum": [
                            "balanced",
                            "conservative",
                            "strict"
                          ],
                          "default": "balanced"
                        }
                      },
                      "required": [
                        "models"
                      ]
                    }
                  },
                  "required": [
                    "route_policy"
                  ]
                },
                "example": {
                  "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
                  }
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      },
      "put": {
        "operationId": "putV1KeyRoute",
        "summary": "Replace the route policy",
        "description": "Replaces the whole policy. Unknown fields are refused, and the whole policy is checked before anything is stored.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "description": "A full route policy.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "models": {
                    "type": "array",
                    "description": "The models this key may route to, up to 10 ids of up to 200 characters. `models[0]` is the default pick for `auto`. May not hold `auto`, `cheapest`, `first` or `next`. An empty list keeps preferences only (`sort`, `zdr`, `no_training`, `sensitivity`): nothing is routed, `auto` runs phantom-1 as on a key with no policy, and `rules` or `on_empty: \"cheapest\"` are refused.",
                    "examples": [
                      [
                        "phantom-1",
                        "anthropic/claude-sonnet-5.5"
                      ]
                    ],
                    "items": {
                      "type": "string",
                      "description": "A model id from `GET /v1/models`."
                    }
                  },
                  "applies_to": {
                    "type": "string",
                    "description": "`auto`: only `model: \"auto\"` requests are routed. `all`: requests that name a model are routed too.",
                    "enum": [
                      "auto",
                      "all"
                    ],
                    "default": "auto"
                  },
                  "rules": {
                    "type": "array",
                    "description": "Up to 20 rules, tried in order. The first whose condition holds picks the model. Defaults to none.",
                    "items": {
                      "type": "object",
                      "description": "One rule. No other fields are accepted.",
                      "properties": {
                        "if": {
                          "type": "object",
                          "description": "Exactly one condition, with its value.",
                          "properties": {
                            "pace": {
                              "type": "string",
                              "description": "Holds when the key's budget pace matches. Never holds without a budget.",
                              "enum": [
                                "on_pace",
                                "ahead"
                              ]
                            },
                            "budget_left_pct_below": {
                              "type": "number",
                              "description": "Holds when less than this percent of the budget is left in the window.",
                              "minimum": 0,
                              "maximum": 100
                            },
                            "days_left_below": {
                              "type": "number",
                              "description": "Holds when fewer than this many days are left in the budget window. Above zero."
                            },
                            "has_tools": {
                              "type": "boolean",
                              "description": "Holds when whether the request sends tools matches this value."
                            },
                            "input_tokens_over": {
                              "type": "integer",
                              "description": "Holds when the prompt is estimated at more than this many tokens.",
                              "minimum": 0
                            },
                            "reasoning_requested": {
                              "type": "boolean",
                              "description": "Holds when whether the request asks for reasoning (`reasoning_effort` or `reasoning`) matches this value."
                            }
                          }
                        },
                        "use": {
                          "type": "string",
                          "description": "One of `models`, or an action: `cheapest` (lowest input plus output price among `models`), `first` (`models[0]`), `next` (the model after the requested one in `models`, wrapping; `models[1]` for `auto`)."
                        }
                      },
                      "required": [
                        "if",
                        "use"
                      ]
                    }
                  },
                  "on_empty": {
                    "type": "string",
                    "description": "Once the budget is used up. `stop`: requests are refused. `cheapest`: routable requests keep running on the cheapest of `models` while the key has credit.",
                    "enum": [
                      "stop",
                      "cheapest"
                    ],
                    "default": "stop"
                  },
                  "fallback_on_error": {
                    "type": "boolean",
                    "description": "When `true`, the policy's other chat models go to the upstream as fallbacks if the picked model fails.",
                    "default": false
                  },
                  "stick_minutes": {
                    "type": "integer",
                    "description": "Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm. `0` turns it off.",
                    "default": 5,
                    "minimum": 0,
                    "maximum": 1440
                  },
                  "stick_by_prompt": {
                    "type": "boolean",
                    "description": "Without `x-phantom-session`, recognise a conversation by a hash of its opening messages, held in memory only. `false`: only the header counts.",
                    "default": true
                  },
                  "sort": {
                    "type": "string",
                    "description": "Default provider ranking for this key's chat and messages requests: `cost`, `ttft` (fastest first token) or `tps` (most tokens per second). A request's own `sort` wins.",
                    "enum": [
                      "cost",
                      "ttft",
                      "tps"
                    ]
                  },
                  "zdr": {
                    "type": "boolean",
                    "description": "Send this key's requests only to providers that delete prompts right away. phantom-1 then skips its free model. A request's own `zdr` wins."
                  },
                  "no_training": {
                    "type": "boolean",
                    "description": "Send this key's requests only to providers that don't train on prompts."
                  },
                  "sensitivity": {
                    "type": "string",
                    "description": "How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there. `balanced` waits for a second sign of trouble in a coding agent's recent steps. `conservative` moves up on one hard error and stays up longer. `strict` moves up on almost any error and stays up longest. It costs more and gives up less quality, which is the trade.",
                    "enum": [
                      "balanced",
                      "conservative",
                      "strict"
                    ],
                    "default": "balanced"
                  }
                },
                "required": [
                  "models"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The policy as stored, with defaults filled in.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "route_policy": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "The policy. `null` when the key has none.",
                      "properties": {
                        "models": {
                          "type": "array",
                          "description": "The models this key may route to, up to 10 ids of up to 200 characters. `models[0]` is the default pick for `auto`. May not hold `auto`, `cheapest`, `first` or `next`. An empty list keeps preferences only (`sort`, `zdr`, `no_training`, `sensitivity`): nothing is routed, `auto` runs phantom-1 as on a key with no policy, and `rules` or `on_empty: \"cheapest\"` are refused.",
                          "examples": [
                            [
                              "phantom-1",
                              "anthropic/claude-sonnet-5.5"
                            ]
                          ],
                          "items": {
                            "type": "string",
                            "description": "A model id from `GET /v1/models`."
                          }
                        },
                        "applies_to": {
                          "type": "string",
                          "description": "`auto`: only `model: \"auto\"` requests are routed. `all`: requests that name a model are routed too.",
                          "enum": [
                            "auto",
                            "all"
                          ],
                          "default": "auto"
                        },
                        "rules": {
                          "type": "array",
                          "description": "Up to 20 rules, tried in order. The first whose condition holds picks the model. Defaults to none.",
                          "items": {
                            "type": "object",
                            "description": "One rule. No other fields are accepted.",
                            "properties": {
                              "if": {
                                "type": "object",
                                "description": "Exactly one condition, with its value.",
                                "properties": {
                                  "pace": {
                                    "type": "string",
                                    "description": "Holds when the key's budget pace matches. Never holds without a budget.",
                                    "enum": [
                                      "on_pace",
                                      "ahead"
                                    ]
                                  },
                                  "budget_left_pct_below": {
                                    "type": "number",
                                    "description": "Holds when less than this percent of the budget is left in the window.",
                                    "minimum": 0,
                                    "maximum": 100
                                  },
                                  "days_left_below": {
                                    "type": "number",
                                    "description": "Holds when fewer than this many days are left in the budget window. Above zero."
                                  },
                                  "has_tools": {
                                    "type": "boolean",
                                    "description": "Holds when whether the request sends tools matches this value."
                                  },
                                  "input_tokens_over": {
                                    "type": "integer",
                                    "description": "Holds when the prompt is estimated at more than this many tokens.",
                                    "minimum": 0
                                  },
                                  "reasoning_requested": {
                                    "type": "boolean",
                                    "description": "Holds when whether the request asks for reasoning (`reasoning_effort` or `reasoning`) matches this value."
                                  }
                                }
                              },
                              "use": {
                                "type": "string",
                                "description": "One of `models`, or an action: `cheapest` (lowest input plus output price among `models`), `first` (`models[0]`), `next` (the model after the requested one in `models`, wrapping; `models[1]` for `auto`)."
                              }
                            },
                            "required": [
                              "if",
                              "use"
                            ]
                          }
                        },
                        "on_empty": {
                          "type": "string",
                          "description": "Once the budget is used up. `stop`: requests are refused. `cheapest`: routable requests keep running on the cheapest of `models` while the key has credit.",
                          "enum": [
                            "stop",
                            "cheapest"
                          ],
                          "default": "stop"
                        },
                        "fallback_on_error": {
                          "type": "boolean",
                          "description": "When `true`, the policy's other chat models go to the upstream as fallbacks if the picked model fails.",
                          "default": false
                        },
                        "stick_minutes": {
                          "type": "integer",
                          "description": "Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm. `0` turns it off.",
                          "default": 5,
                          "minimum": 0,
                          "maximum": 1440
                        },
                        "stick_by_prompt": {
                          "type": "boolean",
                          "description": "Without `x-phantom-session`, recognise a conversation by a hash of its opening messages, held in memory only. `false`: only the header counts.",
                          "default": true
                        },
                        "sort": {
                          "type": "string",
                          "description": "Default provider ranking for this key's chat and messages requests: `cost`, `ttft` (fastest first token) or `tps` (most tokens per second). A request's own `sort` wins.",
                          "enum": [
                            "cost",
                            "ttft",
                            "tps"
                          ]
                        },
                        "zdr": {
                          "type": "boolean",
                          "description": "Send this key's requests only to providers that delete prompts right away. phantom-1 then skips its free model. A request's own `zdr` wins."
                        },
                        "no_training": {
                          "type": "boolean",
                          "description": "Send this key's requests only to providers that don't train on prompts."
                        },
                        "sensitivity": {
                          "type": "string",
                          "description": "How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there. `balanced` waits for a second sign of trouble in a coding agent's recent steps. `conservative` moves up on one hard error and stays up longer. `strict` moves up on almost any error and stays up longest. It costs more and gives up less quality, which is the trade.",
                          "enum": [
                            "balanced",
                            "conservative",
                            "strict"
                          ],
                          "default": "balanced"
                        }
                      },
                      "required": [
                        "models"
                      ]
                    }
                  },
                  "required": [
                    "route_policy"
                  ]
                },
                "example": {
                  "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
                  }
                }
              }
            }
          },
          "400": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchV1KeyRoute",
        "summary": "Update part of the route policy",
        "description": "Merges the top-level fields you send into the stored policy, then checks and stores the result. `rules` or `models` sent here replace the whole list.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "description": "Any of the policy fields. With no stored policy, the result must still include `models`.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "models": {
                    "type": "array",
                    "description": "The models this key may route to, up to 10 ids of up to 200 characters. `models[0]` is the default pick for `auto`. May not hold `auto`, `cheapest`, `first` or `next`. An empty list keeps preferences only (`sort`, `zdr`, `no_training`, `sensitivity`): nothing is routed, `auto` runs phantom-1 as on a key with no policy, and `rules` or `on_empty: \"cheapest\"` are refused.",
                    "examples": [
                      [
                        "phantom-1",
                        "anthropic/claude-sonnet-5.5"
                      ]
                    ],
                    "items": {
                      "type": "string",
                      "description": "A model id from `GET /v1/models`."
                    }
                  },
                  "applies_to": {
                    "type": "string",
                    "description": "`auto`: only `model: \"auto\"` requests are routed. `all`: requests that name a model are routed too.",
                    "enum": [
                      "auto",
                      "all"
                    ],
                    "default": "auto"
                  },
                  "rules": {
                    "type": "array",
                    "description": "Up to 20 rules, tried in order. The first whose condition holds picks the model. Defaults to none.",
                    "items": {
                      "type": "object",
                      "description": "One rule. No other fields are accepted.",
                      "properties": {
                        "if": {
                          "type": "object",
                          "description": "Exactly one condition, with its value.",
                          "properties": {
                            "pace": {
                              "type": "string",
                              "description": "Holds when the key's budget pace matches. Never holds without a budget.",
                              "enum": [
                                "on_pace",
                                "ahead"
                              ]
                            },
                            "budget_left_pct_below": {
                              "type": "number",
                              "description": "Holds when less than this percent of the budget is left in the window.",
                              "minimum": 0,
                              "maximum": 100
                            },
                            "days_left_below": {
                              "type": "number",
                              "description": "Holds when fewer than this many days are left in the budget window. Above zero."
                            },
                            "has_tools": {
                              "type": "boolean",
                              "description": "Holds when whether the request sends tools matches this value."
                            },
                            "input_tokens_over": {
                              "type": "integer",
                              "description": "Holds when the prompt is estimated at more than this many tokens.",
                              "minimum": 0
                            },
                            "reasoning_requested": {
                              "type": "boolean",
                              "description": "Holds when whether the request asks for reasoning (`reasoning_effort` or `reasoning`) matches this value."
                            }
                          }
                        },
                        "use": {
                          "type": "string",
                          "description": "One of `models`, or an action: `cheapest` (lowest input plus output price among `models`), `first` (`models[0]`), `next` (the model after the requested one in `models`, wrapping; `models[1]` for `auto`)."
                        }
                      },
                      "required": [
                        "if",
                        "use"
                      ]
                    }
                  },
                  "on_empty": {
                    "type": "string",
                    "description": "Once the budget is used up. `stop`: requests are refused. `cheapest`: routable requests keep running on the cheapest of `models` while the key has credit.",
                    "enum": [
                      "stop",
                      "cheapest"
                    ],
                    "default": "stop"
                  },
                  "fallback_on_error": {
                    "type": "boolean",
                    "description": "When `true`, the policy's other chat models go to the upstream as fallbacks if the picked model fails.",
                    "default": false
                  },
                  "stick_minutes": {
                    "type": "integer",
                    "description": "Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm. `0` turns it off.",
                    "default": 5,
                    "minimum": 0,
                    "maximum": 1440
                  },
                  "stick_by_prompt": {
                    "type": "boolean",
                    "description": "Without `x-phantom-session`, recognise a conversation by a hash of its opening messages, held in memory only. `false`: only the header counts.",
                    "default": true
                  },
                  "sort": {
                    "type": "string",
                    "description": "Default provider ranking for this key's chat and messages requests: `cost`, `ttft` (fastest first token) or `tps` (most tokens per second). A request's own `sort` wins.",
                    "enum": [
                      "cost",
                      "ttft",
                      "tps"
                    ]
                  },
                  "zdr": {
                    "type": "boolean",
                    "description": "Send this key's requests only to providers that delete prompts right away. phantom-1 then skips its free model. A request's own `zdr` wins."
                  },
                  "no_training": {
                    "type": "boolean",
                    "description": "Send this key's requests only to providers that don't train on prompts."
                  },
                  "sensitivity": {
                    "type": "string",
                    "description": "How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there. `balanced` waits for a second sign of trouble in a coding agent's recent steps. `conservative` moves up on one hard error and stays up longer. `strict` moves up on almost any error and stays up longest. It costs more and gives up less quality, which is the trade.",
                    "enum": [
                      "balanced",
                      "conservative",
                      "strict"
                    ],
                    "default": "balanced"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The policy as stored, with defaults filled in.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "route_policy": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "The policy. `null` when the key has none.",
                      "properties": {
                        "models": {
                          "type": "array",
                          "description": "The models this key may route to, up to 10 ids of up to 200 characters. `models[0]` is the default pick for `auto`. May not hold `auto`, `cheapest`, `first` or `next`. An empty list keeps preferences only (`sort`, `zdr`, `no_training`, `sensitivity`): nothing is routed, `auto` runs phantom-1 as on a key with no policy, and `rules` or `on_empty: \"cheapest\"` are refused.",
                          "examples": [
                            [
                              "phantom-1",
                              "anthropic/claude-sonnet-5.5"
                            ]
                          ],
                          "items": {
                            "type": "string",
                            "description": "A model id from `GET /v1/models`."
                          }
                        },
                        "applies_to": {
                          "type": "string",
                          "description": "`auto`: only `model: \"auto\"` requests are routed. `all`: requests that name a model are routed too.",
                          "enum": [
                            "auto",
                            "all"
                          ],
                          "default": "auto"
                        },
                        "rules": {
                          "type": "array",
                          "description": "Up to 20 rules, tried in order. The first whose condition holds picks the model. Defaults to none.",
                          "items": {
                            "type": "object",
                            "description": "One rule. No other fields are accepted.",
                            "properties": {
                              "if": {
                                "type": "object",
                                "description": "Exactly one condition, with its value.",
                                "properties": {
                                  "pace": {
                                    "type": "string",
                                    "description": "Holds when the key's budget pace matches. Never holds without a budget.",
                                    "enum": [
                                      "on_pace",
                                      "ahead"
                                    ]
                                  },
                                  "budget_left_pct_below": {
                                    "type": "number",
                                    "description": "Holds when less than this percent of the budget is left in the window.",
                                    "minimum": 0,
                                    "maximum": 100
                                  },
                                  "days_left_below": {
                                    "type": "number",
                                    "description": "Holds when fewer than this many days are left in the budget window. Above zero."
                                  },
                                  "has_tools": {
                                    "type": "boolean",
                                    "description": "Holds when whether the request sends tools matches this value."
                                  },
                                  "input_tokens_over": {
                                    "type": "integer",
                                    "description": "Holds when the prompt is estimated at more than this many tokens.",
                                    "minimum": 0
                                  },
                                  "reasoning_requested": {
                                    "type": "boolean",
                                    "description": "Holds when whether the request asks for reasoning (`reasoning_effort` or `reasoning`) matches this value."
                                  }
                                }
                              },
                              "use": {
                                "type": "string",
                                "description": "One of `models`, or an action: `cheapest` (lowest input plus output price among `models`), `first` (`models[0]`), `next` (the model after the requested one in `models`, wrapping; `models[1]` for `auto`)."
                              }
                            },
                            "required": [
                              "if",
                              "use"
                            ]
                          }
                        },
                        "on_empty": {
                          "type": "string",
                          "description": "Once the budget is used up. `stop`: requests are refused. `cheapest`: routable requests keep running on the cheapest of `models` while the key has credit.",
                          "enum": [
                            "stop",
                            "cheapest"
                          ],
                          "default": "stop"
                        },
                        "fallback_on_error": {
                          "type": "boolean",
                          "description": "When `true`, the policy's other chat models go to the upstream as fallbacks if the picked model fails.",
                          "default": false
                        },
                        "stick_minutes": {
                          "type": "integer",
                          "description": "Keep a conversation on the model it started on for this many minutes after its last request, so its prompt cache stays warm. `0` turns it off.",
                          "default": 5,
                          "minimum": 0,
                          "maximum": 1440
                        },
                        "stick_by_prompt": {
                          "type": "boolean",
                          "description": "Without `x-phantom-session`, recognise a conversation by a hash of its opening messages, held in memory only. `false`: only the header counts.",
                          "default": true
                        },
                        "sort": {
                          "type": "string",
                          "description": "Default provider ranking for this key's chat and messages requests: `cost`, `ttft` (fastest first token) or `tps` (most tokens per second). A request's own `sort` wins.",
                          "enum": [
                            "cost",
                            "ttft",
                            "tps"
                          ]
                        },
                        "zdr": {
                          "type": "boolean",
                          "description": "Send this key's requests only to providers that delete prompts right away. phantom-1 then skips its free model. A request's own `zdr` wins."
                        },
                        "no_training": {
                          "type": "boolean",
                          "description": "Send this key's requests only to providers that don't train on prompts."
                        },
                        "sensitivity": {
                          "type": "string",
                          "description": "How soon phantom-1 moves a conversation up to its strongest model, and how long it stays there. `balanced` waits for a second sign of trouble in a coding agent's recent steps. `conservative` moves up on one hard error and stays up longer. `strict` moves up on almost any error and stays up longest. It costs more and gives up less quality, which is the trade.",
                          "enum": [
                            "balanced",
                            "conservative",
                            "strict"
                          ],
                          "default": "balanced"
                        }
                      },
                      "required": [
                        "models"
                      ]
                    }
                  },
                  "required": [
                    "route_policy"
                  ]
                },
                "example": {
                  "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
                  }
                }
              }
            }
          },
          "400": {
            "description": "The body is not a JSON object, the merged policy fails the checks, or it could not be saved.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteV1KeyRoute",
        "summary": "Clear the key's route policy for model auto",
        "description": "Removes the policy. `model: \"auto\"` is then refused on this key.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "responses": {
          "200": {
            "description": "The policy is cleared.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "route_policy": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "Always `null`."
                    }
                  },
                  "required": [
                    "route_policy"
                  ]
                },
                "example": {
                  "route_policy": null
                }
              }
            }
          },
          "400": {
            "description": "The policy could not be cleared (the key is inactive, or the write failed).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      }
    },
    "/v1/key/route/test": {
      "post": {
        "operationId": "postV1KeyRouteTest",
        "summary": "Test which model a request would be routed to",
        "description": "Which model a chat request with this body would run on now, and the rule that picked it. Runs the same routing code as `POST /v1/chat/completions` against the key's current budget window and routing memory. Charges nothing and adds nothing to the routing memory. Model selection runs locally without a model call. `phantom-1:free` picks from the free models without calling one, and a spent budget does not stop it.\n\nIt reports what the chat route would do for this key. On a key with no credit, `phantom-1` and `auto` (when the key has no route policy) report a free model, because the chat route runs them as `phantom-1:free`. With `x-phantom-free: off` the chat route answers 402 there, so this answers `model: null` and `reason: insufficient_quota`. `auto` on a key with no route policy and credit reports phantom-1's pick (a 200, not an error): `auto` only needs a route policy when you want your own rules to pick.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "x-phantom-session",
            "in": "header",
            "required": false,
            "description": "Your own conversation id. phantom-1 keeps a conversation's routing state under it: paid chat starts each task on standard and can move it to frontier on any request, tool calls included. Anthropic messages containing only `tool_result` blocks continue the same user message. Other routing (`auto` with a key policy) can keep one model for the session while `stick_minutes` lasts. Only the first 200 characters count. Without this header, Phantom uses Claude Code's `x-claude-code-session-id` when it arrives, and otherwise groups requests by prompt or conversation opening, depending on the route. Phantom stores a salted hash with the selected model and expiry, and keeps provider affinity for the session so its prompt cache stays warm. Read to find the conversation's remembered model.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-session-id",
            "in": "header",
            "required": false,
            "description": "Claude Code's own session id, which it sends on every request. When `x-phantom-session` is missing, Phantom uses this the same way: the first 200 characters, hashed under the key.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-agent-id",
            "in": "header",
            "required": false,
            "description": "Sent by Claude Code from its helper agents (such as Explore), never from the main agent. phantom-1 runs a helper's request on Standard. Phantom reads only whether the header has a value.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-subagent",
            "in": "header",
            "required": false,
            "description": "Codex's helper kind. phantom-1 runs `collab_spawn`, `thread_spawn` and `review` on Standard; other kinds, such as `compact`, route as usual.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-turn-metadata",
            "in": "header",
            "required": false,
            "description": "Codex's turn metadata, as JSON. phantom-1 reads only `subagent_kind`, `thread_source` and `parent_thread_id`, to tell a helper's request apart as with `x-openai-subagent`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-parent-thread-id",
            "in": "header",
            "required": false,
            "description": "The Codex thread a helper thread started from. With `thread_source` set to `subagent` in `x-codex-turn-metadata`, it marks a helper's request.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route",
            "in": "header",
            "required": false,
            "description": "Send `off` to skip the key's route policy for this request. The request runs on the model it names; `model: \"auto\"` is refused with a 400.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-free",
            "in": "header",
            "required": false,
            "description": "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. A key with credit never runs a free model on phantom-1, so there the header changes nothing. Read the same way the chat route reads it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-escalate",
            "in": "header",
            "required": false,
            "description": "Send `1` when the current model isn't managing the task. phantom-1 moves this request one tier up, from standard to frontier. It picks again on the next request, so send the header on each request that should stay up, tool calls included. A key's route policy moves it to the policy's last model. Phantom can't tell a weak answer from a good one, so escalation is your call. Read the same way the chat route reads it; nothing is remembered.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "A chat completions request body. Only the fields below affect routing.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "model": {
                    "type": "string",
                    "description": "The model to request, `auto`, or a router: `phantom-1`, `phantom-1:private` or `phantom-1:free`.",
                    "examples": [
                      "auto"
                    ]
                  },
                  "messages": {
                    "type": "array",
                    "description": "Chat messages. Their size feeds the token estimate, and their opening identifies the conversation when `stick_by_prompt` is on.",
                    "items": {
                      "type": "object",
                      "description": "A message.",
                      "additionalProperties": true
                    }
                  },
                  "tools": {
                    "type": "array",
                    "description": "Tool definitions. A non-empty list makes `has_tools` true.",
                    "items": {
                      "type": "object",
                      "description": "A tool.",
                      "additionalProperties": true
                    }
                  },
                  "functions": {
                    "type": "array",
                    "description": "Older form of `tools`, treated the same.",
                    "items": {
                      "type": "object",
                      "description": "A function.",
                      "additionalProperties": true
                    }
                  },
                  "zdr": {
                    "type": "boolean",
                    "description": "Only providers that delete prompts right away, for `phantom-1` and `auto`. Checked like the chat route checks it: a value that is not true or false is a 400."
                  },
                  "no_training": {
                    "type": "boolean",
                    "description": "Only providers that do not train on prompts, for `phantom-1`, `phantom-1:private` and `auto`. A value that is not true or false is a 400."
                  },
                  "max_tokens": {
                    "type": "integer",
                    "description": "Output estimate for price comparisons (500 when absent, at most 4000)."
                  },
                  "max_completion_tokens": {
                    "type": "integer",
                    "description": "Read before `max_tokens` for the output estimate."
                  },
                  "reasoning_effort": {
                    "type": "string",
                    "description": "Any value but `none` makes `reasoning_requested` true."
                  },
                  "reasoning": {
                    "type": "object",
                    "description": "An object makes `reasoning_requested` true unless it sets `enabled: false` or `effort: \"none\"`.",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "model"
                ],
                "additionalProperties": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The decision.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "model": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "The model the request would run on. `null` when the chat route would refuse the request for credit: the budget is used up, or the key has no credit and the request sent `x-phantom-free: off`."
                    },
                    "reason": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "What picked it: `<condition>:<value>` for a rule, `default`, `requested`, `cache`, `on_empty`, `budget_exceeded`, or `insufficient_quota`. `null` when routing did not apply."
                    },
                    "routed": {
                      "type": "boolean",
                      "description": "`true` when the route policy picked the model."
                    },
                    "fallbacks": {
                      "type": "array",
                      "description": "Models sent to the upstream as fallbacks when `fallback_on_error` is on; empty otherwise. Present only when `routed` is `true`.",
                      "items": {
                        "type": "string",
                        "description": "A model id."
                      }
                    },
                    "tier": {
                      "type": "string",
                      "description": "The tier phantom-1 picked: `standard` or `frontier` for paid phantom-1 and phantom-1:private, `free` for phantom-1:free."
                    },
                    "confidence": {
                      "type": "number",
                      "description": "How sure phantom-1 is of the pick, from 0 to 1. Left out when the router gives none, as with a free pick or a pick made by words that say the last try failed."
                    },
                    "scores": {
                      "type": "object",
                      "description": "phantom-1's score for each tier: `standard` and `frontier`. Left out when the router gives none."
                    }
                  },
                  "required": [
                    "model",
                    "reason",
                    "routed"
                  ]
                },
                "example": {
                  "model": "deepseek/deepseek-v4.1-flash-1017",
                  "reason": "default",
                  "routed": true,
                  "fallbacks": []
                }
              }
            }
          },
          "400": {
            "description": "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. The retired `phantom-1:zdr` is `router_retired`, with `detail` naming `phantom-1:private`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                },
                "example": {
                  "error": "model is required, for example \"auto\"."
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key, or a key Phantom does not know, has revoked or has expired.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Always `invalid_key`.",
                      "enum": [
                        "invalid_key"
                      ]
                    }
                  },
                  "required": [
                    "error"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/key/spend": {
      "get": {
        "operationId": "getV1KeySpend",
        "summary": "Read the key's spend by model and day",
        "description": "What the calling key spent over a date range, by model and by day, and what `phantom-1` routing saved. The range is whole UTC days, `from` and `to` both included, and defaults to this month so far. It covers at most 366 days. Only the calling key shows: to see every key in a workspace, use `GET /v1/workspaces/{id}/spend` with workspace access. Costs are what Phantom charged, markup included. Nothing in the answer carries prompt or completion text, or a key.\n\n`routing` is an estimate. For each call sent to `phantom-1`, `phantom-1:free` or `phantom-1:private`, Phantom prices the same tokens on `phantom-1`'s frontier model at that model's price today, and subtracts what the call cost. Calls that already ran on the frontier model count as no saving. A different model may write more or fewer tokens, and prices change, so treat it as a guide. When the frontier model's price isn't listed, `routing.available` is `false` and no figure is given. Calls that asked for `auto` on a key with a route policy aren't counted: the policy, not `phantom-1`, picked their model.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "First day, `YYYY-MM-DD`, UTC. Defaults to the first of the month `to` falls in.",
            "schema": {
              "type": "string",
              "description": "First day, `YYYY-MM-DD`, UTC. Defaults to the first of the month `to` falls in.",
              "format": "date",
              "examples": [
                "2026-10-01"
              ]
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Last day, `YYYY-MM-DD`, UTC. Defaults to today. Can't be in the future.",
            "schema": {
              "type": "string",
              "description": "Last day, `YYYY-MM-DD`, UTC. Defaults to today. Can't be in the future.",
              "format": "date",
              "examples": [
                "2026-10-18"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The key's spend.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "scope": {
                      "type": "string",
                      "description": "`key` on this route.",
                      "enum": [
                        "key",
                        "workspace"
                      ]
                    },
                    "from": {
                      "type": "string",
                      "description": "First day covered, UTC.",
                      "format": "date"
                    },
                    "to": {
                      "type": "string",
                      "description": "Last day covered, UTC.",
                      "format": "date"
                    },
                    "total": {
                      "type": "object",
                      "description": "Everything in the range.",
                      "properties": {
                        "calls": {
                          "type": "integer",
                          "description": "Calls, free ones included."
                        },
                        "spent_usd": {
                          "type": "number",
                          "description": "What they cost, in US dollars."
                        },
                        "prompt_tokens": {
                          "type": "integer",
                          "description": "Prompt tokens, cached ones included."
                        },
                        "completion_tokens": {
                          "type": "integer",
                          "description": "Completion tokens."
                        }
                      },
                      "required": [
                        "calls",
                        "spent_usd",
                        "prompt_tokens",
                        "completion_tokens"
                      ]
                    },
                    "keys": {
                      "type": "array",
                      "description": "One entry here: the calling key, by the name its workspace gave it, or `This key`.",
                      "items": {
                        "type": "object",
                        "description": "A key.",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "The key's name."
                          },
                          "prefix": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "`null` on this route."
                          },
                          "active": {
                            "type": "boolean",
                            "description": "Whether the key still works."
                          },
                          "calls": {
                            "type": "integer",
                            "description": "Calls in the range."
                          },
                          "spent_usd": {
                            "type": "number",
                            "description": "What they cost, in US dollars."
                          },
                          "saved_usd": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "What `phantom-1` routing saved on this key, in US dollars. `null` when it can't be worked out; see `routing`."
                          },
                          "models": {
                            "type": "array",
                            "description": "The models the key ran, biggest spender first.",
                            "items": {
                              "type": "object",
                              "description": "A model.",
                              "properties": {
                                "model": {
                                  "type": "string",
                                  "description": "The model that ran."
                                },
                                "calls": {
                                  "type": "integer",
                                  "description": "Calls."
                                },
                                "spent_usd": {
                                  "type": "number",
                                  "description": "Cost in US dollars."
                                }
                              },
                              "required": [
                                "model",
                                "calls",
                                "spent_usd"
                              ]
                            }
                          }
                        },
                        "required": [
                          "name",
                          "prefix",
                          "active",
                          "calls",
                          "spent_usd",
                          "saved_usd",
                          "models"
                        ]
                      }
                    },
                    "models": {
                      "type": "array",
                      "description": "Each model that ran, biggest spender first.",
                      "items": {
                        "type": "object",
                        "description": "A model.",
                        "properties": {
                          "model": {
                            "type": "string",
                            "description": "The model that ran."
                          },
                          "calls": {
                            "type": "integer",
                            "description": "Calls."
                          },
                          "spent_usd": {
                            "type": "number",
                            "description": "Cost in US dollars."
                          },
                          "prompt_tokens": {
                            "type": "integer",
                            "description": "Prompt tokens."
                          },
                          "completion_tokens": {
                            "type": "integer",
                            "description": "Completion tokens."
                          }
                        },
                        "required": [
                          "model",
                          "calls",
                          "spent_usd",
                          "prompt_tokens",
                          "completion_tokens"
                        ]
                      }
                    },
                    "days": {
                      "type": "array",
                      "description": "Every day in the range, oldest first. A day with no calls is zero.",
                      "items": {
                        "type": "object",
                        "description": "A day.",
                        "properties": {
                          "date": {
                            "type": "string",
                            "description": "The UTC day.",
                            "format": "date"
                          },
                          "calls": {
                            "type": "integer",
                            "description": "Calls."
                          },
                          "spent_usd": {
                            "type": "number",
                            "description": "Cost in US dollars."
                          }
                        },
                        "required": [
                          "date",
                          "calls",
                          "spent_usd"
                        ]
                      }
                    },
                    "routing": {
                      "type": "object",
                      "description": "What `phantom-1` routing saved.",
                      "properties": {
                        "available": {
                          "type": "boolean",
                          "description": "`false` when the frontier model's price isn't listed. Then only `reason` follows."
                        },
                        "reason": {
                          "type": "string",
                          "description": "Why no saving is given. Only when `available` is `false`."
                        },
                        "calls": {
                          "type": "integer",
                          "description": "Calls sent to a `phantom-1` router."
                        },
                        "spent_usd": {
                          "type": "number",
                          "description": "What they cost, in US dollars."
                        },
                        "baseline_model": {
                          "type": "string",
                          "description": "The model the same calls are priced on."
                        },
                        "baseline_usd": {
                          "type": "number",
                          "description": "What the same calls would have cost on it, in US dollars."
                        },
                        "saved_usd": {
                          "type": "number",
                          "description": "`baseline_usd` less `spent_usd`."
                        },
                        "basis": {
                          "type": "string",
                          "description": "How `baseline_usd` is worked out, in words."
                        }
                      },
                      "required": [
                        "available"
                      ]
                    }
                  },
                  "required": [
                    "scope",
                    "from",
                    "to",
                    "total",
                    "keys",
                    "models",
                    "days",
                    "routing"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "A date that isn't `YYYY-MM-DD` or isn't real, `from` after `to`, a `to` in the future, or a range over 366 days.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key in `Authorization` (`Missing or invalid Authorization header`), or a key Phantom does not know, has revoked or has expired (`invalid_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "500": {
            "description": "The read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages": {
      "post": {
        "operationId": "postV1Messages",
        "summary": "Create a message (Anthropic)",
        "description": "Anthropic's Messages API on a Phantom key, so Claude Code and the Anthropic SDKs work with `ANTHROPIC_BASE_URL=https://phantom.codes`. Any chat model in the catalog works, `auto` included. Anthropic ids such as `claude-sonnet-5-5` map to the upstream's `anthropic/claude-sonnet-5.5`.\n\nBilling and routing match `POST /v1/chat/completions`: Phantom runs the key's route policy, estimates the prompt (system prompt, messages and tools), holds the worst-case cost, sets `max_tokens` to what the hold covers, calls the upstream's `/v1/messages`, and bills the cost the upstream reports, or the catalog rate for the reported tokens. Cache reads and cache writes count as input tokens. A refused or failed call bills nothing. A stream bills when it ends, including when you hang up early; output tokens then fall back to an estimate from the text sent so far.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "anthropicKey": []
          },
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "anthropic-version",
            "in": "header",
            "required": false,
            "description": "Anthropic API version, forwarded to the upstream. Defaults to `2023-06-01` when left out.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "anthropic-beta",
            "in": "header",
            "required": false,
            "description": "Anthropic beta flags (prompt caching, long context and the like), forwarded to the upstream unchanged.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-session",
            "in": "header",
            "required": false,
            "description": "Your own conversation id. phantom-1 keeps a conversation's routing state under it: paid chat starts each task on standard and can move it to frontier on any request, tool calls included. Anthropic messages containing only `tool_result` blocks continue the same user message. Other routing (`auto` with a key policy) can keep one model for the session while `stick_minutes` lasts. Only the first 200 characters count. Without this header, Phantom uses Claude Code's `x-claude-code-session-id` when it arrives, and otherwise groups requests by prompt or conversation opening, depending on the route. Phantom stores a salted hash with the selected model and expiry, and keeps provider affinity for the session so its prompt cache stays warm.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-session-id",
            "in": "header",
            "required": false,
            "description": "Claude Code's own session id, which it sends on every request. When `x-phantom-session` is missing, Phantom uses this the same way: the first 200 characters, hashed under the key.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-agent-id",
            "in": "header",
            "required": false,
            "description": "Sent by Claude Code from its helper agents (such as Explore), never from the main agent. phantom-1 runs a helper's request on Standard. Phantom reads only whether the header has a value.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-subagent",
            "in": "header",
            "required": false,
            "description": "Codex's helper kind. phantom-1 runs `collab_spawn`, `thread_spawn` and `review` on Standard; other kinds, such as `compact`, route as usual.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-turn-metadata",
            "in": "header",
            "required": false,
            "description": "Codex's turn metadata, as JSON. phantom-1 reads only `subagent_kind`, `thread_source` and `parent_thread_id`, to tell a helper's request apart as with `x-openai-subagent`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-parent-thread-id",
            "in": "header",
            "required": false,
            "description": "The Codex thread a helper thread started from. With `thread_source` set to `subagent` in `x-codex-turn-metadata`, it marks a helper's request.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-agent",
            "in": "header",
            "required": false,
            "description": "The coding agent a request came through: `claude-code`, `codex`, `cursor`, `gemini-cli` or `coding-agent`. Phantom sets it when you call an agent's base path (`https://phantom.codes/codex/v1`). Any other value is ignored.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route",
            "in": "header",
            "required": false,
            "description": "Send `off` to skip the key's route policy for this request. The request runs on the model it names; `model: \"auto\"` is refused with a 400.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-escalate",
            "in": "header",
            "required": false,
            "description": "Send `1` when the current model isn't managing the task. phantom-1 moves this request one tier up, from standard to frontier. It picks again on the next request, so send the header on each request that should stay up, tool calls included. A key's route policy moves it to the policy's last model. Phantom can't tell a weak answer from a good one, so escalation is your call.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-free",
            "in": "header",
            "required": false,
            "description": "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. A key with credit never runs a free model on phantom-1, so there the header changes nothing.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-api-key",
            "in": "header",
            "required": false,
            "description": "Your own OpenAI API key. On a call an OpenAI model serves, it is tried first, and a call it served costs nothing on Phantom: OpenAI bills you. If OpenAI refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-anthropic-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Anthropic API key. On a call an Anthropic model serves, it is tried first, and a call it served costs nothing on Phantom: Anthropic bills you. If Anthropic refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-gateway-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Vercel AI Gateway API key. The call runs on it in place of Phantom's key, so your Gateway account pays for it and Phantom charges $0: nothing is held, and a key with no credit runs `phantom-1` on paid models rather than as `phantom-1:free`. The key's budget and spend-rate cap still apply. If the Gateway refuses the key you get a `401` (`invalid_gateway_key`), or a `402` (`gateway_key_no_credit`) when its account is out of credit; the call never falls back to Phantom's key. Provider keys sent with it run inside your Gateway account. Phantom never stores, logs or returns the key. `phantom-1:free` ignores it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "An Anthropic Messages request. Fields not listed go to the upstream unchanged.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "router": {
                    "type": "string",
                    "description": "The router to pick the model: `phantom-1`, `phantom-1:free` or `phantom-1:private` (see `GET /v1/routers`). Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`. Phantom removes it before calling the upstream.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "Required unless the request sends `router`. A chat model id, an Anthropic `claude-*` id, `phantom-1` to let phantom-1 pick, or `auto` to route by the key's route policy (phantom-1 when the key has none). `phantom-1:free` runs only free models, at $0, and needs no credit. `phantom-1:private` routes between models with zero data retention and no training on every provider, and requires both on every call. The retired `phantom-1:zdr` answers 400 `router_retired`.",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "messages": {
                    "type": "array",
                    "description": "The conversation, in Anthropic's format. Must be non-empty.",
                    "examples": [
                      [
                        {
                          "role": "user",
                          "content": "Hello"
                        }
                      ]
                    ],
                    "items": {
                      "type": "object",
                      "description": "A message.",
                      "additionalProperties": true
                    }
                  },
                  "max_tokens": {
                    "type": "integer",
                    "description": "Your output limit. Phantom replaces it with the smallest of this, what the balance buys, and the model's output cap, then shrinks it to what the hold covers."
                  },
                  "stream": {
                    "type": "boolean",
                    "description": "Answer as a server-sent event stream.",
                    "default": false
                  },
                  "system": {
                    "type": "string",
                    "description": "The system prompt. Anthropic also accepts an array of text blocks. Counts toward the prompt estimate."
                  },
                  "tools": {
                    "type": "array",
                    "description": "Tool definitions. Count toward the prompt estimate and the route policy's conditions. Phantom forwards function and custom tools, `namespace`, `local_shell`, `apply_patch`, a `shell` with `environment.type: \"local\"`, `tool_search*`, `mcp`, `mcp_toolset`, `bash_*`, `text_editor_*`, `computer_*`, `memory_*`, and the search and fetch tools below. It drops every other tool type without an error, including any it does not know, because a server tool can bill per call. A `web_search*` tool adds the model's price per search, or $0.01 when the upstream lists none, times its `max_uses` to the hold, so a key needs that much more balance. Phantom sets `max_uses` to 5 when you send none and lowers it to 10 when you send more. A `web_fetch*` tool gets `max_uses` the same way and a `max_content_tokens` of at most 20,000, and the hold adds those tokens at the model's input rate. OpenAI's `web_search`, `web_search_preview` and their dated variants have no `max_uses`: on `/v1/responses` Phantom sets `max_tool_calls` to the same count, and on the other routes it drops them. On `phantom-1:free`, and on `phantom-1` from a key with no credit, Phantom drops every `web_search*` tool: each search costs money even on a free model.",
                    "items": {
                      "type": "object",
                      "description": "A tool.",
                      "additionalProperties": true
                    }
                  },
                  "thinking": {
                    "type": "object",
                    "description": "Extended thinking. When `max_tokens` is lowered below `budget_tokens`, the budget drops to `max_tokens - 1`; when that is under 1024, thinking is removed from the request. `type: \"enabled\"` also counts as reasoning for the route policy.",
                    "properties": {
                      "type": {
                        "type": "string",
                        "description": "`enabled` to turn thinking on."
                      },
                      "budget_tokens": {
                        "type": "integer",
                        "description": "Most tokens the model may spend thinking."
                      }
                    }
                  },
                  "models": {
                    "type": "array",
                    "description": "Dropped. Phantom never lets the upstream pick a model it did not price.",
                    "items": {
                      "type": "string",
                      "description": "A model id."
                    }
                  },
                  "sort": {
                    "type": "string",
                    "description": "How to rank the providers that serve the model: `cost` (the default), `ttft` (fastest first token) or `tps` (most tokens per second). Overrides the key's route policy. Removed before calling the upstream.",
                    "enum": [
                      "cost",
                      "ttft",
                      "tps"
                    ]
                  },
                  "zdr": {
                    "type": "boolean",
                    "description": "Only use providers that delete prompts right away. Off by default. Overrides the key's route policy. With it on, phantom-1 skips its free model. Removed before calling the upstream."
                  },
                  "no_training": {
                    "type": "boolean",
                    "description": "Only use providers that don't train on prompts. Removed before calling the upstream."
                  },
                  "providerOptions": {
                    "type": "object",
                    "description": "Passed to the upstream, except `gateway.models`, which is dropped. `gateway.order` still chooses among providers of the same model. Phantom always sets `gateway.caching: \"auto\"`, and `gateway.sort: \"cost\"` unless you choose a sort. Your `gateway` settings win over `sort`. They can't turn off `zdr` or `no_training`. Phantom also drops `serviceTier`, `speed` and `sharedRequestType` from `gateway` and from the options of every provider (`openai`, `google`, `vertex`, `xai`, `anthropic`), and a top-level `service_tier` or `speed`, so a call runs at the standard tier. It also drops `inferenceRegion` (a pinned region costs more), `inference_geo` and `cache_ttl`, and the `ttl` of any `cache_control` or `cacheControl` (a one-hour cache costs 2x input to write, against the 1.25x Phantom bills), so a call uses the upstream's own region choice and the five-minute cache.",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "messages"
                ],
                "additionalProperties": true
              },
              "example": {
                "model": "phantom-1",
                "max_tokens": 1024,
                "messages": [
                  {
                    "role": "user",
                    "content": "Hello"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upstream's Anthropic message, passed through. Other statuses from the upstream also come back as the upstream sent them, with its Anthropic error body; nothing is billed then.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The message id."
                    },
                    "type": {
                      "type": "string",
                      "description": "`message`."
                    },
                    "role": {
                      "type": "string",
                      "description": "`assistant`."
                    },
                    "model": {
                      "type": "string",
                      "description": "The model the upstream reports running. Billing uses this model's rate when the catalog carries it."
                    },
                    "content": {
                      "type": "array",
                      "description": "The output blocks: text, thinking, tool use.",
                      "items": {
                        "type": "object",
                        "description": "A content block.",
                        "additionalProperties": true
                      }
                    },
                    "stop_reason": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "Why the model stopped."
                    },
                    "stop_sequence": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "The stop sequence that ended the answer, or null when none did."
                    },
                    "usage": {
                      "type": "object",
                      "description": "Token counts Phantom bills from. When they are missing, Phantom estimates from the prompt and the content.",
                      "properties": {
                        "input_tokens": {
                          "type": "integer",
                          "description": "Uncached input tokens."
                        },
                        "output_tokens": {
                          "type": "integer",
                          "description": "Output tokens."
                        },
                        "cache_read_input_tokens": {
                          "type": "integer",
                          "description": "Input tokens read from the cache."
                        },
                        "cache_creation_input_tokens": {
                          "type": "integer",
                          "description": "Input tokens written to the cache."
                        }
                      },
                      "additionalProperties": true
                    },
                    "phantom": {
                      "type": "object",
                      "description": "Added by Phantom: what this call cost and how it was served.",
                      "properties": {
                        "cost_usd": {
                          "type": "number",
                          "description": "What this call was charged, in US dollars."
                        },
                        "provider": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The provider that answered, or null when the upstream did not say."
                        },
                        "attempts": {
                          "type": "integer",
                          "description": "Provider attempts across every model tried. 1 when the first try worked."
                        },
                        "fallback": {
                          "type": "boolean",
                          "description": "`true` when a provider or model failed and another one answered."
                        }
                      }
                    }
                  }
                },
                "example": {
                  "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
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "With `stream: true`: the upstream's Anthropic events (`message_start`, `content_block_delta`, `message_delta`, `message_stop` and the rest), passed through. Right before the chunk that holds `event: message_stop`, Phantom inserts `event: phantom.receipt` with `data: {\"type\":\"phantom.receipt\",\"receipt\":\"<compact receipt>\",\"phantom\":{...}}`, where `phantom` has the same fields as in a non-streaming answer. Without a signing key the event carries `phantom` only."
                }
              }
            },
            "headers": {
              "x-phantom-request-id": {
                "description": "Phantom's id for this request (`req_` + 24 hex characters). The same value is `request_id` in the receipt. Also sent when the upstream refuses the call and its error is passed through.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-router": {
                "description": "The router that picked the model: `phantom-1`, `phantom-1:free` or `phantom-1:private`. Sent when the request named a router in `router` or `model`, or sent `model: \"auto\"` on a key with no route policy. The body's `model` names the model that ran. Also sent with a passed-through upstream error. The body adds `router` with the same name, and in a stream the `phantom.receipt` event carries it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-routed": {
                "description": "Present only when the key's route policy picked the model: the model id, then `; reason=` and what decided it. A rule shows as `<condition>:<value>`; other reasons are `default` (the policy's first model), `requested`, `cache` (kept on the conversation's model) and `on_empty` (past the budget, the cheapest model). A `phantom-1` call never sends it; see `x-phantom-route-receipt`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-receipt": {
                "description": "Sent on routed `phantom-1` calls: the model you asked for, the tier and model that ran, how sure phantom-1 was when the pick gives a confidence, and a short reason label. Reason labels may change. Sent on routed phantom-1 calls: names requested model, served tier, underlying model, confidence when the pick gives one, and reason.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-scores": {
                "description": "phantom-1's score for each model and the one it picked. Sent only when you ask with `x-phantom-route-debug: 1` or `router_debug: true`. For debugging only; the format may change. Sent when debug mode is requested: returns phantom-1's score for each model and the one it picked.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-model": {
                "description": "The model id Phantom sent to the upstream. On chat and messages, the receipt's `model_served` holds the id the upstream reported running. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-request-id": {
                "description": "The upstream's own request id, copied from its `x-request-id` response header when it sends one. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. Non-streaming answers only. `model_requested` is the id you sent after renames (`auto` stays `auto`), `model_served` is the `model` field of the upstream's answer, and `reasoning_tokens` is 0. A stream carries the receipt in the body instead.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cached-tokens": {
                "description": "Prompt tokens the upstream served from its cache, billed at the cached rate. Non-streaming answers only: the `cache_read_input_tokens` the upstream reported.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars. Non-streaming answers only. A stream carries it in the `phantom.receipt` event.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-provider": {
                "description": "The provider that answered, such as `anthropic`, `bedrock` or `azure`. Left out when the upstream does not say. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-fallback": {
                "description": "`true` when a provider or model failed and another one answered the call, `false` when the first try worked. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. Non-streaming answers only. A stream's headers leave before it is billed.",
                "schema": {
                  "type": "string"
                }
              },
              "cache-control": {
                "description": "Caching rules for the response. Streams only: `no-cache`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "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). `phantom-1:free` answers 400 when no free model can take the request (images, tools, long context). `phantom-1:private` answers `private_model_unfit` when none of its zero-data-retention models can take the request. With `zdr` on, `zdr_unavailable` means no provider of the model has zero data retention; nothing ran and nothing is billed. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "401": {
            "description": "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. A call can't pay for itself with x402 or MPP. Or the Vercel AI Gateway refused the key in `x-gateway-api-key` (`invalid_gateway_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "402": {
            "description": "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). Then: the key is past its spend cap (and its policy did not move the request to its cheapest model), holds less than $0.001, cannot pay for the prompt alone, cannot buy 32 output tokens after it, or the hold failed. Or the Vercel AI Gateway account behind `x-gateway-api-key` is out of credit or past its budget (`gateway_key_no_credit`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                },
                "example": {
                  "type": "error",
                  "error": {
                    "type": "billing_error",
                    "message": "Not enough credit ($0.0000 left). Top up at https://phantom.codes/checkout."
                  }
                }
              }
            }
          },
          "404": {
            "description": "The model is not a chat model in the catalog, or it was retired (the error names the closest current model).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached. On free models (`phantom-1:free`, and `phantom-1` or `auto` from a key with no credit), counted per workspace: 20 requests a minute (`free_rate_exceeded`) or the daily cap (`free_daily_cap`): 50 a day, 200 a day through a coding agent base path (such as `/codex/v1`), or 1,000 a day once the workspace has taken in $10 of credit. The message says how to raise the cap.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "Phantom has no upstream key configured, or the upstream could not be reached. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "503": {
            "description": "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`). Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/messages/count_tokens": {
      "post": {
        "operationId": "postV1MessagesCountTokens",
        "summary": "Count the input tokens of a Messages request",
        "description": "Counts the input tokens of an Anthropic Messages request without running it. Free: nothing is held or billed, but the key must be valid and hold at least $0.001. Claude Code calls this to size its context.\n\nPhantom forwards the body to the upstream's `count_tokens` endpoint and returns the upstream's status and body unchanged. When `model` is not a chat model in the catalog (`auto`, for example), the count runs on `anthropic/claude-sonnet-5.5`.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "anthropicKey": []
          },
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "anthropic-version",
            "in": "header",
            "required": false,
            "description": "Anthropic API version, forwarded to the upstream. Defaults to `2023-06-01` when left out.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "anthropic-beta",
            "in": "header",
            "required": false,
            "description": "Anthropic beta flags (prompt caching, long context and the like), forwarded to the upstream unchanged.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "An Anthropic Messages request body. Every field goes to the upstream unchanged except `model`.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "router": {
                    "type": "string",
                    "description": "A router's name in place of `model`. Here it runs the model that router names for this endpoint, as `model: \"phantom-1\"` does. Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "The model to count for. Aliases resolve to the catalog id. Replaced with `anthropic/claude-sonnet-5.5` when it is missing or not a chat model in the catalog.",
                    "examples": [
                      "claude-sonnet-5-5"
                    ]
                  },
                  "messages": {
                    "type": "array",
                    "description": "The conversation to count, in Anthropic's format.",
                    "items": {
                      "type": "object",
                      "description": "A message.",
                      "additionalProperties": true
                    }
                  },
                  "system": {
                    "type": "string",
                    "description": "The system prompt, when there is one. Anthropic also accepts an array of text blocks."
                  },
                  "tools": {
                    "type": "array",
                    "description": "Tool definitions, which count toward the input.",
                    "items": {
                      "type": "object",
                      "description": "A tool.",
                      "additionalProperties": true
                    }
                  }
                },
                "additionalProperties": true
              },
              "example": {
                "model": "claude-sonnet-5-5",
                "messages": [
                  {
                    "role": "user",
                    "content": "Hello"
                  }
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upstream's answer, passed through.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "input_tokens": {
                      "type": "integer",
                      "description": "Tokens the request would read."
                    }
                  },
                  "required": [
                    "input_tokens"
                  ]
                },
                "example": {
                  "input_tokens": 10
                }
              }
            }
          },
          "400": {
            "description": "The body is not JSON. An upstream refusal comes back with the upstream's own status and body. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "401": {
            "description": "No key in `x-api-key` or `Authorization`, a key Phantom does not know, or an expired or deactivated key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          },
          "402": {
            "description": "Sent only after the body checks out (a body that is not JSON or an invalid `router` is a 400 whatever the key holds). Then: the key is past its spend cap (unless its route policy says `on_empty: \"cheapest\"`), or holds less than $0.001. A request naming `phantom-1:free` skips these credit checks.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                },
                "example": {
                  "type": "error",
                  "error": {
                    "type": "billing_error",
                    "message": "Not enough credit ($0.0000 left). Top up at https://phantom.codes/checkout."
                  }
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap is reached.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "The upstream could not be reached. Also a 5xx from the upstream, passed through with its own status and body.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnthropicError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/models": {
      "get": {
        "operationId": "getV1Models",
        "summary": "List models with their prices and limits",
        "description": "The model catalog with prices, newest first. The upstream decides which models exist and what they cost. Phantom reads that list and adds its 5% markup to every price, which is what each call bills at. Needs no key.",
        "tags": [
          "Inference"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The catalog. Empty when the upstream could not be reached.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "description": "Always `list`.",
                      "enum": [
                        "list"
                      ]
                    },
                    "data": {
                      "type": "array",
                      "description": "One entry per model.",
                      "items": {
                        "type": "object",
                        "description": "A model.",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "The id to send as `model`.",
                            "examples": [
                              "anthropic/claude-sonnet-5.5"
                            ]
                          },
                          "object": {
                            "type": "string",
                            "description": "Always `model`.",
                            "enum": [
                              "model"
                            ]
                          },
                          "name": {
                            "type": "string",
                            "description": "Display name."
                          },
                          "created": {
                            "type": "integer",
                            "description": "When the upstream published the model, in Unix seconds. Same as `released`."
                          },
                          "released": {
                            "type": "integer",
                            "description": "When the upstream published the model, in Unix seconds."
                          },
                          "owned_by": {
                            "type": "string",
                            "description": "Always `phantom`.",
                            "enum": [
                              "phantom"
                            ]
                          },
                          "kind": {
                            "type": "string",
                            "description": "Which route serves the model.",
                            "enum": [
                              "chat",
                              "embedding",
                              "image",
                              "video",
                              "speech",
                              "transcription",
                              "reranking"
                            ]
                          },
                          "context_length": {
                            "type": "integer",
                            "description": "The most tokens the model reads in one request."
                          },
                          "max_output_tokens": {
                            "type": "integer",
                            "description": "The most tokens the model writes in one response. Left out when the upstream publishes no limit."
                          },
                          "pricing": {
                            "type": "object",
                            "description": "US dollars per token (per image for image models). Video, speech and transcription models bill by length, so their `prompt`, `prompt_cached` and `completion` are 0 and their own rate is in `video_per_second`, `speech_per_character` or `transcription_per_second`.",
                            "properties": {
                              "prompt": {
                                "type": "number",
                                "description": "Per input token."
                              },
                              "prompt_cached": {
                                "type": "number",
                                "description": "Per input token served from the upstream's cache. 15% of `prompt` when the upstream publishes no cached rate."
                              },
                              "completion": {
                                "type": "number",
                                "description": "Per output token."
                              },
                              "tiers": {
                                "type": "array",
                                "description": "Only on models whose upstream charges more for a long prompt: the higher prices, lowest size first. A request whose prompt has more tokens than `over_prompt_tokens` pays that tier's prices for every token, not only the tokens past it. A model with one price has no `tiers`.",
                                "items": {
                                  "type": "object",
                                  "description": "One tier.",
                                  "properties": {
                                    "over_prompt_tokens": {
                                      "type": "integer",
                                      "description": "The tier applies to a prompt of more tokens than this."
                                    },
                                    "prompt": {
                                      "type": "number",
                                      "description": "Per input token in this tier."
                                    },
                                    "prompt_cached": {
                                      "type": "number",
                                      "description": "Per input token served from the upstream's cache in this tier."
                                    },
                                    "completion": {
                                      "type": "number",
                                      "description": "Per output token in this tier."
                                    }
                                  },
                                  "required": [
                                    "over_prompt_tokens",
                                    "prompt",
                                    "prompt_cached",
                                    "completion"
                                  ]
                                }
                              },
                              "video_per_second": {
                                "type": "object",
                                "description": "Only on video models: US dollars per second of video, by the upstream's tier label (`720p`, `1080p`, `pro-audio`, `default`...). A job starts at the highest of them, whatever `resolution` the caller sends, so that is what `POST /v1/video/generations` holds and charges: seconds times the highest rate.",
                                "examples": [
                                  {
                                    "720p": 0.105,
                                    "1080p": 0.1575
                                  }
                                ],
                                "additionalProperties": true
                              },
                              "speech_per_character": {
                                "type": "number",
                                "description": "Only on speech models: US dollars per input character."
                              },
                              "transcription_per_second": {
                                "type": "number",
                                "description": "Only on transcription models: US dollars per second of audio."
                              }
                            },
                            "required": [
                              "prompt",
                              "prompt_cached",
                              "completion"
                            ]
                          },
                          "video_seconds": {
                            "type": "array",
                            "description": "Only on video models that list their lengths: the whole numbers of seconds the model makes, smallest first. `seconds` on `POST /v1/video/generations` must be one of them (a 400 `invalid_seconds` otherwise). Absent when the upstream lists none; the route then takes 1 to 60.",
                            "items": {
                              "type": "integer",
                              "description": "A length in seconds."
                            }
                          },
                          "promo": {
                            "type": "string",
                            "description": "A short label for a current offer, when there is one."
                          },
                          "description": {
                            "type": "string",
                            "description": "What the model is."
                          },
                          "web_search": {
                            "type": "boolean",
                            "description": "The model can search the web."
                          },
                          "zdr": {
                            "type": "boolean",
                            "description": "The upstream promises not to retain requests (zero data retention)."
                          },
                          "router": {
                            "type": "boolean",
                            "description": "`true` for a router (`phantom-1`, `phantom-1:free`, `phantom-1:private`), which picks a model per request. Its prices are those of its default chat model: the standard tier for `phantom-1`, the first free model for `phantom-1:free`, the standard tier for `phantom-1:private`. `GET /v1/routers` lists every model each one picks from, with prices."
                          },
                          "no_training": {
                            "type": "boolean",
                            "description": "The upstream trains on no request to this model."
                          },
                          "free": {
                            "type": "boolean",
                            "description": "The upstream charges nothing for the model."
                          },
                          "capabilities": {
                            "type": "array",
                            "description": "Capability tags, such as `tool-use` or `vision`.",
                            "items": {
                              "type": "string",
                              "description": "A tag."
                            }
                          },
                          "modalities": {
                            "type": "object",
                            "description": "Input and output types, when the upstream publishes them.",
                            "properties": {
                              "input": {
                                "type": "array",
                                "description": "Accepted inputs, such as `text` or `image`.",
                                "items": {
                                  "type": "string",
                                  "description": "An input type."
                                }
                              },
                              "output": {
                                "type": "array",
                                "description": "Produced outputs.",
                                "items": {
                                  "type": "string",
                                  "description": "An output type."
                                }
                              }
                            },
                            "required": [
                              "input",
                              "output"
                            ]
                          },
                          "deprecated_at": {
                            "type": "string",
                            "description": "When the upstream retires the model, when it has announced a date."
                          }
                        },
                        "required": [
                          "id",
                          "object",
                          "name",
                          "created",
                          "released",
                          "owned_by",
                          "kind",
                          "context_length",
                          "pricing",
                          "description",
                          "web_search",
                          "zdr",
                          "router",
                          "no_training",
                          "free",
                          "capabilities"
                        ]
                      }
                    }
                  },
                  "required": [
                    "object",
                    "data"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=300, stale-while-revalidate=3600`: the CDN keeps the answer for 5 minutes.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/models/status": {
      "get": {
        "operationId": "getV1ModelsStatus",
        "summary": "Check whether a model is answering right now",
        "description": "Whether a model is answering now. Phantom reads each provider's uptime, speed and price for the model from the upstream and sums them up: `up` when the best provider worked at least 95% of the time over the last 15 minutes (the last day when 15 minutes is unreported), `degraded` at 50% or more, `down` below that or with no provider. A reading can be about 10 minutes old: Phantom keeps the upstream's figures for 5 minutes, and the CDN keeps each answer for a minute and may serve it stale for 5 more while it refreshes. Needs no key.",
        "tags": [
          "Inference"
        ],
        "security": [],
        "parameters": [
          {
            "name": "model",
            "in": "query",
            "required": true,
            "description": "A model id from `GET /v1/models`, or `phantom-1`.",
            "schema": {
              "type": "string",
              "description": "A model id from `GET /v1/models`, or `phantom-1`.",
              "examples": [
                "phantom-1"
              ]
            }
          },
          {
            "name": "job",
            "in": "query",
            "required": false,
            "description": "For `phantom-1`: which of its models to check. Ignored for other ids.",
            "schema": {
              "type": "string",
              "description": "For `phantom-1`: which of its models to check. Ignored for other ids.",
              "enum": [
                "chat",
                "vision",
                "embedding",
                "rerank",
                "image",
                "video",
                "speech",
                "transcription"
              ],
              "default": "chat"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The model's status.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "requested": {
                      "type": "string",
                      "description": "The `model` you sent."
                    },
                    "model": {
                      "type": "string",
                      "description": "The model that was checked. For `phantom-1`, the model that runs `job` (chat checks its standard model)."
                    },
                    "status": {
                      "type": "string",
                      "description": "The summary.",
                      "enum": [
                        "up",
                        "degraded",
                        "down"
                      ]
                    },
                    "uptime_15m": {
                      "type": [
                        "number",
                        "null"
                      ],
                      "description": "The best provider's share of requests that worked over the last 15 minutes (or the last day when 15 minutes is unreported), in percent."
                    },
                    "cheapest": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "The cheapest working provider's prices, which is where a call sorted by cost lands. Null for models priced per image, second or character.",
                      "properties": {
                        "input_per_m": {
                          "type": "number",
                          "description": "US dollars per million input tokens."
                        },
                        "output_per_m": {
                          "type": "number",
                          "description": "US dollars per million output tokens."
                        }
                      },
                      "required": [
                        "input_per_m",
                        "output_per_m"
                      ]
                    },
                    "providers": {
                      "type": "array",
                      "description": "Each provider, best uptime first.",
                      "items": {
                        "type": "object",
                        "description": "One provider.",
                        "properties": {
                          "provider": {
                            "type": "string",
                            "description": "The provider's name."
                          },
                          "uptime_15m": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Share of requests that worked over the last 15 minutes, in percent."
                          },
                          "uptime_1d": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Share of requests that worked over the last day, in percent."
                          },
                          "latency_p50_ms": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "Median time to first token over the last hour, in milliseconds."
                          },
                          "input_per_m": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "US dollars per million input tokens."
                          },
                          "output_per_m": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "US dollars per million output tokens."
                          }
                        },
                        "required": [
                          "provider"
                        ]
                      }
                    }
                  },
                  "required": [
                    "requested",
                    "model",
                    "status",
                    "providers"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=60, stale-while-revalidate=300`: the CDN keeps a status for a minute. Errors carry no cache header.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "`model` is missing, or `job` is not one of the listed values.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "The upstream has no such model, or could not be reached (`model_not_found`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/privacy": {
      "get": {
        "operationId": "getV1Privacy",
        "summary": "Fetch what is stored about you",
        "description": "Reports what rows exist for the caller, counted live from the database. Send a key, a session cookie, or both; a signed-in account and an anonymous key are separate, and the report covers each one you send.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "apiKey": []
          },
          {
            "session": []
          }
        ],
        "responses": {
          "200": {
            "description": "The report.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "tier": {
                      "type": "string",
                      "description": "`account` when a signed-in session came with the request, otherwise `anonymous`.",
                      "enum": [
                        "account",
                        "anonymous"
                      ]
                    },
                    "key": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "About the key in `Authorization`. `null` when none was sent.",
                      "properties": {
                        "identity": {
                          "type": [
                            "object",
                            "null"
                          ],
                          "description": "Always `null`: `api_keys` has no identity column."
                        },
                        "identity_linkable": {
                          "type": "boolean",
                          "description": "`true` when an `account_grants` row pairs this key with a signed-in account (the key was funded by a historical account grant). `DELETE /v1/account` removes that row."
                        },
                        "prompts_stored": {
                          "type": "integer",
                          "description": "Always `0`: the API stores no prompt text."
                        },
                        "usage_rows": {
                          "type": "integer",
                          "description": "Billing rows for this key in `usage_log`: model, token counts and cost, no content."
                        },
                        "zdr_requests": {
                          "type": "integer",
                          "description": "Of those rows, requests on `phantom-1:private`, or on `phantom-1:zdr`, its retired name. Phantom sent each one with zero data retention required."
                        },
                        "payment_linkable": {
                          "type": "boolean",
                          "description": "`true` when a payment names this key as the target of a top-up (`payments.target_key_hash`), or a workspace purchase funds its workspace."
                        }
                      },
                      "required": [
                        "identity",
                        "identity_linkable",
                        "prompts_stored",
                        "usage_rows",
                        "zdr_requests",
                        "payment_linkable"
                      ]
                    },
                    "account": {
                      "type": [
                        "object",
                        "null"
                      ],
                      "description": "About the signed-in account. `null` without a session.",
                      "properties": {
                        "identity": {
                          "type": "object",
                          "description": "What Neon Auth holds.",
                          "properties": {
                            "email": {
                              "type": [
                                "string",
                                "null"
                              ],
                              "description": "The account's email address."
                            },
                            "providers": {
                              "type": "array",
                              "description": "Sign-in methods linked to the account, such as `credential`, `google` or `github`.",
                              "items": {
                                "type": "string",
                                "description": "A provider id."
                              }
                            }
                          },
                          "required": [
                            "email",
                            "providers"
                          ]
                        }
                      },
                      "required": [
                        "identity"
                      ]
                    },
                    "invariants": {
                      "type": "object",
                      "description": "Facts about the whole system, the same for every caller.",
                      "properties": {
                        "prompts_written_by_api": {
                          "type": "boolean",
                          "description": "Always `false`.",
                          "enum": [
                            false
                          ]
                        },
                        "key_has_identity_column": {
                          "type": "boolean",
                          "description": "Always `false`.",
                          "enum": [
                            false
                          ]
                        },
                        "payment_to_key_join_exists": {
                          "type": "boolean",
                          "description": "Always `true`: a top-up records the key it credits. Whether that applies to you is `key.payment_linkable`.",
                          "enum": [
                            true
                          ]
                        },
                        "identity_to_key_join_exists": {
                          "type": "boolean",
                          "description": "Always `true`: `account_grants` pairs an account with the key it funded. Whether that applies to you is `key.identity_linkable`.",
                          "enum": [
                            true
                          ]
                        }
                      },
                      "required": [
                        "prompts_written_by_api",
                        "key_has_identity_column",
                        "payment_to_key_join_exists",
                        "identity_to_key_join_exists"
                      ]
                    }
                  },
                  "required": [
                    "tier",
                    "key",
                    "account",
                    "invariants"
                  ]
                },
                "example": {
                  "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
                  }
                }
              }
            }
          },
          "401": {
            "description": "A key Phantom does not know, has revoked or has expired (`invalid_key`), or neither a key nor a session came with the request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                },
                "example": {
                  "error": "invalid_key"
                }
              }
            }
          }
        }
      }
    },
    "/v1/purchase/base": {
      "post": {
        "operationId": "postV1PurchaseBase",
        "summary": "Start a Base USDC purchase",
        "description": "Creates a Stripe deposit address for the exact USDC amount on Base. Credit is granted only after Stripe confirms settlement by webhook. Minimum $1.00.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount_usd": {
                    "type": "number",
                    "description": "Amount in US dollars."
                  },
                  "bundle": {
                    "type": "string",
                    "description": "Optional named bundle."
                  },
                  "target_api_key": {
                    "type": "string",
                    "description": "Optional key to top up."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Deposit address and payment quote.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payment_id": {
                      "type": "string",
                      "description": "Phantom purchase id."
                    },
                    "coin": {
                      "type": "string",
                      "description": "Always `usdc-base`."
                    },
                    "network": {
                      "type": "string",
                      "description": "Always `base`."
                    },
                    "recipient": {
                      "type": "string",
                      "description": "Stripe deposit address for this payment."
                    },
                    "amount": {
                      "type": "string",
                      "description": "Exact amount in USDC."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Quote expiry."
                    },
                    "recovery_code": {
                      "type": "string",
                      "description": "Guest recovery code."
                    }
                  },
                  "required": [
                    "payment_id",
                    "coin",
                    "network",
                    "recipient",
                    "amount",
                    "expires_at",
                    "recovery_code"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "The body is not a JSON object, the purchase is invalid, or it is under $1.00."
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Stripe Base USDC deposits are not available."
          }
        }
      }
    },
    "/v1/purchase/card": {
      "post": {
        "operationId": "postV1PurchaseCard",
        "summary": "Start a card payment for prepaid credit",
        "description": "Creates a Stripe PaymentIntent (Stripe's record of one card charge) and a pending payment row. Pay it in the browser with Stripe.js using `client_secret`. The PaymentIntent allows only payment methods that never redirect the buyer (cards, Link and wallets), and a card that needs 3D Secure completes it in Stripe's dialog, so the buyer stays on the page. Then poll `GET /v1/purchase/{id}/status`. The card is charged the price plus Stripe's card fee (see `card_fee_bps` in `GET /v1/bundles`). From $50 Phantom pays Stripe's fixed 30 cents, so the card pays only the percentage. The key receives the price, plus bonus credit from $100 (`bonus_tiers` in `GET /v1/bundles`); `credit_usd` says how much. Needs no key. Keep `recovery_code`: it is shown once, and it is the only way to get the key back if the page is lost.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount_usd": {
                    "type": "number",
                    "description": "The price in US dollars, before Stripe's card fee. Must be within the limits from `GET /v1/bundles`, and at least the card minimum. Required unless `bundle` is sent.",
                    "examples": [
                      10
                    ]
                  },
                  "validity_days": {
                    "type": "integer",
                    "description": "Days a new key stays valid, a whole number.",
                    "default": 365,
                    "minimum": 1,
                    "maximum": 3650
                  },
                  "bundle": {
                    "type": "string",
                    "description": "An old preset name, used only when `amount_usd` is missing. Each stands for a fixed dollar amount.",
                    "enum": [
                      "test",
                      "small",
                      "medium",
                      "large",
                      "whale"
                    ]
                  },
                  "target_api_key": {
                    "type": "string",
                    "description": "A key you hold, to add the credit to it rather than get a new key. It must be an active `sk-phantom-` key; a key in a workspace adds the credit to the workspace. Naming it stores a link from this payment to that key. Without it, the purchase makes a new key in a new guest workspace and links the payment to that workspace."
                  },
                  "hosted": {
                    "type": "boolean",
                    "description": "Return a Stripe-hosted `checkout_url` instead of a `client_secret`, for callers with no card form, such as the Phantom CLI. Open the link in a browser, pay, then poll the status route with the recovery code. After paying, Stripe sends the buyer to `/checkout/paid`. Stripe's page asks for an email address and the cardholder's name; Stripe keeps them, and Phantom never sees them.",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The payment is created and waiting for the card.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payment_id": {
                      "type": "string",
                      "description": "The payment id to poll."
                    },
                    "client_secret": {
                      "type": "string",
                      "description": "The PaymentIntent secret Stripe.js needs to confirm the card. Absent with `hosted: true`."
                    },
                    "checkout_url": {
                      "type": "string",
                      "description": "With `hosted: true`: the Stripe page where the buyer pays. It expires after an hour."
                    },
                    "recovery_code": {
                      "type": "string",
                      "description": "Shown once. Send it as `x-phantom-recovery-code` on the status poll, or to `POST /v1/purchase/recover`, to get the key."
                    },
                    "amount_cents": {
                      "type": "integer",
                      "description": "What the card is charged, in US cents: the price plus Stripe's fee on the whole charge, rounded up to the cent."
                    },
                    "credit_usd": {
                      "type": "number",
                      "description": "Credit the key receives: the price plus any bonus."
                    }
                  },
                  "required": [
                    "payment_id",
                    "recovery_code",
                    "amount_cents",
                    "credit_usd"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "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.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Stripe or the database failed. `detail` carries the error message.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "Card checkout is off because no Stripe key is set.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    },
                    "code": {
                      "type": "string",
                      "description": "Always `card_unavailable`.",
                      "enum": [
                        "card_unavailable"
                      ]
                    }
                  },
                  "required": [
                    "detail",
                    "code"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/purchase/recover": {
      "post": {
        "operationId": "postV1PurchaseRecover",
        "summary": "Recover a purchased key from its recovery code",
        "description": "Returns the key a paid purchase issued, given the recovery code shown at checkout. Needs no payment id and does not expire; it works for as long as the payment row exists. If the key was never handed out, this call creates it. For a Solana purchase that is not paid yet, it first looks on chain for the transfer, as the status poll does, and records one it finds with Stripe. It still answers 404 then: Stripe's webhook marks the payment paid, usually within a minute, and the next call returns the key. An unknown code and an unpaid payment get the same answer, so the route does not reveal which codes exist. Needs no API key.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "recovery_code": {
                    "type": "string",
                    "description": "The recovery code. Spaces, dashes and case are ignored, and look-alike letters (I, L, O, U) are read as 1, 1, 0, V. At least 16 characters after that."
                  }
                },
                "required": [
                  "recovery_code"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The purchase is paid.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "api_key": {
                      "type": "string",
                      "description": "The key. An empty string when the purchase topped up a key you already hold."
                    },
                    "workspace_id": {
                      "type": "string",
                      "description": "The guest workspace the key sits in. Left out for a top-up."
                    },
                    "recovery": {
                      "type": "object",
                      "description": "The workspace's recovery file, whose `management_credential` is this recovery code. Left out for a top-up.",
                      "properties": {
                        "version": {
                          "type": "integer",
                          "description": "The file format version."
                        },
                        "workspace_id": {
                          "type": "string",
                          "description": "The workspace the key sits in."
                        },
                        "management_credential": {
                          "type": "string",
                          "description": "The recovery code with its dashes and spaces removed."
                        }
                      }
                    },
                    "credit_usd": {
                      "type": "number",
                      "description": "Credit the purchase added, in US dollars."
                    }
                  },
                  "required": [
                    "api_key",
                    "credit_usd"
                  ]
                },
                "example": {
                  "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": "..."
                  }
                }
              }
            }
          },
          "400": {
            "description": "The body is not a JSON object, or `recovery_code` is missing, not a string, or too short.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "404": {
            "description": "No paid purchase has that code. A Solana transfer this call just found and recorded is paid once Stripe confirms it: try again in a minute.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                },
                "example": {
                  "error": "No completed payment for that code"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/purchase/solana": {
      "post": {
        "operationId": "postV1PurchaseSolana",
        "summary": "Start a USDC payment on Solana for prepaid credit",
        "description": "Creates a pending payment paid in USDC on Solana, to Stripe's deposit address. Send exactly `amount` to `recipient` with `reference` attached to the transfer (the `solana_pay_url` link does this in a wallet app), then poll `GET /v1/purchase/{id}/status`. The poll looks for the transfer on chain and records it with Stripe; once Stripe has checked it, Stripe's signed webhook adds the credit. The price is rounded up to the next cent, because Stripe books whole cents, and only a transfer of exactly `amount` counts. The quote holds for 30 minutes. The key receives the price plus bonus credit from $100 (`bonus_tiers` in `GET /v1/bundles`); `credit_usd` says how much. SOL and USDT are no longer accepted: Stripe takes neither. Needs no key. Keep `recovery_code`: it is shown once.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "coin": {
                    "type": "string",
                    "description": "The coin to pay with. USDC is the only one; `usdcsol` is accepted as `usdc`. `sol` and `usdt` get a 400.",
                    "enum": [
                      "usdc",
                      "usdcsol"
                    ],
                    "default": "usdc"
                  },
                  "amount_usd": {
                    "type": "number",
                    "description": "The price in US dollars, within the limits from `GET /v1/bundles`. Required unless `bundle` is sent.",
                    "examples": [
                      5
                    ]
                  },
                  "validity_days": {
                    "type": "integer",
                    "description": "Days a new key stays valid, a whole number.",
                    "default": 365,
                    "minimum": 1,
                    "maximum": 3650
                  },
                  "bundle": {
                    "type": "string",
                    "description": "An old preset name, used only when `amount_usd` is missing.",
                    "enum": [
                      "test",
                      "small",
                      "medium",
                      "large",
                      "whale"
                    ]
                  },
                  "target_api_key": {
                    "type": "string",
                    "description": "A key you hold, to add the credit to it rather than get a new key. It must be an active `sk-phantom-` key; a key in a workspace adds the credit to the workspace. Naming it stores a link from this payment to that key. Without it, the purchase makes a new key in a new guest workspace and links the payment to that workspace."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The payment is created and waiting for the transfer.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payment_id": {
                      "type": "string",
                      "description": "The payment id to poll."
                    },
                    "coin": {
                      "type": "string",
                      "description": "The coin to send. Always `usdc`.",
                      "enum": [
                        "usdc"
                      ]
                    },
                    "recipient": {
                      "type": "string",
                      "description": "Stripe's deposit address to pay. It can change from one day to the next, so use the one in this response."
                    },
                    "amount": {
                      "type": "string",
                      "description": "The exact amount to send, in USDC, as a decimal string.",
                      "examples": [
                        "5"
                      ]
                    },
                    "amount_base_units": {
                      "type": "string",
                      "description": "The same amount in millionths of a USDC, as an integer string.",
                      "examples": [
                        "5000000"
                      ]
                    },
                    "mint": {
                      "type": "string",
                      "description": "USDC's mint address on Solana (which token the transfer moves)."
                    },
                    "credit_usd": {
                      "type": "number",
                      "description": "Credit the key receives: the price plus any bonus."
                    },
                    "reference": {
                      "type": "string",
                      "description": "A random public key, base58. Attach it to the transfer as a read-only account so Phantom can find it on chain."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "When the quote ends, 30 minutes from now. A transfer that lands a little late is still accepted.",
                      "format": "date-time"
                    },
                    "recovery_code": {
                      "type": "string",
                      "description": "Shown once. Send it as `x-phantom-recovery-code` on the status poll, or to `POST /v1/purchase/recover`, to get the key."
                    },
                    "solana_pay_url": {
                      "type": "string",
                      "description": "A `solana:` link (Solana Pay format) with the recipient, amount, token and reference filled in, for a wallet app or QR code."
                    }
                  },
                  "required": [
                    "payment_id",
                    "coin",
                    "recipient",
                    "amount",
                    "amount_base_units",
                    "mint",
                    "credit_usd",
                    "reference",
                    "expires_at",
                    "recovery_code",
                    "solana_pay_url"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "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.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "The payment could not be saved.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "503": {
            "description": "USDC on Solana is off right now. `GET /v1/coins` lists it only while it is on.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/purchase/stripe-crypto": {
      "post": {
        "operationId": "postV1PurchaseStripeCrypto",
        "summary": "Start a crypto payment on Stripe's page",
        "description": "Creates a Stripe PaymentIntent (Stripe's record of one payment) that takes only crypto, and a pending payment row. Send the buyer to `checkout_url`, a Stripe link (today on `pm-redirects.stripe.com`, which hands the buyer on to Stripe's crypto page) where they pick the coin and network (USDC on Solana, Base, Ethereum, Polygon or Tempo; USDP; USDG), connect a wallet and pay. Stripe then sends them back to `/checkout`. Poll `GET /v1/purchase/{id}/status` with the recovery code: Stripe's signed webhook adds the credit once the payment succeeds, and the status reads `confirming` while the network confirms it. The buyer pays the price, rounded up to the next cent, with no fee on top; the minimum is $1.00. The key receives the price, plus bonus credit from $100 (`bonus_tiers` in `GET /v1/bundles`); `credit_usd` says how much. Needs no key. Keep `recovery_code`: it is shown once, and it is the only way to get the key back if the buyer finishes paying in another browser.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount_usd": {
                    "type": "number",
                    "description": "The price in US dollars, from $1.00 and within the limits from `GET /v1/bundles`. Required unless `bundle` is sent.",
                    "examples": [
                      10
                    ]
                  },
                  "validity_days": {
                    "type": "integer",
                    "description": "Days a new key stays valid, a whole number.",
                    "default": 365,
                    "minimum": 1,
                    "maximum": 3650
                  },
                  "bundle": {
                    "type": "string",
                    "description": "An old preset name, used only when `amount_usd` is missing. Each stands for a fixed dollar amount.",
                    "enum": [
                      "test",
                      "small",
                      "medium",
                      "large",
                      "whale"
                    ]
                  },
                  "target_api_key": {
                    "type": "string",
                    "description": "A key you hold, to add the credit to it rather than get a new key. It must be an active `sk-phantom-` key; a key in a workspace adds the credit to the workspace. Naming it stores a link from this payment to that key. Without it, the purchase makes a new key in a new guest workspace and links the payment to that workspace."
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The payment is created and waiting on Stripe's page.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payment_id": {
                      "type": "string",
                      "description": "The payment id to poll."
                    },
                    "checkout_url": {
                      "type": "string",
                      "description": "A stripe.com link the buyer opens to pay. Today it is on `pm-redirects.stripe.com`, which sends the buyer on to Stripe's crypto page. Read the host from the URL: Stripe picks it, not Phantom."
                    },
                    "recovery_code": {
                      "type": "string",
                      "description": "Shown once. Send it as `x-phantom-recovery-code` on the status poll, or to `POST /v1/purchase/recover`, to get the key."
                    },
                    "amount_cents": {
                      "type": "integer",
                      "description": "What the buyer pays, in US cents: the price rounded up to the next cent."
                    },
                    "credit_usd": {
                      "type": "number",
                      "description": "Credit the key receives: the price plus any bonus."
                    }
                  },
                  "required": [
                    "payment_id",
                    "checkout_url",
                    "recovery_code",
                    "amount_cents",
                    "credit_usd"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "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.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Crypto payments are off right now, or Stripe could not start the payment.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/purchase/x402": {
      "post": {
        "operationId": "postV1PurchaseX402",
        "summary": "Create a quote for Stripe-backed x402 credit",
        "description": "How an agent buys credit: for a new key, for a key it already has (`target_api_key`), or for a workspace. Creates a thirty-minute quote. Save the recovery code, then POST payment_url with pay.sh. Solana USDC goes to the Stripe deposit address. Before quoting, the server checks that address has a USDC token account and creates it with its operator key when missing. Credit is granted only after Stripe confirms the transfer through its signed webhook, so poll `GET /v1/purchase/{id}/status` until it is `completed`. This purchase has the same $0.10 minimum as other crypto purchases; individual API calls still debit actual usage. To top up a key, send it as target_api_key in the body, not in Authorization: pay replaces that header when it pays over MPP. For a workspace purchase, send workspace_id and authorize with its management bearer, guest cookie or owner session.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "amount_usd": {
                    "type": "number",
                    "description": "The price in whole cents, paid in USDC. Credit is the price plus bonus credit from $100 (`bonus_tiers` in `GET /v1/bundles`).",
                    "minimum": 0.1,
                    "maximum": 10000
                  },
                  "validity_days": {
                    "type": "integer",
                    "description": "How long a new key stays valid; a top-up extends the key to at least this.",
                    "default": 365,
                    "minimum": 1,
                    "maximum": 3650
                  },
                  "target_api_key": {
                    "type": "string",
                    "description": "A Phantom key to add the credit to instead of issuing a new one. A key in a workspace adds it to the workspace. Checked before the quote is stored; this links the payment to that key and its workspace. Not with workspace_id."
                  },
                  "workspace_id": {
                    "type": "string",
                    "description": "Optional authorized workspace that receives the credit. Not with target_api_key."
                  }
                },
                "required": [
                  "amount_usd"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Quote and recovery credential; save the credential privately before paying.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payment_id": {
                      "type": "string",
                      "description": "Purchase identifier."
                    },
                    "payment_url": {
                      "type": "string",
                      "description": "POST this URL through pay.sh to satisfy MPP or x402."
                    },
                    "recovery_code": {
                      "type": "string",
                      "description": "Shown once, except for workspace funding. It opens a new key at `GET /v1/purchase/{id}/status` (in `x-phantom-recovery-code`). A top-up of target_api_key needs it only if that key's workspace is deleted before Stripe confirms, when the credit goes to a new key instead; a key rotated or revoked in the meantime still gets the credit in its workspace."
                    },
                    "price_usd": {
                      "type": "number",
                      "description": "What the payment_url charges, in USDC."
                    },
                    "credit_usd": {
                      "type": "number",
                      "description": "Credit purchased: the price plus any bonus."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Quote expiration."
                    }
                  }
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "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.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Workspace authorization required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Quote could not be stored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "description": "Stripe x402 is off, or the deposit address has no USDC token account and the server could not create one. No quote is stored.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/purchase/{id}/status": {
      "get": {
        "operationId": "getV1PurchaseIdStatus",
        "summary": "Poll a purchase and collect its key once paid",
        "description": "Reports where a purchase stands and, once it is paid, hands back the key. For a Solana payment each poll also looks for the transfer on chain (at most every few seconds per server). When a finalized transfer has landed with the reference, exactly the owed amount (Stripe books only an exact amount, so more or less is not counted) and a time inside the quote window plus a short grace, the poll records it with Stripe. The payment stays `pending` until Stripe's signed webhook marks it paid, usually within a minute. A buyer who closes the page early is not stuck: the daily cleanup job and `POST /v1/purchase/recover` look for the transfer too. A card or Stripe crypto payment is marked paid by Stripe's webhook.\n\nA paid purchase that named a key credits that key's workspace and extends the key's expiry to at least the new validity; no key comes back. If the key was rotated or revoked before Stripe confirmed the payment, the credit still lands in its workspace, where the replacement key spends it. Otherwise the new key is sealed with the recovery code, so send `x-phantom-recovery-code` to get it. The first poll with the code creates the key; later polls with the code return the same key. Needs no API key. This route is left out of the purchase rate limit.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The `payment_id` from the purchase call.",
            "schema": {
              "type": "string",
              "description": "The `payment_id` from the purchase call."
            }
          },
          {
            "name": "x-phantom-recovery-code",
            "in": "header",
            "required": false,
            "description": "The recovery code shown at checkout. With it, the status poll decrypts and returns the key of a paid purchase. Sent as a header so it never lands in a URL or access log. Without it, a paid purchase that issues a new key reports `ready` and `recovery_required: true`, and no key. A top-up or a workspace purchase does not need it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The purchase's state.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "description": "`pending` until paid; `confirming` while Stripe waits for a crypto payment's network to confirm it; `ready` when paid but the key was not handed out on this poll; `completed` when this poll returned the key or the top-up landed; `expired` when the daily cleanup job marked a payment still pending after 7 days, or Stripe said a confirming payment failed or was canceled. A payment that succeeds later, such as a Solana transfer that lands late or a second try on Stripe's crypto page, still moves an expired payment to paid.",
                      "enum": [
                        "pending",
                        "confirming",
                        "ready",
                        "completed",
                        "expired"
                      ]
                    },
                    "api_key": {
                      "type": "string",
                      "description": "The new key, when the purchase is paid and the recovery code opened it. Left out otherwise."
                    },
                    "workspace_id": {
                      "type": "string",
                      "description": "The guest workspace the new key sits in, which holds the credit. Only with `api_key`."
                    },
                    "recovery": {
                      "type": "object",
                      "description": "The workspace's recovery file: `version`, `workspace_id` and `management_credential`, which is the recovery code. Restore it with `POST /v1/workspaces/recover`. Only with `api_key`."
                    },
                    "topped_up": {
                      "type": "boolean",
                      "description": "The credit landed in a workspace instead of on a new key: the workspace of the key named at checkout (even if that key was rotated or revoked since), or the workspace the purchase funds. No `api_key` comes back in that case."
                    },
                    "recovery_required": {
                      "type": "boolean",
                      "description": "The purchase needs its recovery code to hand out a new key, and none came back on this poll. True while such a purchase is unpaid too. False when the credit lands in a workspace: a top-up whose named key still exists, or a workspace purchase. A top-up whose key was deleted with its workspace falls back to a new key, so it needs the code."
                    },
                    "credit_usd": {
                      "type": "number",
                      "description": "Credit the purchase adds, in US dollars."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "Once a key exists (the new key, or the key named for a top-up), when that key expires. Before that, when the unpaid quote expires.",
                      "format": "date-time"
                    },
                    "pay_currency": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "For a crypto payment to an address, the coin: `usdcsol` (USDC on Solana) or `usdc-base`. A payment from before SOL and USDT were retired can still read `sol` or `usdtsol`. `null` for a card payment or one on Stripe's crypto page."
                    },
                    "pay_amount": {
                      "type": [
                        "string",
                        "null"
                      ],
                      "description": "For a Solana payment, the exact amount owed in whole coins. `null` for a card payment."
                    }
                  },
                  "required": [
                    "status",
                    "topped_up",
                    "recovery_required",
                    "credit_usd",
                    "expires_at",
                    "pay_currency",
                    "pay_amount"
                  ]
                },
                "example": {
                  "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
                }
              }
            }
          },
          "400": {
            "description": "No payment id in the path.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "404": {
            "description": "No payment has that id.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                },
                "example": {
                  "error": "Payment not found"
                }
              }
            }
          }
        }
      }
    },
    "/v1/purchase/{id}/transaction": {
      "get": {
        "operationId": "getV1PurchaseIdTransaction",
        "summary": "Read the label a wallet shows for the payment",
        "description": "The first half of a Solana Pay transaction request: the name and icon a wallet app shows before it asks for the transaction. Needs no key.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The `payment_id` of a Solana payment.",
            "schema": {
              "type": "string",
              "description": "The `payment_id` of a Solana payment."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The label and icon.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "label": {
                      "type": "string",
                      "description": "Always `Phantom AI`.",
                      "enum": [
                        "Phantom AI"
                      ]
                    },
                    "icon": {
                      "type": "string",
                      "description": "The logo URL.",
                      "format": "uri"
                    }
                  },
                  "required": [
                    "label",
                    "icon"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postV1PurchaseIdTransaction",
        "summary": "Create the payment transaction",
        "description": "The second half of a Solana Pay transaction request. Returns the unsigned transfer for the given wallet to sign and send: the exact USDC amount to Stripe's deposit address, with the reference attached, and the address's USDC token account created when it has none. The paying wallet pays the network fee. Refuses a payment that cannot succeed before anything is signed. Needs no key.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The `payment_id` of a Solana payment.",
            "schema": {
              "type": "string",
              "description": "The `payment_id` of a Solana payment."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "account": {
                    "type": "string",
                    "description": "The paying wallet's Solana address."
                  }
                },
                "required": [
                  "account"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The transaction to sign.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "transaction": {
                      "type": "string",
                      "description": "The unsigned transaction, base64."
                    },
                    "message": {
                      "type": "string",
                      "description": "A line for the wallet to show, such as `Pay 20 USDC for Phantom AI credit`."
                    }
                  },
                  "required": [
                    "transaction",
                    "message"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "The body is not a JSON object, `account` is not a Solana address, `account` is the receiving address, the payment is not a Solana payment or has no amount, or it was quoted in SOL or USDT, which are no longer taken.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "402": {
            "description": "The wallet holds less USDC than the payment, or too little SOL for the network fee.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "404": {
            "description": "No payment has that id.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "409": {
            "description": "The payment is already paid.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "410": {
            "description": "The quote expired. Start a new payment.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "USDC on Solana is off right now, or Solana could not be reached.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "detail": {
                      "type": "string",
                      "description": "What went wrong, in words to show the buyer."
                    }
                  },
                  "required": [
                    "detail"
                  ]
                }
              }
            }
          }
        }
      }
    },
    "/v1/purchase/{id}/x402": {
      "post": {
        "operationId": "postV1PurchaseIdX402",
        "summary": "Pay a quote with Solana MPP or x402 into Stripe",
        "description": "POST the quoted payment URL through pay.sh. An unpaid request returns an fixed USDC MPP charge and x402 exact challenges. The verified transfer is recorded durably, then submitted to Stripe using transaction_verification. Processing is not fulfillment: use the existing purchase status endpoint and recovery header, or your workspace status, until the signed Stripe webhook grants credit. A lost response can be recovered without making another payment.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Identifier from the x402 purchase quote.",
            "schema": {
              "type": "string",
              "description": "Identifier from the x402 purchase quote."
            }
          },
          {
            "name": "payment-signature",
            "in": "header",
            "required": false,
            "description": "Signed x402 payment authorization supplied by a compatible payment client. Signed x402 exact credential.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Payment received; credit may still be pending Stripe verification.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "payment_id": {
                      "type": "string",
                      "description": "Purchase identifier."
                    },
                    "status": {
                      "type": "string",
                      "description": "Current purchase state."
                    },
                    "payment_received": {
                      "type": "boolean",
                      "description": "An on-chain transfer is recorded; do not pay again."
                    }
                  }
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              },
              "payment-response": {
                "description": "Settlement receipt for an x402 payment.",
                "schema": {
                  "type": "string"
                }
              },
              "payment-receipt": {
                "description": "Settlement receipt for an MPP payment.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Malformed settlement.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "402": {
            "description": "Pay this challenge using a compatible Solana MPP or x402 client.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              },
              "www-authenticate": {
                "description": "Solana MPP charge challenge.",
                "schema": {
                  "type": "string"
                }
              },
              "payment-required": {
                "description": "Base64 x402 exact challenge.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "404": {
            "description": "Quote not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "409": {
            "description": "Expired quote or conflicting transfer.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Unavailable, the deposit address cannot receive USDC (no challenge is sent), or verification pending; poll the purchase before paying again.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/receipts/anchor": {
      "get": {
        "operationId": "getV1ReceiptsAnchor",
        "summary": "Look up whether a receipt is anchored on Solana",
        "description": "Whether a receipt's hash was written to Solana, and where. Public: anyone shown a receipt can check it without a key.",
        "tags": [
          "Receipts"
        ],
        "security": [],
        "parameters": [
          {
            "name": "leaf",
            "in": "query",
            "required": true,
            "description": "SHA-256 of the compact receipt, 64 hex characters. Case does not matter.",
            "schema": {
              "type": "string",
              "description": "SHA-256 of the compact receipt, 64 hex characters. Case does not matter."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The anchor, or `anchored: false` with the hash and network when there is none.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "anchored": {
                      "type": "boolean",
                      "description": "The hash is on chain."
                    },
                    "anchor": {
                      "type": "object",
                      "description": "The anchor record. Present when `anchored` is `true`.",
                      "properties": {
                        "leaf_hash": {
                          "type": "string",
                          "description": "SHA-256 hex of the compact receipt, exactly as held."
                        },
                        "tx_signature": {
                          "type": "string",
                          "description": "The Solana transaction that carries the hash in a memo."
                        },
                        "slot": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "description": "The Solana slot the transaction landed in, when known."
                        },
                        "cluster": {
                          "type": "string",
                          "description": "The Solana network: `devnet`, `testnet` or `mainnet-beta`."
                        },
                        "created_at": {
                          "type": "string",
                          "description": "When Phantom recorded the anchor.",
                          "format": "date-time"
                        },
                        "explorer_url": {
                          "type": "string",
                          "description": "The transaction on Solana Explorer, for the network this deployment uses.",
                          "format": "uri"
                        }
                      },
                      "required": [
                        "leaf_hash",
                        "tx_signature",
                        "slot",
                        "cluster",
                        "created_at",
                        "explorer_url"
                      ]
                    },
                    "leaf_hash": {
                      "type": "string",
                      "description": "The hash asked about, lowercased. Present when `anchored` is `false`."
                    },
                    "cluster": {
                      "type": "string",
                      "description": "The network this deployment anchors to. Present when `anchored` is `false`."
                    }
                  },
                  "required": [
                    "anchored"
                  ]
                }
              }
            }
          },
          "400": {
            "description": "`leaf` is missing or not 64 hex characters.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postV1ReceiptsAnchor",
        "summary": "Write a receipt's hash to Solana for $0.01",
        "description": "Writes the SHA-256 of a receipt to Solana in a memo transaction, so anyone can later see it existed at that time. Phantom first checks the receipt against its own signing key and refuses one it did not sign, before reading your key. The charge is $0.01, taken after the transaction confirms; a transaction that does not land costs nothing. A receipt anchored before is answered from the record at no charge, though the key must still be able to pay the fee to get that far.",
        "tags": [
          "Receipts"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "receipt": {
                    "type": "string",
                    "description": "The `x-phantom-receipt` value, as received."
                  }
                },
                "required": [
                  "receipt"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The receipt is anchored, now or earlier.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "anchored": {
                      "type": "boolean",
                      "description": "Always `true`.",
                      "enum": [
                        true
                      ]
                    },
                    "already_anchored": {
                      "type": "boolean",
                      "description": "`true` when an earlier call anchored this receipt; nothing was charged."
                    },
                    "anchor": {
                      "type": "object",
                      "description": "The anchor record.",
                      "properties": {
                        "leaf_hash": {
                          "type": "string",
                          "description": "SHA-256 hex of the compact receipt, exactly as held."
                        },
                        "tx_signature": {
                          "type": "string",
                          "description": "The Solana transaction that carries the hash in a memo."
                        },
                        "slot": {
                          "type": [
                            "integer",
                            "null"
                          ],
                          "description": "The Solana slot the transaction landed in, when known."
                        },
                        "cluster": {
                          "type": "string",
                          "description": "The Solana network: `devnet`, `testnet` or `mainnet-beta`."
                        },
                        "created_at": {
                          "type": "string",
                          "description": "When Phantom recorded the anchor.",
                          "format": "date-time"
                        },
                        "explorer_url": {
                          "type": "string",
                          "description": "The transaction on Solana Explorer, for the network this deployment uses.",
                          "format": "uri"
                        }
                      },
                      "required": [
                        "leaf_hash",
                        "tx_signature",
                        "slot",
                        "cluster",
                        "created_at",
                        "explorer_url"
                      ]
                    }
                  },
                  "required": [
                    "anchored",
                    "already_anchored",
                    "anchor"
                  ]
                }
              }
            },
            "headers": {
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars. The anchoring fee. Not sent for a repeat anchor.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. Not sent for a repeat anchor.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Bad JSON, no `receipt`, or a receipt that does not verify against this deployment's signing key.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "No `Bearer` key in `Authorization`, or a key Phantom does not know (`Key cannot be charged: not_found.`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "402": {
            "description": "The key cannot pay the fee: `inactive`, `expired`, `insufficient_balance`, `budget_exceeded` or `spend_rate_exceeded`, as `Key cannot be charged: <reason>.`",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "502": {
            "description": "The Solana transaction did not land. Nothing was charged.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "This deployment has no Solana signer configured for anchoring.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/receipts/key": {
      "get": {
        "operationId": "getV1ReceiptsKey",
        "summary": "Read the public key that signs receipts",
        "description": "The public half of the key that signs `x-phantom-receipt`, as JWK and PEM. Public, so anyone shown a receipt can check it without a Phantom key. A deployment with no signing key answers `signs: false` and sends no receipts.",
        "tags": [
          "Receipts"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The key, or `signs: false` with `detail` when the deployment signs nothing.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "signs": {
                      "type": "boolean",
                      "description": "Whether this deployment signs receipts."
                    },
                    "detail": {
                      "type": "string",
                      "description": "Why there is no key. Present only when `signs` is `false`."
                    },
                    "algorithm": {
                      "type": "string",
                      "description": "Always `Ed25519`. Present when `signs` is `true`, as are the fields below.",
                      "enum": [
                        "Ed25519"
                      ]
                    },
                    "receipt_version": {
                      "type": "integer",
                      "description": "The receipt format version, the `v` field in each receipt. Receipts of another version do not verify."
                    },
                    "header": {
                      "type": "string",
                      "description": "The response header that carries receipts.",
                      "enum": [
                        "x-phantom-receipt"
                      ]
                    },
                    "format": {
                      "type": "string",
                      "description": "How a receipt is laid out: `base64url(canonical JSON payload).base64url(signature)`."
                    },
                    "public_key_jwk": {
                      "type": "object",
                      "description": "The public key as a JSON Web Key (`kty: \"OKP\"`, `crv: \"Ed25519\"`).",
                      "additionalProperties": true
                    },
                    "public_key_pem": {
                      "type": "string",
                      "description": "The public key as PEM text."
                    }
                  },
                  "required": [
                    "signs"
                  ]
                },
                "example": {
                  "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"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=300, stale-while-revalidate=3600`: the CDN keeps the answer for 5 minutes.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/rerank": {
      "post": {
        "operationId": "postV1Rerank",
        "summary": "Rerank documents by relevance to a query",
        "description": "Scores each document against a query. Phantom estimates the input from the query and the documents (about four characters per token), holds that cost on the key, and sends the request to the upstream's rerank endpoint. It bills the `usage.cost` the upstream reports when there is one, otherwise the estimate. A failed call bills nothing and returns the hold.\n\nWhen the upstream refuses the request with a 4xx status, that status comes back unchanged in an OpenAI error with code `upstream_unavailable`.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "query": {
                    "type": "string",
                    "description": "The text to score the documents against. Must be a non-empty string.",
                    "examples": [
                      "What is the capital of France?"
                    ]
                  },
                  "documents": {
                    "type": "array",
                    "description": "The documents to score. Must be a non-empty array. Items that are not strings count as their JSON text for the estimate. Sent to the upstream unchanged.",
                    "examples": [
                      [
                        "Paris is the capital of France.",
                        "Berlin is in Germany."
                      ]
                    ],
                    "items": {
                      "type": "string",
                      "description": "One document."
                    }
                  },
                  "router": {
                    "type": "string",
                    "description": "A router's name in place of `model`. Here it runs the model that router names for this endpoint, as `model: \"phantom-1\"` does. Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "`phantom-1` runs `voyage/rerank-3`. A reranking model id from `GET /v1/models`. Aliases resolve to the catalog id.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "top_n": {
                    "type": "integer",
                    "description": "Return only the best `top_n` results. Sent to the upstream only when set and not zero."
                  }
                },
                "required": [
                  "query",
                  "documents"
                ]
              },
              "example": {
                "model": "phantom-1",
                "query": "What is the capital of France?",
                "documents": [
                  "Paris is the capital of France.",
                  "Berlin is in Germany."
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upstream's rerank response, passed through unchanged.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "model": {
                      "type": "string",
                      "description": "The model that scored the documents, when the upstream reports it."
                    },
                    "results": {
                      "type": "array",
                      "description": "Scored documents, as the upstream returns them.",
                      "items": {
                        "type": "object",
                        "description": "One scored document.",
                        "additionalProperties": true
                      }
                    },
                    "usage": {
                      "type": "object",
                      "description": "Usage as the upstream reports it. `cost` in US dollars, when present, is what Phantom bills.",
                      "additionalProperties": true
                    }
                  }
                },
                "example": {
                  "model": "voyage/rerank-3",
                  "results": [
                    {
                      "index": 0,
                      "relevance_score": 0.9
                    }
                  ]
                }
              }
            },
            "headers": {
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. On this route `model_served` is the `model` field of the upstream's response when it has one, `prompt_tokens` is Phantom's estimate, and `upstream_request_id` is `null`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The body is not JSON, `query` is missing or empty, or `documents` is missing or empty. Also a 400 from the upstream, passed through. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "No key (`missing_api_key`), or a key that does not start with `sk-` (`invalid_api_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the estimate (`insufficient_balance`). Also sent when the hold could not be placed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "Insufficient balance or inactive API key",
                    "type": "insufficient_quota",
                    "code": "insufficient_balance"
                  }
                }
              }
            }
          },
          "404": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "The upstream answered with a 5xx status, or the call failed (`upstream_unavailable`). Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "Phantom has no upstream key configured (`upstream_unavailable`). Also sent when the upstream refuses Phantom's own account (its credit or budget is used up, or its key is rejected), or when Phantom can't load its model list. Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/responses": {
      "post": {
        "operationId": "postV1Responses",
        "summary": "Create a response (Responses API)",
        "description": "OpenAI's Responses API, streaming or not, so Codex CLI and the OpenAI SDK's `responses.create` work on a Phantom key. Any chat model in the catalog works, `auto` included.\n\nBilling and routing match `POST /v1/chat/completions`: Phantom runs the key's route policy, estimates the prompt (instructions, input and tools), holds the worst-case cost, sets `max_output_tokens` to what the hold covers, calls the upstream's `/v1/responses`, and bills the cost the upstream reports, or the catalog rate for the reported tokens. A refused or failed call bills nothing. A stream bills when it ends, including when you hang up early.\n\nPhantom keeps no conversation: `store` is always sent as `false`, and `previous_response_id` is refused. Send the whole conversation in `input`, as Codex does.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "x-phantom-session",
            "in": "header",
            "required": false,
            "description": "Your own conversation id. phantom-1 keeps a conversation's routing state under it: paid chat starts each task on standard and can move it to frontier on any request, tool calls included. Anthropic messages containing only `tool_result` blocks continue the same user message. Other routing (`auto` with a key policy) can keep one model for the session while `stick_minutes` lasts. Only the first 200 characters count. Without this header, Phantom uses Claude Code's `x-claude-code-session-id` when it arrives, and otherwise groups requests by prompt or conversation opening, depending on the route. Phantom stores a salted hash with the selected model and expiry, and keeps provider affinity for the session so its prompt cache stays warm.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-session-id",
            "in": "header",
            "required": false,
            "description": "Claude Code's own session id, which it sends on every request. When `x-phantom-session` is missing, Phantom uses this the same way: the first 200 characters, hashed under the key.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-claude-code-agent-id",
            "in": "header",
            "required": false,
            "description": "Sent by Claude Code from its helper agents (such as Explore), never from the main agent. phantom-1 runs a helper's request on Standard. Phantom reads only whether the header has a value.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-subagent",
            "in": "header",
            "required": false,
            "description": "Codex's helper kind. phantom-1 runs `collab_spawn`, `thread_spawn` and `review` on Standard; other kinds, such as `compact`, route as usual.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-turn-metadata",
            "in": "header",
            "required": false,
            "description": "Codex's turn metadata, as JSON. phantom-1 reads only `subagent_kind`, `thread_source` and `parent_thread_id`, to tell a helper's request apart as with `x-openai-subagent`.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-codex-parent-thread-id",
            "in": "header",
            "required": false,
            "description": "The Codex thread a helper thread started from. With `thread_source` set to `subagent` in `x-codex-turn-metadata`, it marks a helper's request.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-agent",
            "in": "header",
            "required": false,
            "description": "The coding agent a request came through: `claude-code`, `codex`, `cursor`, `gemini-cli` or `coding-agent`. Phantom sets it when you call an agent's base path (`https://phantom.codes/codex/v1`). Any other value is ignored.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-route",
            "in": "header",
            "required": false,
            "description": "Send `off` to skip the key's route policy for this request. The request runs on the model it names; `model: \"auto\"` is refused with a 400.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-escalate",
            "in": "header",
            "required": false,
            "description": "Send `1` when the current model isn't managing the task. phantom-1 moves this request one tier up, from standard to frontier. It picks again on the next request, so send the header on each request that should stay up, tool calls included. A key's route policy moves it to the policy's last model. Phantom can't tell a weak answer from a good one, so escalation is your call.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-phantom-free",
            "in": "header",
            "required": false,
            "description": "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. A key with credit never runs a free model on phantom-1, so there the header changes nothing.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-openai-api-key",
            "in": "header",
            "required": false,
            "description": "Your own OpenAI API key. On a call an OpenAI model serves, it is tried first, and a call it served costs nothing on Phantom: OpenAI bills you. If OpenAI refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-anthropic-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Anthropic API key. On a call an Anthropic model serves, it is tried first, and a call it served costs nothing on Phantom: Anthropic bills you. If Anthropic refuses it, the call runs on Phantom's keys and bills as usual, and so does a call Phantom can't confirm your key served. The usual hold still applies while the call runs. Phantom never stores, logs or returns the key. Other models, and `phantom-1:free`, ignore it.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "x-gateway-api-key",
            "in": "header",
            "required": false,
            "description": "Your own Vercel AI Gateway API key. The call runs on it in place of Phantom's key, so your Gateway account pays for it and Phantom charges $0: nothing is held, and a key with no credit runs `phantom-1` on paid models rather than as `phantom-1:free`. The key's budget and spend-rate cap still apply. If the Gateway refuses the key you get a `401` (`invalid_gateway_key`), or a `402` (`gateway_key_no_credit`) when its account is out of credit; the call never falls back to Phantom's key. Provider keys sent with it run inside your Gateway account. Phantom never stores, logs or returns the key. `phantom-1:free` ignores it.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "description": "A Responses API request. Fields not listed go to the upstream unchanged.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "router": {
                    "type": "string",
                    "description": "The router to pick the model: `phantom-1`, `phantom-1:free` or `phantom-1:private` (see `GET /v1/routers`). Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`. Phantom removes it before calling the upstream.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "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). `phantom-1` with an image routes like any request, on a tier whose model can read images. `phantom-1:free` runs only free models, at $0, and needs no credit. `phantom-1:private` routes between models with zero data retention and no training on every provider, and requires both on every call. The retired `phantom-1:zdr` answers 400 `router_retired`.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "input": {
                    "type": "string",
                    "description": "The prompt, or an array of input items (messages, function call outputs). Counts toward the prompt estimate.",
                    "examples": [
                      "Write a haiku about receipts."
                    ]
                  },
                  "instructions": {
                    "type": "string",
                    "description": "The system prompt. Counts toward the prompt estimate."
                  },
                  "tools": {
                    "type": "array",
                    "description": "Tool definitions. Count toward the prompt estimate. Phantom forwards function and custom tools, `namespace`, `local_shell`, `apply_patch`, a `shell` with `environment.type: \"local\"`, `tool_search*`, `mcp`, `mcp_toolset`, `bash_*`, `text_editor_*`, `computer_*`, `memory_*`, and the search and fetch tools below. It drops every other tool type without an error, including any it does not know, because a server tool can bill per call. A `web_search*` tool adds the model's price per search, or $0.01 when the upstream lists none, times its `max_uses` to the hold, so a key needs that much more balance. Phantom sets `max_uses` to 5 when you send none and lowers it to 10 when you send more. A `web_fetch*` tool gets `max_uses` the same way and a `max_content_tokens` of at most 20,000, and the hold adds those tokens at the model's input rate. OpenAI's `web_search`, `web_search_preview` and their dated variants have no `max_uses`: on `/v1/responses` Phantom sets `max_tool_calls` to the same count, and on the other routes it drops them. On `phantom-1:free`, and on `phantom-1` from a key with no credit, Phantom drops every `web_search*` tool: each search costs money even on a free model.",
                    "items": {
                      "type": "object",
                      "description": "A tool.",
                      "additionalProperties": true
                    }
                  },
                  "stream": {
                    "type": "boolean",
                    "description": "Answer as a server-sent event stream.",
                    "default": false
                  },
                  "max_output_tokens": {
                    "type": "integer",
                    "description": "Your output limit. Phantom replaces it with the smallest of this, what the balance buys, and the model's output cap, then shrinks it to what the hold covers."
                  },
                  "store": {
                    "type": "boolean",
                    "description": "Always sent as `false`. Phantom keeps no conversation."
                  },
                  "previous_response_id": {
                    "type": "string",
                    "description": "Refused with 400. Send the whole conversation in `input`."
                  },
                  "sort": {
                    "type": "string",
                    "description": "How to rank the providers that serve the model: `cost` (the default), `ttft` (fastest first token) or `tps` (most tokens per second). Removed before calling the upstream.",
                    "enum": [
                      "cost",
                      "ttft",
                      "tps"
                    ]
                  },
                  "zdr": {
                    "type": "boolean",
                    "description": "Only use providers that delete prompts right away. Off by default. Overrides the key's route policy. With it on, phantom-1 skips its free model. Removed before calling the upstream."
                  },
                  "no_training": {
                    "type": "boolean",
                    "description": "Only use providers that don't train on prompts. Removed before calling the upstream."
                  },
                  "providerOptions": {
                    "type": "object",
                    "description": "Passed to the upstream, except `gateway.models`, which is dropped. Phantom always sets `gateway.caching: \"auto\"`, and `gateway.sort: \"cost\"` unless you choose a sort. Phantom also drops `serviceTier`, `speed` and `sharedRequestType` from `gateway` and from the options of every provider (`openai`, `google`, `vertex`, `xai`, `anthropic`), and a top-level `service_tier` or `speed`, so a call runs at the standard tier. It also drops `inferenceRegion` (a pinned region costs more), `inference_geo` and `cache_ttl`, and the `ttl` of any `cache_control` or `cacheControl` (a one-hour cache costs 2x input to write, against the 1.25x Phantom bills), so a call uses the upstream's own region choice and the five-minute cache.",
                    "additionalProperties": true
                  }
                },
                "required": [
                  "input"
                ],
                "additionalProperties": true
              },
              "example": {
                "model": "phantom-1",
                "input": "Write a haiku about receipts."
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "The upstream's response, passed through, plus `phantom`. Other statuses from the upstream also come back as the upstream sent them; nothing is billed then.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The response id."
                    },
                    "status": {
                      "type": "string",
                      "description": "The upstream's state for the response, such as `completed`."
                    },
                    "object": {
                      "type": "string",
                      "description": "`response`."
                    },
                    "model": {
                      "type": "string",
                      "description": "The model the upstream reports running."
                    },
                    "output": {
                      "type": "array",
                      "description": "Output items: messages, reasoning, function calls.",
                      "items": {
                        "type": "object",
                        "description": "An output item.",
                        "additionalProperties": true
                      }
                    },
                    "usage": {
                      "type": "object",
                      "description": "Token counts Phantom bills from. When they are missing, Phantom estimates them.",
                      "properties": {
                        "input_tokens": {
                          "type": "integer",
                          "description": "Input tokens."
                        },
                        "output_tokens": {
                          "type": "integer",
                          "description": "Output tokens, reasoning included."
                        }
                      },
                      "additionalProperties": true
                    },
                    "phantom": {
                      "type": "object",
                      "description": "Added by Phantom: what this call cost and how it was served.",
                      "properties": {
                        "cost_usd": {
                          "type": "number",
                          "description": "What this call was charged, in US dollars."
                        },
                        "provider": {
                          "type": [
                            "string",
                            "null"
                          ],
                          "description": "The provider that answered, or null when the upstream did not say."
                        },
                        "attempts": {
                          "type": "integer",
                          "description": "Provider attempts across every model tried."
                        },
                        "fallback": {
                          "type": "boolean",
                          "description": "`true` when a provider or model failed and another one answered."
                        }
                      }
                    }
                  }
                },
                "example": {
                  "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
                  }
                }
              },
              "text/event-stream": {
                "schema": {
                  "type": "string",
                  "description": "With `stream: true`: the upstream's Responses events, passed through. Right before the chunk that holds the terminal event (`response.completed`, `response.incomplete` or `response.failed`), Phantom inserts `event: phantom.receipt` with `data: {\"type\":\"phantom.receipt\",\"receipt\":\"<compact receipt>\",\"phantom\":{...}}`. Without a signing key the event carries `phantom` only. Clients that don't know the event ignore it."
                }
              }
            },
            "headers": {
              "x-phantom-request-id": {
                "description": "Phantom's id for this request (`req_` + 24 hex characters). The same value is `request_id` in the receipt. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-router": {
                "description": "The router that picked the model: `phantom-1`, `phantom-1:free` or `phantom-1:private`. Sent when the request named a router in `router` or `model`, or sent `model: \"auto\"` on a key with no route policy. The body's `model` names the model that ran. Also sent with a passed-through upstream error. The body adds `router` with the same name, and in a stream the `phantom.receipt` event carries it.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-routed": {
                "description": "Present only when the key's route policy picked the model: the model id, then `; reason=` and what decided it. A rule shows as `<condition>:<value>`; other reasons are `default` (the policy's first model), `requested`, `cache` (kept on the conversation's model) and `on_empty` (past the budget, the cheapest model). A `phantom-1` call never sends it; see `x-phantom-route-receipt`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-receipt": {
                "description": "Sent on routed `phantom-1` calls: the model you asked for, the tier and model that ran, how sure phantom-1 was when the pick gives a confidence, and a short reason label. Reason labels may change. Sent on routed phantom-1 calls: names requested model, served tier, underlying model, confidence when the pick gives one, and reason.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-route-scores": {
                "description": "phantom-1's score for each model and the one it picked. Sent only when you ask with `x-phantom-route-debug: 1` or `router_debug: true`. For debugging only; the format may change. Sent when debug mode is requested: returns phantom-1's score for each model and the one it picked.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-model": {
                "description": "The model id Phantom sent to the upstream. On chat and messages, the receipt's `model_served` holds the id the upstream reported running. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream-request-id": {
                "description": "The upstream's own request id, copied from its `x-request-id` response header when it sends one. Also sent with a passed-through upstream error.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. Non-streaming answers only. A stream carries the receipt in the body instead.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cached-tokens": {
                "description": "Prompt tokens the upstream served from its cache, billed at the cached rate. Non-streaming answers only: `usage.input_tokens_details.cached_tokens`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars. Non-streaming answers only. A stream carries it in the `phantom.receipt` event.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-provider": {
                "description": "The provider that answered, such as `anthropic`, `bedrock` or `azure`. Left out when the upstream does not say. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-fallback": {
                "description": "`true` when a provider or model failed and another one answered the call, `false` when the first try worked. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. Non-streaming answers only.",
                "schema": {
                  "type": "string"
                }
              },
              "cache-control": {
                "description": "Caching rules for the response. Streams only: `no-cache`.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "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. `phantom-1:free` answers `free_model_unfit` when no free model can take the request (images, tools, long context). `phantom-1:private` answers `private_model_unfit` when none of its zero-data-retention models can take the request. With `zdr` on, `zdr_unavailable` means no provider of the model has zero data retention; nothing ran and nothing is billed. A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "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. A call can't pay for itself with x402 or MPP. Or the Vercel AI Gateway refused the key in `x-gateway-api-key` (`invalid_gateway_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "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). Then: the key is past its spend cap, cannot pay for the prompt, cannot buy 32 output tokens after it, or the hold failed. Or the Vercel AI Gateway account behind `x-gateway-api-key` is out of credit or past its budget (`gateway_key_no_credit`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "Not enough credit ($0.0000 left). Top up at https://phantom.codes/checkout.",
                    "type": "insufficient_quota",
                    "code": "insufficient_quota"
                  }
                }
              }
            }
          },
          "404": {
            "description": "The model is not a chat model in the catalog, or it was retired.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached. On free models (`phantom-1:free`, and `phantom-1` or `auto` from a key with no credit), counted per workspace: 20 requests a minute (`free_rate_exceeded`) or the daily cap (`free_daily_cap`): 50 a day, 200 a day through a coding agent base path (such as `/codex/v1`), or 1,000 a day once the workspace has taken in $10 of credit. The message says how to raise the cap.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "Phantom has no upstream key configured, or the upstream could not be reached. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "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`). Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the key's per-minute spend cap or a `phantom-1:free` cap is reached: seconds until the minute frees up, or until midnight UTC for the daily cap.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/routers": {
      "get": {
        "operationId": "getV1Routers",
        "summary": "List the phantom-1 tiers and their models",
        "description": "Phantom's routers. A router picks a model per request. Send its id as `router`, or as `model` in SDKs that require `model`. Each entry lists the models the router picks between, with the prices `GET /v1/models` shows. Needs no key.",
        "tags": [
          "Inference"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "The routers. A model the upstream doesn't list right now is left out of `models`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "object": {
                      "type": "string",
                      "description": "Always `list`.",
                      "enum": [
                        "list"
                      ]
                    },
                    "data": {
                      "type": "array",
                      "description": "One entry per router.",
                      "items": {
                        "type": "object",
                        "description": "A router.",
                        "properties": {
                          "id": {
                            "type": "string",
                            "description": "The id to send as `router`.",
                            "enum": [
                              "phantom-1",
                              "phantom-1:free",
                              "phantom-1:private"
                            ],
                            "examples": [
                              "phantom-1"
                            ]
                          },
                          "object": {
                            "type": "string",
                            "description": "Always `router`.",
                            "enum": [
                              "router"
                            ]
                          },
                          "name": {
                            "type": "string",
                            "description": "Display name."
                          },
                          "description": {
                            "type": "string",
                            "description": "What the router picks from and its limits."
                          },
                          "jobs": {
                            "type": "object",
                            "description": "The model the router's name runs on each other endpoint, by job: `vision` (chat with images, which starts on the standard model like any chat), `embedding`, `rerank`, `image`, `video`, `speech`, `transcription`. When the upstream drops a job's model, or it passes its retirement date, this names the backup that now runs it. A job left out is one the router doesn't serve with a fixed model: `phantom-1:private` routes chat with images between its `models`. `GET /v1/models` has their prices.",
                            "additionalProperties": true
                          },
                          "models": {
                            "type": "array",
                            "description": "The models the router picks between for text chat, cheapest tier first.",
                            "items": {
                              "type": "object",
                              "description": "A model the router can pick.",
                              "properties": {
                                "id": {
                                  "type": "string",
                                  "description": "The model id."
                                },
                                "tier": {
                                  "type": "string",
                                  "description": "The tier label of the model: `standard` or `frontier` for phantom-1 and phantom-1:private, `free` for every model phantom-1:free picks.",
                                  "enum": [
                                    "free",
                                    "standard",
                                    "frontier"
                                  ]
                                },
                                "pricing": {
                                  "type": "object",
                                  "description": "US dollars per token, with Phantom's markup.",
                                  "properties": {
                                    "prompt": {
                                      "type": "number",
                                      "description": "Per input token."
                                    },
                                    "completion": {
                                      "type": "number",
                                      "description": "Per output token."
                                    }
                                  },
                                  "required": [
                                    "prompt",
                                    "completion"
                                  ]
                                }
                              },
                              "required": [
                                "id",
                                "tier",
                                "pricing"
                              ]
                            }
                          }
                        },
                        "required": [
                          "id",
                          "object",
                          "name",
                          "description",
                          "jobs",
                          "models"
                        ]
                      }
                    }
                  },
                  "required": [
                    "object",
                    "data"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. `public, s-maxage=300, stale-while-revalidate=3600`: the CDN keeps the answer for 5 minutes.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/video/generations": {
      "post": {
        "operationId": "postV1VideoGenerations",
        "summary": "Start a video generation job, paid up front",
        "description": "Starts a video job and answers `202` with a job id to poll at `GET /v1/video/generations/{id}`. Phantom prices the video at the model's highest per-second rate, holds that cost, starts the job at the upstream, and debits the key as soon as the upstream accepts it, since the upstream charges from then on. A job that later fails is refunded by the poll. If the job starts but Phantom cannot save it, the charge is refunded here and the answer is `502`.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "prompt": {
                    "type": "string",
                    "description": "What the video shows. Must be a non-empty string. Sent to the upstream.",
                    "examples": [
                      "A paper boat drifting down a rainy street"
                    ]
                  },
                  "router": {
                    "type": "string",
                    "description": "A router's name in place of `model`. Here it runs the model that router names for this endpoint, as `model: \"phantom-1\"` does. Leave `model` out, or set it to the same router; any other `model` is a 400 `router_model_conflict`.",
                    "enum": [
                      "phantom-1",
                      "phantom-1:free",
                      "phantom-1:private"
                    ]
                  },
                  "model": {
                    "type": "string",
                    "description": "`phantom-1` runs `alibaba/wan-v2.7-t2v`. A video model id from `GET /v1/models`. Aliases resolve to the catalog id.",
                    "default": "phantom-1",
                    "examples": [
                      "phantom-1"
                    ]
                  },
                  "seconds": {
                    "type": "integer",
                    "description": "Length in whole seconds. Each model makes only some lengths: `video_seconds` in `GET /v1/models` lists them (2 to 15 for `alibaba/wan-v2.7-t2v`, 5 or 10 for the Kling v2.5 and v2.6 models, 4, 6 or 8 for Veo). Any other value is a 400 `invalid_seconds` before anything is held or charged. A model that lists no lengths takes 1 to 60. Left out, it is 5, or the first length above 5 the model makes.",
                    "default": 5,
                    "minimum": 1,
                    "maximum": 60
                  },
                  "duration": {
                    "type": "number",
                    "description": "Same as `seconds`, read only when `seconds` is absent."
                  },
                  "resolution": {
                    "type": "string",
                    "description": "Saved with the job and nothing more. It is not sent upstream and does not change the price."
                  },
                  "size": {
                    "type": "string",
                    "description": "Same as `resolution`, read only when `resolution` is absent."
                  },
                  "aspect_ratio": {
                    "type": "string",
                    "description": "Width to height, such as `16:9`. Sent to the upstream when set.",
                    "examples": [
                      "16:9"
                    ]
                  },
                  "generate_audio": {
                    "type": "boolean",
                    "description": "Ask the model for a soundtrack. Sent to the upstream when set."
                  }
                },
                "required": [
                  "prompt"
                ]
              },
              "example": {
                "model": "phantom-1",
                "prompt": "A paper boat drifting down a rainy street"
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "The job started and the key was charged. No receipt yet; the poll that finds the video done returns it.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The job id: `vid_` and 24 hex characters."
                    },
                    "object": {
                      "type": "string",
                      "description": "Always `video.generation`.",
                      "enum": [
                        "video.generation"
                      ]
                    },
                    "status": {
                      "type": "string",
                      "description": "Always `queued` here.",
                      "enum": [
                        "queued"
                      ]
                    },
                    "model": {
                      "type": "string",
                      "description": "The catalog model id the job runs on."
                    },
                    "seconds": {
                      "type": "integer",
                      "description": "The length in seconds."
                    },
                    "cost_usd": {
                      "type": "number",
                      "description": "What the job costs, in US dollars."
                    },
                    "poll_url": {
                      "type": "string",
                      "description": "Where to poll: `/v1/video/generations/{id}`."
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "status",
                    "model",
                    "seconds",
                    "cost_usd",
                    "poll_url"
                  ]
                },
                "example": {
                  "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"
                }
              }
            },
            "headers": {
              "x-phantom-cost-usd": {
                "description": "What this call was charged, in US dollars.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. On a `502`, sent only when the charge was refunded because the job could not be saved.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Always `pai`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-content-logged": {
                "description": "`false` on every call that reached a model: an answer, or an upstream error passed through. It says Phantom did not store the prompt or the output of this call. A refusal that comes before the call reaches a model (a bad key, a bad body, no credit, a spend cap) does not send it.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "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). A `router` that is not one of `phantom-1`, `phantom-1:free` or `phantom-1:private` is `invalid_router`, and the retired `phantom-1:zdr` is `router_retired`; a `router` with a different `model` is `router_model_conflict`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "401": {
            "description": "No key (`missing_api_key`), or a key that does not start with `sk-` (`invalid_api_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "402": {
            "description": "The key is unknown, inactive, expired or over its spend cap, or its balance does not cover the video (`insufficient_balance`). Also sent when the hold could not be placed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "Insufficient balance for a 4s video ($0.4000).",
                    "type": "insufficient_quota",
                    "code": "insufficient_balance"
                  }
                }
              }
            }
          },
          "404": {
            "description": "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).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "429": {
            "description": "The key's per-minute spend cap is reached (`spend_rate_exceeded`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "502": {
            "description": "The job did not start, so nothing is billed, or it started but could not be saved and the charge was refunded (`upstream_unavailable`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. On a `502`, sent only when the charge was refunded because the job could not be saved.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "503": {
            "description": "Phantom has no upstream key configured (`upstream_unavailable`), or the model has no published per-second rate (`model_unpriced`). Also sent when the upstream refuses Phantom's own account (its credit or budget is used up, or its key is rejected), or when Phantom can't load its model list. Retry in a few minutes. Nothing is billed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/video/generations/{id}": {
      "get": {
        "operationId": "getV1VideoGenerationsId",
        "summary": "Poll a video generation job for its result",
        "description": "Reports a video job started with `POST /v1/video/generations`. Phantom looks the job up by its id and the calling key together, so another key cannot read it. A finished or failed job is answered from Phantom's record without asking the upstream again. A running job is checked with the upstream on each poll.\n\nWhen the upstream reports an error, or reports the job done with no video, Phantom marks the job failed and refunds the charge. Only the poll that marks it failed refunds, so a charge is never refunded twice. If the refund does not go through, the job goes back to running and the poll answers `502 refund_failed`; poll again.\n\nA finished job carries the upstream's video URL. Phantom does not copy the file.",
        "tags": [
          "Inference"
        ],
        "security": [
          {
            "apiKey": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The job id from the start call (`vid_...`).",
            "schema": {
              "type": "string",
              "description": "The job id from the start call (`vid_...`)."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The job's state. Which fields appear depends on `status`.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "The job id."
                    },
                    "object": {
                      "type": "string",
                      "description": "Always `video.generation`.",
                      "enum": [
                        "video.generation"
                      ]
                    },
                    "status": {
                      "type": "string",
                      "description": "`pending` while the upstream works, `completed` with a video URL, or `failed` and refunded.",
                      "enum": [
                        "pending",
                        "completed",
                        "failed"
                      ]
                    },
                    "model": {
                      "type": "string",
                      "description": "The catalog model id the job runs on."
                    },
                    "cost_usd": {
                      "type": "number",
                      "description": "What the job cost, in US dollars. 0 once it failed and was refunded."
                    },
                    "seconds": {
                      "type": "integer",
                      "description": "Only when `completed`: the video length."
                    },
                    "data": {
                      "type": "array",
                      "description": "Only when `completed`: the video.",
                      "items": {
                        "type": "object",
                        "description": "One video.",
                        "properties": {
                          "url": {
                            "type": "string",
                            "description": "Where to download it, as the upstream returned it.",
                            "format": "uri"
                          }
                        }
                      }
                    },
                    "error": {
                      "type": "string",
                      "description": "Only when `failed`: why."
                    },
                    "refunded": {
                      "type": "boolean",
                      "description": "Only when `failed`: always `true`.",
                      "enum": [
                        true
                      ]
                    },
                    "refund_usd": {
                      "type": "number",
                      "description": "Only when `failed`: what the job gave back to the key, in US dollars. It is what the start call took off the key, and a later poll of the same job says the same."
                    }
                  },
                  "required": [
                    "id",
                    "object",
                    "status",
                    "model",
                    "cost_usd"
                  ]
                },
                "example": {
                  "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"
                    }
                  ]
                }
              }
            },
            "headers": {
              "x-phantom-upstream": {
                "description": "Always `pai`. The receipt's `upstream` field holds the same value. Sent with a `completed` answer only. Always `pai`.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-receipt": {
                "description": "A signed receipt for the call: `base64url(canonical JSON payload).base64url(signature)`. The payload names the model served, token counts, cost and hashes of the request and response. Check it against `GET /v1/receipts/key`. Left out when the deployment has no signing key. Sent with a `completed` answer only. On this route `model_served` is the job's model id, the token counts are 0, `upstream_request_id` is `null`, and `input_hash` covers the job settings (model, seconds, resolution, audio) rather than the prompt, which Phantom does not keep.",
                "schema": {
                  "type": "string"
                }
              },
              "x-phantom-balance-usd": {
                "description": "Credit left on the key after this call was billed, in US dollars. Left out when the debit found no key to charge; never sent as a guessed zero. Sent only on the poll that marks the job failed and refunds it: the balance after the refund.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "No key (`missing_api_key`), or a key that does not start with `sk-` (`invalid_api_key`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "No job with this id for this key (`job_not_found`).",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                },
                "example": {
                  "error": {
                    "message": "No video job 'vid_9' for this API key.",
                    "type": "invalid_request_error",
                    "code": "job_not_found"
                  }
                }
              }
            }
          },
          "502": {
            "description": "The upstream could not be reached for the status, and the job stays running (`upstream_unavailable`). Or the job failed but the refund did not go through (`refund_failed`). Poll again in both cases.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "503": {
            "description": "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`). The job stays as it was. Poll again in a few minutes.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            },
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again. Sent when the Gateway refused Phantom's own account: seconds to wait before polling again.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces": {
      "get": {
        "operationId": "getV1Workspaces",
        "summary": "List the account's workspace",
        "description": "An account owns at most one workspace. `current_workspace_id` is the guest workspace this browser or credential manages, else the account's workspace. Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postV1Workspaces",
        "summary": "Get the account's workspace, or make a guest workspace",
        "description": "Signed in, returns the account's one workspace and makes it when there is none; `existing` is true and `recovery` is null when it already existed. With `guest: true` or signed out, makes a guest workspace and returns its recovery file and a browser session. The body must be a JSON object: send `{}` (or `{\"guest\": true}`) even when you have nothing to put in it, because an empty body is a 400. Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "guest": {
                    "type": "boolean",
                    "description": "Make a guest workspace even if a session is signed in. Signed out, a guest workspace is made either way."
                  },
                  "name": {
                    "type": "string",
                    "description": "A name for the new workspace."
                  }
                }
              },
              "example": {
                "guest": true
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "The body is empty, not JSON, or not a JSON object (an array, say): \"Send a JSON object.\" Or another invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/recover": {
      "post": {
        "operationId": "postV1WorkspacesRecover",
        "summary": "Restore a guest workspace from its recovery file",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}": {
      "get": {
        "operationId": "getV1WorkspacesId",
        "summary": "Read a workspace's balance, keys and recent charges",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "description": "Workspace id."
                    },
                    "name": {
                      "type": "string",
                      "description": "Workspace display name."
                    },
                    "account_linked": {
                      "type": "boolean",
                      "description": "Whether an account is linked to this workspace."
                    },
                    "balance_usd": {
                      "type": "number",
                      "description": "Available balance in US dollars."
                    },
                    "held_usd": {
                      "type": "number",
                      "description": "Funds held for requests in flight, in US dollars."
                    },
                    "keys": {
                      "type": "array",
                      "description": "The workspace's API keys. Raw keys are never returned.",
                      "items": {
                        "type": "object",
                        "description": "A key.",
                        "additionalProperties": true
                      }
                    },
                    "access": {
                      "type": "array",
                      "description": "Active management credentials and sessions.",
                      "items": {
                        "type": "object",
                        "description": "One credential.",
                        "additionalProperties": true
                      }
                    },
                    "charges": {
                      "type": "array",
                      "description": "The 50 most recent usage charges, newest first. Each carries `why`, the reason the model ran in plain words, and no `route_reason`: the raw reason code stays on the server.",
                      "items": {
                        "type": "object",
                        "description": "A usage charge.",
                        "properties": {
                          "why": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "Why the model ran, in plain words. `null` when the call had no reason. A key's own route policy reason shows as written."
                          }
                        },
                        "required": [
                          "why"
                        ],
                        "additionalProperties": true
                      }
                    }
                  },
                  "required": [
                    "id",
                    "name",
                    "account_linked",
                    "balance_usd",
                    "held_usd",
                    "keys",
                    "access",
                    "charges"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteV1WorkspacesId",
        "summary": "Delete an empty workspace",
        "description": "Deletes the workspace with its API keys, management credentials, device codes and automatic reload settings, and clears the browser session. Purchase and usage history stay; usage rows hold only a key hash. Refused with 409 while the workspace has credit left, a request still holding credit, or a payment in progress. A hold that set aside no money, or one that has expired, does not count: an expired hold goes back to the balance first. Management requires workspace ownership or a separate management credential; inference API keys do not grant management access.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The workspace was deleted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "deleted": {
                      "type": "boolean",
                      "description": "Always `true`.",
                      "enum": [
                        true
                      ]
                    }
                  },
                  "required": [
                    "deleted"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "The workspace still has credit, a request holding credit or a payment in progress.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/access/{token}": {
      "delete": {
        "operationId": "deleteV1WorkspacesIdAccessToken",
        "summary": "Revoke a session, device or recovery credential",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "token",
            "in": "path",
            "required": true,
            "description": "The management access entry, from the workspace view.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/claim": {
      "post": {
        "operationId": "postV1WorkspacesIdClaim",
        "summary": "Move a guest workspace into the signed-in account",
        "description": "An account owns one workspace. With none, the guest workspace becomes it. With one, the guest workspace's keys, credit, payments and open holds move into it (`merged: true`), the keys keep working. Either way the guest workspace's recovery file, browser sessions, CLI devices and unredeemed device codes stop working, and a request with one of them gets a 401 that says to sign in again (`phantom login` in the CLI, or sign in on /keys); the account's own sign-in manages the workspace. 409 when the workspace belongs to another account. Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/device": {
      "get": {
        "operationId": "getV1WorkspacesIdDevice",
        "summary": "Read a pending device login",
        "description": "Looks up the device login whose `user_code` is in `code`, so the page can show the client name before the owner approves it. Without `code`, or with a code that is unknown, expired or already decided, the answer is 404 `No pending login. Start phantom login again.`",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "code",
            "in": "query",
            "required": true,
            "description": "The `user_code` the CLI showed, such as `ABCD-EFGH`. Case and the dash do not matter.",
            "schema": {
              "type": "string",
              "description": "The `user_code` the CLI showed, such as `ABCD-EFGH`. Case and the dash do not matter."
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The pending login.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "user_code": {
                      "type": "string",
                      "description": "The code, formatted with a dash."
                    },
                    "client_name": {
                      "type": "string",
                      "description": "The name the client gave when it started the login."
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "When the code stops working.",
                      "format": "date-time"
                    }
                  },
                  "required": [
                    "user_code",
                    "client_name",
                    "expires_at"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "Management access required."
          },
          "404": {
            "description": "No pending login."
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed."
          }
        }
      },
      "post": {
        "operationId": "postV1WorkspacesIdDevice",
        "summary": "Approve or deny device login",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Decision recorded.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request."
          },
          "401": {
            "description": "Management access required."
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "No pending login."
          },
          "409": {
            "description": "Too many keys."
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed."
          }
        }
      }
    },
    "/v1/workspaces/{id}/fund": {
      "post": {
        "operationId": "postV1WorkspacesIdFund",
        "summary": "Start a card or crypto purchase for a workspace",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Every method pays Stripe, and Stripe's signed webhook adds the credit. `card` returns a Stripe Checkout `checkout_url` and charges the price plus Stripe's card fee, with the total in `amount_cents`. `stripe-crypto` returns a `checkout_url`, a Stripe link (today on `pm-redirects.stripe.com`, which hands the buyer on to Stripe's crypto page), where the buyer picks the coin and network (minimum $1.00). `crypto` quotes USDC on Solana to Stripe's deposit address, or USDC on Base with `coin: usdc-base` (minimum $1.00); SOL and USDT are no longer accepted. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "method": {
                    "type": "string",
                    "description": "Payment method: `card` on Stripe Checkout, `stripe-crypto` on Stripe's crypto page, or `crypto` for a USDC transfer quoted here.",
                    "enum": [
                      "card",
                      "crypto",
                      "stripe-crypto"
                    ]
                  },
                  "amount_usd": {
                    "type": "number",
                    "description": "Amount in US dollars."
                  },
                  "coin": {
                    "type": "string",
                    "description": "With `method: crypto`: `usdc` for USDC on Solana (the default), `usdc-base` for USDC on Base. `sol` and `usdt` get a 400.",
                    "enum": [
                      "usdc",
                      "usdc-base"
                    ]
                  }
                },
                "required": [
                  "method",
                  "amount_usd"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/import": {
      "post": {
        "operationId": "postV1WorkspacesIdImport",
        "summary": "Import a key into a workspace (ended; 410)",
        "description": "Every key now comes in its own workspace, so there is no key outside one to import. To move a purchased key and its credit into your account, restore the purchase's recovery file and attach that workspace to your account (`POST /v1/workspaces/{id}/claim`).",
        "tags": [
          "Keys"
        ],
        "security": [],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "410": {
            "description": "Key import has ended.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/keys": {
      "post": {
        "operationId": "postV1WorkspacesIdKeys",
        "summary": "Create a named key that spends the workspace balance",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/keys/{key}": {
      "post": {
        "operationId": "postV1WorkspacesIdKeysKey",
        "summary": "Update, rotate or revoke one of the workspace's keys",
        "description": "With action update the body is the same as PATCH: caps, route_policy, name, and the phantom-1 lineup (lineup replaces it; lineup_changes changes only what it names, null sets one back to its default; both is a 400; an `economy` tier or fallback is a 400 too, because phantom-1 has two tiers, Standard and Frontier). Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "key",
            "in": "path",
            "required": true,
            "description": "The key id (`key_id` from the workspace view).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchV1WorkspacesIdKeysKey",
        "summary": "Update, rotate or revoke one of the workspace's keys",
        "description": "The body can set caps, route_policy, name, and the phantom-1 lineup: lineup replaces it, lineup_changes changes only the tiers and fallbacks it names (null sets one back to its default) on top of the stored lineup. Sending both is a 400, and so is an `economy` tier or fallback: phantom-1 has two tiers, Standard and Frontier. Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "key",
            "in": "path",
            "required": true,
            "description": "The key id (`key_id` from the workspace view).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      },
      "delete": {
        "operationId": "deleteV1WorkspacesIdKeysKey",
        "summary": "Update, rotate or revoke one of the workspace's keys",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "key",
            "in": "path",
            "required": true,
            "description": "The key id (`key_id` from the workspace view).",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/logout": {
      "post": {
        "operationId": "postV1WorkspacesIdLogout",
        "summary": "Sign out: revoke this management session",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/payments/{payment}": {
      "get": {
        "operationId": "getV1WorkspacesIdPaymentsPayment",
        "summary": "Read the status of a workspace purchase",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "payment",
            "in": "path",
            "required": true,
            "description": "The payment id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/recovery": {
      "post": {
        "operationId": "postV1WorkspacesIdRecovery",
        "summary": "Replace the recovery file",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/reload": {
      "get": {
        "operationId": "getV1WorkspacesIdReload",
        "summary": "Read or change the workspace's automatic reload",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      },
      "post": {
        "operationId": "postV1WorkspacesIdReload",
        "summary": "Read or change the workspace's automatic reload",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      },
      "patch": {
        "operationId": "patchV1WorkspacesIdReload",
        "summary": "Read or change the workspace's automatic reload",
        "description": "Management requires workspace ownership or a separate management credential; inference API keys do not grant management access. Responses containing secrets are not cached.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Operation completed.",
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store for management responses.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "401": {
            "description": "Management authentication required.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "403": {
            "description": "Added by proxy.ts: a cookie-authenticated write from another site, without a Bearer token.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "404": {
            "description": "Workspace or key not found.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "409": {
            "description": "Operation conflicts with current state.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "Operation failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          },
          "503": {
            "description": "Payment service unavailable.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/workspaces/{id}/spend": {
      "get": {
        "operationId": "getV1WorkspacesIdSpend",
        "summary": "Read the workspace's spend by key, model and day",
        "description": "What every key in the workspace spent over a date range, by key name, model and day, and what `phantom-1` routing saved. Needs workspace ownership or a management credential; an inference key gets 401, and one key reads only its own spend at `GET /v1/key/spend`. The range is whole UTC days, `from` and `to` both included, and defaults to this month so far. It covers at most 366 days. Keys are named, never listed by hash, and a key that was revoked or rotated away stays in the list with `active: false` so its history keeps its name. Costs are what Phantom charged, markup included. Nothing in the answer carries prompt or completion text, or a key.\n\n`routing` is an estimate. For each call sent to `phantom-1`, `phantom-1:free` or `phantom-1:private`, Phantom prices the same tokens on `phantom-1`'s frontier model at that model's price today, and subtracts what the call cost. Calls that already ran on the frontier model count as no saving. A different model may write more or fewer tokens, and prices change, so treat it as a guide. When the frontier model's price isn't listed, `routing.available` is `false` and no figure is given. Calls that asked for `auto` on a key with a route policy aren't counted: the policy, not `phantom-1`, picked their model.",
        "tags": [
          "Keys"
        ],
        "security": [
          {
            "workspace": []
          },
          {
            "workspaceCookie": []
          },
          {
            "session": []
          }
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "The workspace id.",
            "schema": {
              "type": "string",
              "description": "The workspace id."
            }
          },
          {
            "name": "from",
            "in": "query",
            "required": false,
            "description": "First day, `YYYY-MM-DD`, UTC. Defaults to the first of the month `to` falls in.",
            "schema": {
              "type": "string",
              "description": "First day, `YYYY-MM-DD`, UTC. Defaults to the first of the month `to` falls in.",
              "format": "date",
              "examples": [
                "2026-10-01"
              ]
            }
          },
          {
            "name": "to",
            "in": "query",
            "required": false,
            "description": "Last day, `YYYY-MM-DD`, UTC. Defaults to today. Can't be in the future.",
            "schema": {
              "type": "string",
              "description": "Last day, `YYYY-MM-DD`, UTC. Defaults to today. Can't be in the future.",
              "format": "date",
              "examples": [
                "2026-10-18"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "The workspace's spend.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "scope": {
                      "type": "string",
                      "description": "`workspace` on this route.",
                      "enum": [
                        "key",
                        "workspace"
                      ]
                    },
                    "from": {
                      "type": "string",
                      "description": "First day covered, UTC.",
                      "format": "date"
                    },
                    "to": {
                      "type": "string",
                      "description": "Last day covered, UTC.",
                      "format": "date"
                    },
                    "total": {
                      "type": "object",
                      "description": "Everything in the range.",
                      "properties": {
                        "calls": {
                          "type": "integer",
                          "description": "Calls, free ones included."
                        },
                        "spent_usd": {
                          "type": "number",
                          "description": "What they cost, in US dollars."
                        },
                        "prompt_tokens": {
                          "type": "integer",
                          "description": "Prompt tokens, cached ones included."
                        },
                        "completion_tokens": {
                          "type": "integer",
                          "description": "Completion tokens."
                        }
                      },
                      "required": [
                        "calls",
                        "spent_usd",
                        "prompt_tokens",
                        "completion_tokens"
                      ]
                    },
                    "keys": {
                      "type": "array",
                      "description": "Every key in the workspace, biggest spender first, including keys with no calls in the range.",
                      "items": {
                        "type": "object",
                        "description": "A key.",
                        "properties": {
                          "name": {
                            "type": "string",
                            "description": "The key's name."
                          },
                          "prefix": {
                            "type": [
                              "string",
                              "null"
                            ],
                            "description": "The key's first characters, to tell keys with the same name apart. `null` for a key with no stored prefix."
                          },
                          "active": {
                            "type": "boolean",
                            "description": "Whether the key still works."
                          },
                          "calls": {
                            "type": "integer",
                            "description": "Calls in the range."
                          },
                          "spent_usd": {
                            "type": "number",
                            "description": "What they cost, in US dollars."
                          },
                          "saved_usd": {
                            "type": [
                              "number",
                              "null"
                            ],
                            "description": "What `phantom-1` routing saved on this key, in US dollars. `null` when it can't be worked out; see `routing`."
                          },
                          "models": {
                            "type": "array",
                            "description": "The models the key ran, biggest spender first.",
                            "items": {
                              "type": "object",
                              "description": "A model.",
                              "properties": {
                                "model": {
                                  "type": "string",
                                  "description": "The model that ran."
                                },
                                "calls": {
                                  "type": "integer",
                                  "description": "Calls."
                                },
                                "spent_usd": {
                                  "type": "number",
                                  "description": "Cost in US dollars."
                                }
                              },
                              "required": [
                                "model",
                                "calls",
                                "spent_usd"
                              ]
                            }
                          }
                        },
                        "required": [
                          "name",
                          "prefix",
                          "active",
                          "calls",
                          "spent_usd",
                          "saved_usd",
                          "models"
                        ]
                      }
                    },
                    "models": {
                      "type": "array",
                      "description": "Each model that ran, biggest spender first.",
                      "items": {
                        "type": "object",
                        "description": "A model.",
                        "properties": {
                          "model": {
                            "type": "string",
                            "description": "The model that ran."
                          },
                          "calls": {
                            "type": "integer",
                            "description": "Calls."
                          },
                          "spent_usd": {
                            "type": "number",
                            "description": "Cost in US dollars."
                          },
                          "prompt_tokens": {
                            "type": "integer",
                            "description": "Prompt tokens."
                          },
                          "completion_tokens": {
                            "type": "integer",
                            "description": "Completion tokens."
                          }
                        },
                        "required": [
                          "model",
                          "calls",
                          "spent_usd",
                          "prompt_tokens",
                          "completion_tokens"
                        ]
                      }
                    },
                    "days": {
                      "type": "array",
                      "description": "Every day in the range, oldest first. A day with no calls is zero.",
                      "items": {
                        "type": "object",
                        "description": "A day.",
                        "properties": {
                          "date": {
                            "type": "string",
                            "description": "The UTC day.",
                            "format": "date"
                          },
                          "calls": {
                            "type": "integer",
                            "description": "Calls."
                          },
                          "spent_usd": {
                            "type": "number",
                            "description": "Cost in US dollars."
                          }
                        },
                        "required": [
                          "date",
                          "calls",
                          "spent_usd"
                        ]
                      }
                    },
                    "routing": {
                      "type": "object",
                      "description": "What `phantom-1` routing saved.",
                      "properties": {
                        "available": {
                          "type": "boolean",
                          "description": "`false` when the frontier model's price isn't listed. Then only `reason` follows."
                        },
                        "reason": {
                          "type": "string",
                          "description": "Why no saving is given. Only when `available` is `false`."
                        },
                        "calls": {
                          "type": "integer",
                          "description": "Calls sent to a `phantom-1` router."
                        },
                        "spent_usd": {
                          "type": "number",
                          "description": "What they cost, in US dollars."
                        },
                        "baseline_model": {
                          "type": "string",
                          "description": "The model the same calls are priced on."
                        },
                        "baseline_usd": {
                          "type": "number",
                          "description": "What the same calls would have cost on it, in US dollars."
                        },
                        "saved_usd": {
                          "type": "number",
                          "description": "`baseline_usd` less `spent_usd`."
                        },
                        "basis": {
                          "type": "string",
                          "description": "How `baseline_usd` is worked out, in words."
                        }
                      },
                      "required": [
                        "available"
                      ]
                    }
                  },
                  "required": [
                    "scope",
                    "from",
                    "to",
                    "total",
                    "keys",
                    "models",
                    "days",
                    "routing"
                  ]
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "400": {
            "description": "A date that isn't `YYYY-MM-DD` or isn't real, `from` after `to`, a `to` in the future, or a range over 366 days.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "401": {
            "description": "No workspace access: not signed in as the owner, no guest session, and no valid management credential for this workspace.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          },
          "429": {
            "description": "Added by proxy.ts: too many requests from your address in the current window.",
            "headers": {
              "retry-after": {
                "description": "Seconds to wait before trying again.",
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OpenAIError"
                }
              }
            }
          },
          "500": {
            "description": "The read failed.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            }
          }
        }
      }
    },
    "/v1/x402/top-up": {
      "post": {
        "operationId": "postV1X402TopUp",
        "summary": "Top up with Solana USDC (ended; 410)",
        "description": "This route paid Phantom's own wallet, and every agent payment now goes through Stripe. It asks for no payment and stores nothing. Use `POST /v1/purchase/x402` instead: send `amount_usd`, and `target_api_key` to add the credit to a key you have, then pay the `payment_url` it returns with pay.",
        "tags": [
          "Purchases"
        ],
        "security": [],
        "responses": {
          "410": {
            "description": "Top-ups here have ended. The error names `POST /v1/purchase/x402`.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/SimpleError"
                }
              }
            },
            "headers": {
              "cache-control": {
                "description": "Caching rules for the response. no-store.",
                "schema": {
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "workspace": {
        "type": "http",
        "scheme": "bearer",
        "description": "A separate workspace management credential. An inference API key does not grant this access."
      },
      "workspaceCookie": {
        "type": "apiKey",
        "in": "cookie",
        "name": "phantom_workspace",
        "description": "The HTTP-only guest workspace management session."
      },
      "apiKey": {
        "type": "http",
        "scheme": "bearer",
        "description": "A Phantom API key: `Authorization: Bearer sk-phantom-...`."
      },
      "anthropicKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-api-key",
        "description": "A Phantom API key in `x-api-key`, as Anthropic SDKs send it."
      },
      "googleKey": {
        "type": "apiKey",
        "in": "header",
        "name": "x-goog-api-key",
        "description": "A Phantom API key in `x-goog-api-key`, as Google's SDK and Gemini CLI send it."
      },
      "session": {
        "type": "apiKey",
        "in": "cookie",
        "name": "__Secure-neon-auth.session_token",
        "description": "The session cookie set when you sign in on phantom.codes."
      }
    },
    "schemas": {
      "OpenAIError": {
        "type": "object",
        "description": "An error in OpenAI's format.",
        "properties": {
          "error": {
            "type": "object",
            "description": "What went wrong.",
            "properties": {
              "message": {
                "type": "string",
                "description": "Readable explanation."
              },
              "type": {
                "type": "string",
                "description": "Error class, such as `invalid_request_error`, `insufficient_quota`, `rate_limit_error` or `api_error`."
              },
              "code": {
                "type": "string",
                "description": "A stable machine-readable code, when there is one (`missing_api_key`, `spend_rate_exceeded`, `key_busy` and so on)."
              }
            },
            "required": [
              "message",
              "type"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "SimpleError": {
        "type": "object",
        "description": "An error as a single string.",
        "properties": {
          "error": {
            "type": "string",
            "description": "A code such as `invalid_key`, or a readable explanation."
          },
          "detail": {
            "type": "string",
            "description": "More about the error, on routes that add it."
          }
        },
        "required": [
          "error"
        ]
      },
      "GoogleError": {
        "type": "object",
        "description": "An error in Google's format, as Gemini CLI reads it.",
        "properties": {
          "error": {
            "type": "object",
            "description": "What went wrong.",
            "properties": {
              "code": {
                "type": "integer",
                "description": "The HTTP status."
              },
              "message": {
                "type": "string",
                "description": "Readable explanation."
              },
              "status": {
                "type": "string",
                "description": "Google's name for the status: `INVALID_ARGUMENT` (400), `UNAUTHENTICATED` (401), `FAILED_PRECONDITION` (402), `PERMISSION_DENIED` (403), `NOT_FOUND` (404), `RESOURCE_EXHAUSTED` (429), `UNAVAILABLE` (502, 503), otherwise `INTERNAL`."
              }
            },
            "required": [
              "code",
              "message",
              "status"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "AnthropicError": {
        "type": "object",
        "description": "An error in Anthropic's format.",
        "properties": {
          "type": {
            "type": "string",
            "description": "Always `error`.",
            "enum": [
              "error"
            ]
          },
          "error": {
            "type": "object",
            "description": "What went wrong.",
            "properties": {
              "type": {
                "type": "string",
                "description": "`invalid_request_error` (400), `authentication_error` (401), `billing_error` (402), `permission_error` (403), `not_found_error` (404), `request_too_large` (413), `rate_limit_error` (429), otherwise `api_error`."
              },
              "message": {
                "type": "string",
                "description": "Readable explanation."
              }
            },
            "required": [
              "type",
              "message"
            ]
          }
        },
        "required": [
          "type",
          "error"
        ]
      }
    }
  }
}
