Token Wallet API

An OpenAI-style Chat Completions endpoint in front of every model we stock. One key, one wallet, every model. Calls draw down the matching token pack you own — buy packs on /packs.

Base URL

https://token-wallet.ai/v1

Every endpoint below is relative to this base.

Authentication

Create a key on the API Keys page. Keys are shown once at creation — store yours in a secret manager. Send it as a bearer token in the Authorization header.

curl https://token-wallet.ai/v1/chat/completions \
  -H "Authorization: Bearer tw_xxxxxxxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "deepseek",
    "model": "deepseek-chat",
    "messages": [{ "role": "user", "content": "Hello" }]
  }'

Chat completions

POST /chat/completions takes an OpenAI-shaped body plus a required provider field. The provider + model pair must match a pack you own.

{
  "provider": "deepseek",
  "model": "deepseek-chat",
  "messages": [
    { "role": "system", "content": "You are concise." },
    { "role": "user", "content": "Summarise Singapore's AI policy in 3 bullets." }
  ],
  "temperature": 0.5,
  "max_tokens": 512
}

Response — the deduction comes from your pack, and the pack's remaining balance is returned on every call:

{
  "content": "…",
  "usage": {
    "inputTokens": 24,
    "outputTokens": 86,
    "totalTokens": 110,
    "costCredits": 12,
    "latencyMs": 740
  },
  "pack": {
    "id": "pk_…",
    "remainingTokensEst": 192345,
    "internalCreditsRemaining": 19234,
    "status": "ACTIVE"
  },
  "usageLogId": "ul_…"
}

Responses are returned complete (non-streaming). Token-by-token streaming is available today in the browser workspace; streaming over the API is on the roadmap.

List models

GET /models returns the active models and their per-1M token prices.

curl https://token-wallet.ai/v1/models -H "Authorization: Bearer tw_xxxxxxxxxxxx"
{
  "data": [
    {
      "id": "deepseek/deepseek-chat",
      "provider": "deepseek",
      "model": "deepseek-chat",
      "input_price_per_1m_tokens": 1.4,
      "output_price_per_1m_tokens": 2.8
    }
  ]
}

Code examples

Python (requests):

import requests

r = requests.post(
    "https://token-wallet.ai/v1/chat/completions",
    headers={"Authorization": "Bearer tw_xxxxxxxxxxxx"},
    json={
        "provider": "deepseek",
        "model": "deepseek-chat",
        "messages": [{"role": "user", "content": "Hello"}],
    },
)
print(r.json()["content"])

Node (fetch):

const res = await fetch("https://token-wallet.ai/v1/chat/completions", {
  method: "POST",
  headers: {
    Authorization: "Bearer tw_xxxxxxxxxxxx",
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    provider: "deepseek",
    model: "deepseek-chat",
    messages: [{ role: "user", content: "Hello" }],
  }),
});
const data = await res.json();
console.log(data.content);

Errors

Errors return { "error": { "message", "type" } } with the matching HTTP status.

  • 400Invalid input — model or provider unknown, or schema mismatch.
  • 401Missing or invalid API key.
  • 402No active pack for this provider/model, or the pack ran out mid-call. Buy a pack at /packs.
  • 403Account suspended, or this model isn't allowed for this key.
  • 429Rate limit exceeded. Slow down and retry shortly.
  • 502Upstream provider error. The call was not charged.

Rate limits

Default: a burst of 10 requests, refilling at ~0.5 requests/second per key. Need more? Get in touch.

Security

  • Keys are hashed before storage — we never see the plaintext after creation.
  • Pack deductions run inside DB transactions; failed provider calls are never charged.
  • Upstream provider keys live only on the server. Never expose them to the browser.
  • Revoke a key from the API Keys page the moment you suspect it has leaked.