TOKEN ENGINE GATEWAY

API Reference

OpenAI-compatible model calls, plus Token Engine’s own APIs for accounts, billing, channels and the model catalog.

Base URLhttps://api.rstoken.ai

Authentication

Inference and the model catalog use an API key: Authorization: Bearer sk-.... A key is shown once, when it is created, and can never be read again. Revoking or disabling it takes effect on its next request. Account management uses the JWT that POST /v1/auth/login returns, as Authorization: Bearer <JWT>; the console uses a session cookie instead (HttpOnly; __Host-rt_session when the site is served over https, rt_session over plain http), which scripts do not need. Every request a session cookie authenticates that changes something must send the header X-RunToken-CSRF: 1 (else 403 csrf_required), and so must sign-in, every sign-up step, password-reset requests and resets, and re-authentication, whatever Authorization header they carry, and signing out whenever a session cookie comes with it. Other requests authenticated by a bearer JWT need no such header. Sign-up proves the email address with a 6-digit code before the account exists, and opens it without an API key: create keys with POST /v1/keys. The billing webhook is verified by the provider’s signature. Errors of these endpoints are {"error": "<code>", "message": "<sentence>"}.

User account

GET/v1/auth/config

What signing in and up offers: {providers, captcha: {provider, siteKey} | null, legal: {termsVersion, privacyVersion}}.

Public
POST/v1/auth/signup/start

Begin a sign-up with {email, password, name?, referralCode?, agree: true, marketingOptIn?, captchaToken}: a 6-digit code is emailed, valid 10 minutes. Answers 202 {attemptId, email, codeExpiresAt}. Passwords are 8–128 characters (72 bytes at most), not a common password and not the email address (400 weak_password).

Public + X-RunToken-CSRF
POST/v1/auth/signup/verify

Finish it with {attemptId, code}: opens the account, its address verified, and answers 201 {user}. Five wrong codes end the sign-up (400 code_attempts_exceeded).

Public + X-RunToken-CSRF
POST/v1/auth/signup/resend

Email a new code with {attemptId}; at most one a minute and five a day per address.

Public + X-RunToken-CSRF
POST/v1/auth/login

Exchange {email, password} for {user, token}, the token a JWT for scripts. After repeated failures a CAPTCHA token is needed as well (400 captcha_required).

Public + X-RunToken-CSRF
POST/v1/auth/password/forgot

Email a password reset link with {email, captchaToken}; always 202, whether or not an account has the address.

Public + X-RunToken-CSRF
POST/v1/auth/password/reset

Set a new password with {token, password} from the link (valid once, for 30 minutes); every existing session and JWT of the account ends.

Public + X-RunToken-CSRF
GET/v1/auth/:provider/start

A browser’s sign-in with a provider (google, microsoft or x): ?intent=signin (with ref and next), link or reauth. The round trip is bound to the browser by an HttpOnly cookie (__Host-rt_oauth over https) and uses PKCE (and, for Google and Microsoft, an OpenID Connect nonce); the callback, /v1/auth/:provider/callback, signs the browser in or sends it to complete a sign-up, and a failure comes back as /console/login?error=<code>.

Browser
POST/v1/auth/signup/complete

Complete a sign-up that began with a provider, in the browser that holds it, with {email?, agree: true, marketingOptIn?, referralCode?, captchaToken}: 201 {user} for the address the provider vouches for, else a code is emailed (202) and /v1/auth/signup/verify finishes it. GET /v1/auth/signup/pending says who is signing up.

Browser + X-RunToken-CSRF
GET/v1/auth/wallet/nonce

A nonce for signing in with a Web3 wallet (Sign-In with Ethereum, EIP-4361), where the deployment offers it: {nonce}, valid 5 minutes and once. ?intent=link or reauth need the browser’s session.

Browser
POST/v1/auth/wallet/verify

Sign in with {message, signature, intent}: an EIP-4361 message for this site carrying the nonce, signed by the wallet (an ordinary wallet’s signature is checked offline). Signs the browser in (200) or begins a sign-up to complete (202, a wallet has no email address); 400 wallet_expired or wallet_failed otherwise.

Browser + X-RunToken-CSRF
POST/v1/auth/logout

Sign out: ends the session the cookie names and clears the cookie. 204.

Session cookie + X-RunToken-CSRF
POST/v1/auth/reauth

Prove again who is using a console session with {password}, before a sensitive action within the next 10 minutes. 204; 403 invalid_credentials; 400 session_required with a bearer JWT (sign in again instead).

Session cookie + X-RunToken-CSRF
GET/v1/me

Read the current account: {user, legal, orgs:[{orgId,name,role}]}.

JWT
GET/v1/me/sessions

The account’s live sessions: {sessions:[{id, createdAt, lastSeenAt, ip, userAgent, method, current}]}.

JWT
DELETE/v1/me/sessions/:id

End one of the account’s sessions. 204; 404 session_not_found. Ending another one than the caller’s needs a sign-in or re-authentication within 10 minutes, else 403 reauth_required.

JWT
POST/v1/me/sessions/revoke-others

End every other session: {revoked}. Needs a sign-in or re-authentication within 10 minutes, else 403 reauth_required.

JWT
GET/v1/me/identities

The account’s sign-in methods: {identities:[{id, provider, display, email, createdAt, lastUsedAt}], hasPassword}.

JWT
DELETE/v1/me/identities/:id

Remove a sign-in method. 204; 409 last_sign_in_method when it is the only way in; needs a sign-in or re-authentication within 10 minutes (403 reauth_required).

JWT
POST/v1/me/legal/accept

Accept the Terms of Service and Privacy Policy in force with {termsVersion, privacyVersion} (the versions /v1/me names): {legal}; 409 legal_version_outdated for any other version.

