Developer APIToken Relay public API reference

Token Relay exposes multi-protocol inference APIs and customer management OpenAPI endpoints. All protected endpoints use Authorization: Bearer <api_key>.

Inference APIs

One API key, model-selected calls

The same TOKEN_RELAY_API_KEY works across OpenAI-compatible, Anthropic-compatible, and DashScope-compatible endpoints. Use the request body model field to choose any entitled model returned by GET /openapi/v1/models or GET /v1/models. API key allowed_model_ids controls which model values a key may call; if a key is scoped away from the requested model, the gateway returns model_not_allowed.

API key model scope examples

ModeRequestMeaning
automaticPOST /openapi/v1/api-keys {"allowed_model_ids":[]}Use all currently entitled customer-visible models. On PATCH, "allowed_model_ids":[] will clear an existing key back to automatic matching.
single{"allowed_model_ids":["qwen-plus"]}Pin the key to one runtime model value.
selected{"allowed_model_ids":["qwen-plus","qwen-max"]}Restrict the key to a selected model set.
unchangedPATCH /openapi/v1/api-keys/{api_key_id}Omit allowed_model_ids on PATCH to keep the current scope unchanged. Responses include model_scope so clients can render automatic, single, or selected state directly.
MethodPathDescription
GETGET /v1/modelsList models callable by the current API key.
POSTPOST /v1/chat/completionsOpenAI Chat Completions-compatible endpoint with non-streaming and streaming support.
POSTPOST /v1/messagesAnthropic Messages-compatible endpoint that reuses the same authentication, routing, billing, content safety, and context-cache pipeline.
POSTPOST /api/v1/services/aigc/text-generation/generationDashScope Text Generation-compatible endpoint for customers using DashScope request bodies.

Customer Management OpenAPI v1

