Docs
Routes below are the handlers in cosmos_pay_gateway.py. Paths are relative to the process that runs that file. This page does not name a public API host.
Chat
POST /v1/chat/completions, streaming delta.content, and the passthrough fields.
Auth
POST /v1/account/anonymous and the bearer header.
Errors
Refusal statuses the gateway actually sends.
A trailing slash is stripped, except on /. POST with a body that is not JSON returns 400 bad_json before the path is chosen. Anything else returns 404 not_found. The archive names GET /v1/paypal/return. The live file does not implement it, so it is not listed. PUT and DELETE appear on the CORS allow-methods header and have no handlers.
Liveness
| Method | Path | Gate | Result |
|---|---|---|---|
| GET | /healthz |
none | 200 JSON: ok, service cosmos-pay-gateway, at, version 1.0-canonical. |
| OPTIONS | any path | none | 204 and CORS headers. No body. |
| GET | /v1/cloudflare/status |
none | 200. When the Cloudflare module loads and both calls succeed: cloudflare_active true, plus token_status, zone, and zone_status. Otherwise cloudflare_active false, with error or note Cloudflare module not loaded. |
Catalog and account
Bearer routes read Authorization only when the value starts with Bearer . A missing, unknown, or revoked key is 401 bad_key with message unknown or revoked key. See Auth. Rows marked “API mount” run only when make_handler was given the UI API object. Without that object the same path is 404 not_found.
| Method | Path | Gate | Result |
|---|---|---|---|
| GET | /v1/models |
Bearer | 200 {object:"list", data:[...]}. Seed registry rows first, then catalog rows whose ids are not already seeded. A catalog row with no free or paid lane is omitted. Performance is the stored perf row, or {provenance:"UNMEASURED"}. Throughput is not filled in. |
| GET | /v1/models/{id} |
Bearer | 200 seed shape or catalog shape for that id. 404 model_not_found when the id is absent. The id is URL-decoded. |
| GET | /v1/usage/today |
Bearer | 200 for that account: day, free_used_face_usd, free_quota_face_usd, credits_face_usd, rollup, and usd_spent_today, tokens_in, tokens_out, calls, unpriced_calls. Balance is the store, not the meter. With no activity store those five counters are 0. |
| GET | /v1/account |
Bearer and API mount | 200: account (hash), plan, credits_face_usd, keys, settings, promises. Key rows are metadata only: key_hash truncated to 12 characters plus ..., label, created_at, revoked, daily_cap_usd. The raw key is not in this list. Promises are the four strings essentials free forever, toll-free under $100/mo, provider discounts pass at full value, and data opt-in, anonymized, never sold. |
| GET | /v1/settings |
Bearer and API mount | 200 {settings}. Missing keys are filled with autotopup {enabled:false, cap_usd:0.0}, data_contribution {aggregates:true, per_run:false}, and alerts {thresholds:[0.5, 0.8, 1.0], slack_webhook:""}. |
| POST | /v1/settings/{key} |
Bearer and API mount | 200 {ok:true, setting, value}. value is the JSON value field, or the whole body when value is absent. The path key is not an allowlist. |
| POST | /v1/account/anonymous |
none | 200 {api_key, daily_cap_usd:1.0} or 500 anonymous_failed. The raw key is in that response only. Details on Auth. |
| POST | /v1/account/create |
API mount | setup_key must match the mounted secret. Match: 200 {account, key, shown_once:true} on the free plan. Mismatch: 403 bad_setup_key. If CF-Turnstile-Token or turnstile_token is sent and the Cloudflare module is loaded, a failed check is 403 turnstile_verification_failed before the setup key is compared. |
Logs, statement, export
| Method | Path | Gate | Result |
|---|---|---|---|
| GET | /v1/logs |
Bearer and API mount | 200 {object:"list", data, activity} for that account only. data is meter events. activity rows are ts, model, prompt_tokens, completion_tokens, usd, usd_provenance, status, and generation_id only when that stored value is a non-empty string. Query limit defaults to 100. Query lane filters meter events. Query model filters meter events and is passed to the activity log. Message text is not a field. |
| GET | /v1/logs/{event_id} |
Bearer and API mount | 200 {data} for one meter event on this account, searched in the latest 1000 meter rows. 404 event_not_found otherwise. Activity rows are not searched by this path. |
| GET | /v1/statement |
Bearer and API mount | 200 {period, toll, credit_events}. period defaults to the current UTC YYYY-MM. toll is the toll module’s statement line for meter events in that period. credit_events are those events whose event is CREDIT_GRANTED or CREDIT_PURCHASED. |
| GET | /v1/statement/export |
Bearer and API mount | 200 text/csv attachment statement-{period}.csv. Columns: at, event, lane, model, measured_usd, event_id. A missing cost.measured_usd is written as 0.0. |
| GET | /v1/export |
Bearer and API mount | 200 {object:"export", events} from this account’s meter tail. |
| GET | /v1/export/full |
Bearer and API mount | 200: account, plan, credits, keys (same truncated metadata as account), settings, events. |
| POST | /v1/meter/ingest |
Bearer | Body events must be an array or the response is 400 bad_events. Each object is stamped with the caller’s account hash before emit, so the payload cannot name another account. 200 {ok:true, ingested, received}. A meter rejection is skipped, not echoed. |
Keys
Issue, rotate, and create put the raw key in that one response with shown_once: true. Later reads return a truncated hash, not the key. Do not log the raw value.
| Method | Path | Gate | Result |
|---|---|---|---|
| POST | /v1/keys/issue |
Bearer and API mount | 200 {key, shown_once:true}. Optional label and daily_cap_usd. |
| POST | /v1/keys/revoke |
Bearer and API mount | 200 {revoked} for key_hash on this account. A raw key that starts with ck_ is hashed before the lookup. |
| POST | /v1/keys/rotate |
Bearer and API mount | Issues a new key, then revokes key_hash. 200 {key, shown_once:true}. Optional label (default rotated) and daily_cap_usd. |
| POST | /v1/keys/cap |
Bearer and API mount | 200 {ok, key_hash, daily_cap_usd}. |
Credits and founding
| Method | Path | Gate | Result |
|---|---|---|---|
| POST | /v1/credits/purchase |
Bearer and API mount | A non-empty pack_id uses the server table only: mini 5.00, maker 19.00, studio 59.00. Face equals that price. A present amount_usd that is not the table price is 400 bad_amount and does not open checkout. An unknown pack is 400 unknown_pack. No Stripe adapter is 503 no_processor. A processor failure is 502 processor_error. Success is 200 {checkout}. Pack return paths are https://tokenctr.com/done.html and https://tokenctr.com/cancel.html. Without pack_id, amount_usd defaults to 10.0 and processor defaults to stripe. processor paypal is used only when a PayPal adapter is mounted. That branch’s default return paths are https://tokenctr.com/done and https://tokenctr.com/cancel. No mounted processor on that branch is 503 no_processor. |
| POST | /v1/founding/purchase |
Bearer and API mount | tier paid checks out at 10.0. tier verified checks out at 1.0. The default tier is paid. Anything else is 400 bad_tier with message paid | verified. A processor failure is 502 processor_error. Success is 200 {checkout, note}. The note is the webhook grants the tier — the click only creates the session. The same Turnstile check as account create applies when a token is sent. Default return paths match the non-pack credit branch. |
| GET | /v1/founding/status |
API mount, no bearer | 200 {sold, cap, remaining}. |
| POST | /v1/webhooks/{processor} |
API mount | The raw body is what the router verifies. 200 is the router result. WebhookError or ProcessorError is 400 with code set to the first word of the exception text. This route does not use the bearer check. |
Universal Multi-Agent Drop-In (OpenCode, OpenHands, Hermes, Pi, Claude Code, Cursor)
TokenCenter operates with zero agent friction. Our gateway accepts dual OpenAI (/v1/chat/completions) and Anthropic (/v1/messages) wire protocols with automatic header extraction (Authorization: Bearer, x-api-key, api-key, anthropic-api-key) and automatic model prefix normalization.
| Client / Agent | Endpoint Target | Environment Configuration | Supported Aliases |
|---|---|---|---|
| OpenCode / OpenHands | https://api.tokenctr.com/v1 |
OPENAI_BASE_URL="https://api.tokenctr.com/v1" |
auto:code, qwen/qwen-2.5-coder-32b-instruct, gpt-4o |
| Claude Code (Anthropic CLI) | https://api.tokenctr.com/v1 |
ANTHROPIC_BASE_URL="https://api.tokenctr.com/v1" |
claude-3-7-sonnet, claude-3-5-haiku, auto:smart |
| OpenWork & Hermes (Nous Research) | https://api.tokenctr.com/v1 |
OPENAI_API_BASE="https://api.tokenctr.com/v1" |
auto:code, featherless/hermes-3-70b, auto:smart |
| Cursor / Windsurf IDE | https://api.tokenctr.com/v1 |
OpenAI Base URL: https://api.tokenctr.com/v1API Key: ck_... |
auto:code, claude-3-7-sonnet, deepseek-v3 |
| Cline & Roo Code | https://api.tokenctr.com/v1 |
OpenAI or Anthropic Compatible Mode | auto:code, auto:fast, auto:smart |
| Aider CLI | https://api.tokenctr.com/v1 |
OPENAI_API_BASE="https://api.tokenctr.com/v1" |
aider --model auto:code |
Token Arbitrage, Provenance & The Two-Flag Circuit Breaker
We aggressively ingest wholesale and below-cost spot capacity (SambaNova, SiliconFlow, Novita, Hyperbolic, Chutes, DeepInfra, Nebius) while guaranteeing full transparency and zero tolerance for stolen keys. We enforce the sovereign rule: Innocent until proven guilty beyond a reasonable doubt.
| Provenance Tier | Silicon / Contract Source | Two-Flag Governance State | Bypass / Failover Policy |
|---|---|---|---|
| DIRECT_OFFICIAL | Direct contracts with OpenAI, Anthropic, xAI, Google Vertex. | Zero flags. 100% SLA uptime. | Primary canonical rail. |
| MANUFACTURED_INFRA | Dedicated RunPod bare-metal clusters, Crusoe, local vLLM/Ollama. | Zero flags. Sovereign compute. | Wholesale zero-markup compute floor ($0.00 - $0.29/M). |
| CERTIFIED_PARTNER | Cerebras (CS-3 LPU), Groq, DeepInfra, Mistral, Together, Scaleway. | Contractually audited. Zero flags. | Sub-150ms TTFT latency. |
| ARBITRAGED_WHOLESALE | SambaNova, SiliconFlow, Novita AI, Hyperbolic, Chutes spot pools. | Vetted promotional / wholesale capacity. | $0.08 - $0.15/M wholesale rates. |
| GREYMARKET_SUSPECT | Unverified secondary reseller or >70% price anomaly. | Flag 1: Served by default with transparent tag x-tokenctr-provenance: greymarket_flagged_1.Flag 2: Instant automated pause & quarantine. Sub-5ms failover to certified rail. |
Callers can pass x-allow-greymarket: false to restrict routing strictly to certified/direct tiers. Confirmed stolen keys are permanently banned with $0 settlement. |
Chat & Streaming Protocols
POST /v1/chat/completions (OpenAI Wire) and POST /v1/messages (Anthropic Wire) are the core inference lanes. Both support true Server-Sent Events (SSE) streaming and response header provenance auditing.