TokenRa
中文Get API Key

Getting started

API Basics

Rules that apply to every TokenRa request: where to send it, how to authenticate, and how to handle errors.

BASE URL

Base URL

UseBase URLClients
OpenAI-compatible: chat, responses, images, videohttps://tokenra.io/v1OpenAI SDKs, LangChain, most tools
Anthropic Messageshttps://tokenra.ioAnthropic SDKs, Claude Code (they append /v1/messages)
Models available to your keyGET https://tokenra.io/v1/modelsAny HTTP client

AUTH

Authentication

MethodHeader or parameterWhere it works
Bearer token (recommended)Authorization: Bearer sk-...Every endpoint
x-api-keyx-api-key: sk-.../v1/messages and /v1/models (Anthropic format)
Google stylex-goog-api-key header or ?key= queryGemini-native paths under /v1beta/models
Keep keys server-side
Never put a key in browser or mobile code. If a key leaks, delete it in the console and create a new one.

CONVENTIONS

Request conventions

  • Send JSON in UTF-8 with Content-Type: application/json. Image edits use multipart/form-data.
  • Streaming responses are server-sent events: data: lines ending with data: [DONE].
  • Reasoning models and image generation can take tens of seconds. Use a client timeout of at least 120 seconds, or stream.

ASYNC

Async tasks (video)

Video endpoints return a task_id right away. Query GET /v1/video/generations/{task_id} every 10–15 seconds until the status is final.

data.statusMeaning
NOT_START / SUBMITTED / QUEUEDAccepted, waiting to start.
IN_PROGRESSGenerating.
SUCCESSDone. Download result_url.
FAILUREFailed. The reason is in fail_reason; the pre-charged amount is refunded.

ERRORS

Errors

Errors come back as an error object. The message ends with a request id; include it when you contact support.

Error body
{
  "error": {
    "message": "Invalid token (request id: 202610231454005716007698268d9d6k7qSUTYb)",
    "type": "new_api_error",
    "code": ""
  }
}
HTTPerror.codeMeaningWhat to do
401—Missing, wrong or deleted API key. The message is Invalid token.Check the Authorization: Bearer header and the key in the console.
400—The body is not valid JSON.Fix the JSON and send Content-Type: application/json.
500invalid_requestA required field is missing, for example messages.Add the field named in the message. Retrying will not help.
403insufficient_user_quotaYour balance or plan quota is used up.Top up in the console, then retry.
503model_not_foundUnknown model ID, or no channel serves it for your group.Check the ID in the model list or with GET /v1/models.
429—Too many requests.Back off exponentially and retry.
5xx—The upstream provider failed or timed out.Retry a few times; keep the request id if it persists.

RETRIES

Rate limits & retries

  • Retry 429 and 5xx with exponential backoff (for example 1 s, 2 s, 4 s) and stop after a few attempts.
  • Do not retry 400, 401, 403 or model_not_found; fix the request first.
  • Too many parallel requests from one IP can be answered with HTTP 503 and an HTML page instead of JSON. Lower the concurrency, back off and retry, and do not assume every error body is JSON.

BILLING

Usage & billing

  • Text models report usage with prompt, completion, cached and reasoning tokens. Image models bill per request; video models bill per task.
  • Failed requests refund the pre-charged amount. The usage log in the console is the final record.
  • Live rates for every model are in the Model Square.