MethodPathDescription
GETGET /openapi/v1/clientGet the unified customer identity for the current API key.
GETGET /openapi/v1/client/profileGet the current customer profile.
PATCHPATCH /openapi/v1/client/profileUpdate the current customer profile.
POSTPOST /openapi/v1/conversationsCreate customer conversation metadata.
GETGET /openapi/v1/conversationsList customer conversation metadata.
GETGET /openapi/v1/conversations/{conversation_id}Get one conversation metadata record.
PATCHPATCH /openapi/v1/conversations/{conversation_id}Update conversation title, model, and custom metadata.
DELETEDELETE /openapi/v1/conversations/{conversation_id}Archive a conversation metadata record.
GETGET /openapi/v1/context/configGet context window, memory retention, and cache configuration.
PATCHPATCH /openapi/v1/context/configUpdate context window, memory retention, and cache configuration.
GETGET /openapi/v1/security/policyGet content safety, masking, logging, data retention, and model-scope policy.
PATCHPATCH /openapi/v1/security/policyUpdate content safety, masking, logging, data retention, and model-scope policy.
GETGET /openapi/v1/routing/policyGet multi-region, fallback, retry, rollout, and model-scope policy.
PATCHPATCH /openapi/v1/routing/policyUpdate multi-region, fallback, retry, rollout, and model-scope policy.
GETGET /openapi/v1/resourcesList model, MCP, Skills, and Agents resource catalog entries.
GETGET /openapi/v1/resources/{resource_id}Get one resource catalog entry.
GETGET /openapi/v1/resource-typesList resource type values.
GETGET /openapi/v1/modelsList models, capabilities, and price summaries visible to the current customer.
GETGET /openapi/v1/models/{model}Get one model detail record.
GETGET /openapi/v1/models/{model}/preflightCheck one model before sending inference traffic with one Bearer API key. Returns protocol URLs, blocking reasons, and billing reconciliation links.
GETGET /openapi/v1/model-tagsList tags for models visible to the current customer.
GETGET /openapi/v1/balanceGet available and reserved balance.
GETGET /openapi/v1/balance/configGet customer balance and quota alert configuration.
PATCHPATCH /openapi/v1/balance/configUpdate customer balance and quota alert configuration.
POSTPOST /openapi/v1/balance/checkCheck whether a specified charge can be covered by available balance.
GETGET /openapi/v1/balance-transactionsList balance transactions for the current customer.
GETGET /openapi/v1/balance-transactions.csvDownload balance transactions as CSV for recharge, charge, reservation, release, and correction ledger movement.
GETGET /openapi/v1/balance-transactions/{transaction_id}Get one balance transaction.
GETGET /openapi/v1/api-keysList API keys without returning plaintext tokens.
POSTPOST /openapi/v1/api-keysCreate an API key. The plaintext token is returned once.
GETGET /openapi/v1/api-keys/{api_key_id}Get one API key.
GETGET /openapi/v1/api-keys/{api_key_id}/model-accessCheck whether one API key can call each customer-visible model.
PATCHPATCH /openapi/v1/api-keys/{api_key_id}Update API key name, quota, and model scope.
DELETEDELETE /openapi/v1/api-keys/{api_key_id}Delete an API key by safely disabling it.
POSTPOST /openapi/v1/api-keys/{api_key_id}/disableDisable an API key.
POSTPOST /openapi/v1/api-keys/{api_key_id}/copyCopy quota and model scope into a new key. The new plaintext token is returned once.
POSTPOST /openapi/v1/api-keys/{api_key_id}/rotateRotate an API key. The old key is disabled and the new plaintext token is returned once.
GETGET /openapi/v1/usage/breakdownGet recent usage and daily breakdowns.
GETGET /openapi/v1/billing/cost-breakdownGet customer billing charge breakdown rows. This endpoint reports customer charges, not supplier cost.
GETGET /openapi/v1/billing/detailGet customer-safe billing detail rows. Supports from, to, model, status, key_id, and request_id filters.
GETGET /openapi/v1/billing/detail.csvDownload billing detail as CSV for finance reconciliation jobs using the same Bearer API key.
GETGET /openapi/v1/billing/monthly-statementGet a customer monthly billing statement with month=YYYY-MM.
GETGET /openapi/v1/billing/monthly-statement.csvDownload monthly statement as CSV for accounting import and offline reconciliation.
GETGET /openapi/v1/billing/rulesList customer-visible billing rules.
GETGET /openapi/v1/billing/rules/{model}Get one customer-visible billing rule.
GETGET /openapi/v1/cost/overviewGet customer spend overview metrics.
GETGET /openapi/v1/cost/trendGet daily customer spend trend metrics.
GETGET /openapi/v1/cost/modelsGet model-level customer spend metrics.
GETGET /openapi/v1/cost/models/{model}Get customer spend details for one model.
GETGET /openapi/v1/observation/metricsGet success rate, latency, error, and request metrics.
GETGET /openapi/v1/observation/chartsGet chart-ready observation data.
GETGET /openapi/v1/observation/logsList customer-safe request observation logs.
GETGET /openapi/v1/traces/{request_id}Get a diagnostic trace summary for the current customer's request.

Customer-safe billing APIs

The billing APIs expose customer charges only: usage, tokens, request IDs, balance changes, visible model names, and customer prices. They never expose supplier cost, margin, operator-side secrets, or internal price-rule identifiers.

Response envelope

{
  "request_id": "req_xxx",
  "success": true,
  "data": {},
  "code": null,
  "message": null
}

Quick start: OpenAI Chat Completions compatible

Optional preflight for one-key model calls and billing: GET /openapi/v1/models/auto-chat-balanced/preflight. The response includes POST https://xbingo.xin/v1/chat/completions, billing_detail_url, and monthly_statement_url so clients can check model availability before inference and reconcile charges afterwards.

curl https://xbingo.xin/v1/chat/completions \
  -H "Authorization: Bearer $TOKEN_RELAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"auto-chat-balanced","messages":[{"role":"user","content":"hello"}]}'

Quick start: Anthropic Messages compatible

curl https://xbingo.xin/v1/messages \
  -H "Authorization: Bearer $TOKEN_RELAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"auto-chat-balanced","max_tokens":512,"messages":[{"role":"user","content":"hello"}]}'

Quick start: DashScope Text Generation compatible

curl https://xbingo.xin/api/v1/services/aigc/text-generation/generation \
  -H "Authorization: Bearer $TOKEN_RELAY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"auto-chat-balanced","input":{"messages":[{"role":"user","content":"hello"}]},"parameters":{"max_tokens":512}}'