Reference

API Reference

TokenFast exposes OpenAI-compatible endpoints. All requests should be sent to the base URL with your API key in the Authorization header.

Base URL: https://api.tokenfast.ai/v1

Endpoints


POST/v1/chat/completions

Creates a model response for the given chat conversation. This is the primary endpoint for interacting with language models.

Request Body

ParameterTypeDescription
modelrequiredstringID of the model to use (e.g., gpt-4o, claude-sonnet-4-6, gemini-2.5-pro).
messagesrequiredarrayA list of messages comprising the conversation. Each message has a role (system, user, or assistant) and content.
temperaturenumberSampling temperature between 0 and 2. Higher values make output more random. Default: 1.
max_tokensintegerMaximum number of tokens to generate in the response. Default varies by model.
top_pnumberNucleus sampling parameter. An alternative to temperature. Default: 1.
streambooleanIf true, partial message deltas will be sent as server-sent events. Default: false.
stopstring | arrayUp to 4 sequences where the API will stop generating further tokens.
presence_penaltynumberPenalizes new tokens based on whether they appear in the text so far. Range: -2.0 to 2.0.
frequency_penaltynumberPenalizes new tokens based on their existing frequency in the text. Range: -2.0 to 2.0.
toolsarrayA list of tools (functions) the model may call. Each tool is defined with a type, function name, description, and parameters schema.
tool_choicestring | objectControls which tool is called. Options: "none", "auto", or a specific tool object.
response_formatobjectAn object specifying the format of the response. Use {"type": "json_object"} for JSON mode.

Message Object

FieldTypeDescription
rolerequiredstringThe role of the message author: "system", "user", or "assistant".
contentrequiredstringThe content of the message.
namestringAn optional name for the participant.

Example Request

cURL
curl https://api.tokenfast.ai/v1/chat/completions \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-4o",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "Explain quantum computing in simple terms."}
    ],
    "temperature": 0.7,
    "max_tokens": 512
  }'

Example Response

JSON
{
  "id": "chatcmpl-abc123def456",
  "object": "chat.completion",
  "created": 1712345678,
  "model": "gpt-4o",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "Quantum computing uses quantum bits (qubits) that can exist in multiple states simultaneously..."
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 28,
    "completion_tokens": 156,
    "total_tokens": 184
  }
}

GET/v1/models

Lists the currently available models along with their capabilities and pricing information. This endpoint does not require authentication.

Parameters

This endpoint takes no parameters.

Example Request

cURL
curl https://api.tokenfast.ai/v1/models

Example Response

JSON
{
  "object": "list",
  "data": [
    {
      "id": "gpt-4o",
      "object": "model",
      "owned_by": "openai",
      "capabilities": ["chat", "code", "vision", "function_calling", "json_mode"],
      "context_window": 128000,
      "pricing": {
        "input_per_million": 2.50,
        "output_per_million": 10.00
      }
    },
    {
      "id": "claude-sonnet-4-6",
      "object": "model",
      "owned_by": "anthropic",
      "capabilities": ["chat", "code", "vision", "function_calling"],
      "context_window": 200000,
      "pricing": {
        "input_per_million": 3.00,
        "output_per_million": 15.00
      }
    }
  ]
}

GET/v1/usage/keys

Returns a per-key usage report for your whole account: spend, request count and token totals for every API key, bucketed by calendar day (Asia/Shanghai). Authenticate with your usage query key (uk-...) — a read-only credential generated in Dashboard → Settings, separate from your LLM keys.

Parameters

startdate, optionalRange start, YYYY-MM-DD (inclusive, Asia/Shanghai days). Defaults to 29 days before end.
enddate, optionalRange end, YYYY-MM-DD (inclusive). Defaults to today. Max range: 92 days.

Example Request

cURL
curl "https://api.tokenfast.ai/v1/usage/keys?start=2026-06-09&end=2026-07-08" \
  -H "Authorization: Bearer uk-your-usage-query-key"

Example Response

JSON
{
  "object": "usage.keys",
  "start": "2026-06-09",
  "end": "2026-07-08",
  "timezone": "Asia/Shanghai",
  "keys": [
    {
      "name": "production-backend",
      "hint": "sk-...Xy4a",
      "status": "ACTIVE",
      "blocked": false,
      "created_at": "2026-07-01T02:10:00.000Z",
      "total": {
        "spend_usd": 12.48,
        "requests": 1042,
        "prompt_tokens": 180311,
        "completion_tokens": 95204
      },
      "daily": [
        {
          "date": "2026-07-08",
          "spend_usd": 1.02,
          "requests": 88,
          "prompt_tokens": 15200,
          "completion_tokens": 8100
        }
      ]
    }
  ]
}

Revoked keys with usage inside the range are included (status REVOKED), so historical reports stay complete. Days with no traffic have no daily row.

Rate Limits

30 requests per minute per query key, 120 per minute per IP.

Exceeding the limit returns 429 with a Retry-After header. The query key cannot call models, so this limit never affects your LLM traffic. For daily reporting, one request per day per account is enough.


Authentication

All endpoints (except GET /v1/models) require authentication via a Bearer token in the Authorization header:

Authorization: Bearer sk-your-api-key

API keys can be created and managed from your Dashboard. If you send a request without a valid key, you will receive a 401 Unauthorized response.


Rate Limiting

Rate limits are applied per API key. When a rate limit is exceeded, the API returns a 429 status code. Response headers include:

HeaderDescription
x-ratelimit-limit-requestsMaximum requests per minute for your key
x-ratelimit-remaining-requestsRemaining requests in the current window
x-ratelimit-limit-tokensMaximum tokens per minute for your key
x-ratelimit-remaining-tokensRemaining tokens in the current window
retry-afterSeconds to wait before retrying (on 429 responses)

For more details, see the Error Codes page.