JWT
PATCH/v1/me

Change the display name with {name} (1–80 characters).

JWT
POST/v1/me/password

Change the password with {currentPassword, newPassword}. Every other session and JWT ends; the answer carries a new token.

JWT
POST/v1/me/email

Change the account’s email address with {email}: a 6-digit code is emailed to the new address, valid 10 minutes (202 {changeId, email, codeExpiresAt}), at most one a minute and five a day per address. Needs a sign-in or re-authentication within 10 minutes (403 reauth_required); 400 disposable_email. POST /v1/me/email/verify with {changeId, code} changes it: every other session and JWT ends, the answer carries a new token, and the old address is told.

JWT
GET/v1/me/export

A copy of the personal data Token Engine holds about the account, as one JSON document: profile, sign-in methods, sessions of the last six months, API key metadata, organizations, legal acceptances, consents, trial, balance, cards and invoices. It holds no secret.

JWT
POST/v1/me/close

Close the account with {confirmEmail}, its address typed. Needs a sign-in or re-authentication within 10 minutes. Every API key and session ends at once; 409 with blockers while it is the only owner of an organization with other members, its balance is below zero, or reseller commission or a payout is open. Its personal details are anonymised 30 days later.

JWT
GET/v1/keys?orgId=…

List personal API keys, or an organization’s with orgId.

JWT
POST/v1/keys

Create keys with {name, orgId?, expiresAt?, spendCap?: {credits, window: "daily"|"monthly"|"total"}, allowedModels?, quantity?} (the older monthlyQuotaCredits is still accepted). A key belongs to the personal account by default; name an organization and its usage is charged to that organization’s shared balance. allowedModels takes exact catalog model ids and vendor/* wildcards (omit it, or pass ["*"], for every model); any other model is refused with 403 model_not_allowed. A quantity above one returns {data:[…]}. This response is the only time a key’s secret is shown.

JWT
PATCH/v1/keys/:id

Rename, disable or re-enable a key, or change its expiry, spend cap, allowed models or routing defaults.

JWT
DELETE/v1/keys/:id

Revoke one of the caller’s API keys.

JWT

Organizations

Every user has a personal account. Organizations are optional: members share the organization’s own balance, quota, usage and invoices. Without an orgId, keys and billing act on the personal account.

POST/v1/orgs

Create an organization with {name}; the creator becomes its owner.

JWT
GET/v1/orgs

List the organizations the caller belongs to, with their role.

JWT
GET/v1/orgs/:orgId/members

List an organization’s members; the caller must be one.

JWT
POST/v1/orgs/:orgId/members

Add an existing user with {email, role}; owner or admin only.

JWT

Models & inference

When you call a third-party Provider’s model, you must also comply with that Provider’s usage policies, license terms and content rules; open-weight models are additionally subject to their licenses (Terms §7.1). The catalog links them where they are recorded: a provider’s policy_url, a model’s license_url. For endpoints labeled “Token Engine First-Party” (first_party: true), Token Engine acts directly as the inference provider and is bound by the additional commitments for First-Party Services in the Terms of Service and the Privacy Policy (Terms §3.3).

GET/v1/models

List the enabled models this key may call, their providers and customer prices, and each model’s license_url (null when none is recorded).

API Key
GET/v1/catalog

The same catalog for a signed-in session, which the console browses.

JWT
GET/v1/catalog/:vendor/:model

One model with the providers serving it (endpoints): each one’s customer price, regions and data policy, its usage policy (policy_url, null when not recorded) and whether it is Token Engine First-Party (first_party).

JWT
POST/v1/chat/completions

Create an OpenAI-style chat completion, streaming over SSE if asked.

API Key

Billing

POST/v1/billing/topup

Create a top-up intent with {amount, currency?, orgId?}; the personal account by default.

JWT
GET/v1/usage/events/export?from=…&to=…&orgId=…

The account’s usage records over [from, to) as CSV, oldest first, at most 12 months per request and none older than 12 months: created_at, request_id, model, provider, request_kind, status, error_code, api_key_id, api_key_name, prompt_tokens, completion_tokens, cached_tokens, cache_write_tokens, total_tokens, token_source, charge_credits, latency_ms, ttfb_ms. An organization’s with orgId for its members; 404 for any other account.

API Key or JWT
GET/v1/billing/balance?orgId=…

Read the personal balance. A JWT may pass orgId for an organization’s; an organization’s API key reads its own.

JWT / API Key
GET/v1/billing/usage?from=…&to=…&orgId=…

Summarize usage over a period, for the personal account or an organization. Usage is shown for the last 12 months: an earlier start is moved up to it, and a period entirely older is refused with 400 range_too_old.

JWT
GET/v1/billing/invoices?orgId=…

List invoices, personal or for an organization.

JWT
GET/v1/billing/invoices/:id.pdf

Download a monthly statement as a PDF. Statements are issued automatically once a month closes.

JWT

Resellers & affiliates

Apply to become a reseller; a Token Engine administrator approves the application and sets the commission rate, a share of Token Engine’s markup on referred usage. A user is attributed to a reseller when their account is created: pass referralCode to /v1/auth/signup/start, or start Google sign-in at /v1/auth/google/start?ref=CODE (used if it leads to a new account). Attribution is permanent, and a reseller never earns commission on their own usage.

POST/v1/resellers

Apply to become a reseller; the application starts pending.

JWT
POST/v1/resellers/referrals

Create a referral code (approved resellers): 4–32 letters, digits, - or _, unique regardless of case.

JWT
GET/v1/resellers/referrals

List the caller’s codes and how many users each referred.

JWT
GET/v1/resellers/commissions

List accrued or paid commissions.

JWT
GET/v1/resellers/summary

Status, rate, referred users and commission totals.

JWT