API Reference

Complete endpoint documentation for the TokenSea platform.

Chat Completions

POST /v1/chat/completions

OpenAI-compatible chat completion endpoint. Supports streaming, tool use, and multi-turn conversations. TokenSea automatically routes to the correct upstream provider based on the model.

Parameters

ParameterTypeDescription
modelstringRequiredModel alias (e.g. claude-sonnet-4-20250514, gpt-4.1)
messagesarrayRequiredArray of {role, content} message objects
max_tokensintegerRequiredMaximum tokens to generate in the response
streambooleanEnable SSE streaming (default: false)
temperaturefloatSampling temperature 0-1 (default: 1)
top_pfloatNucleus sampling threshold
toolsarrayTool/function definitions for function calling
tool_choicestringTool choice mode: auto, none, or specific tool
Request
curl https://api.tokensea.dev/v1/chat/completions \
  -H "Authorization: Bearer tsk-..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'
Response
{
  "id": "chatcmpl-abc123",
  "object": "chat.completion",
  "model": "claude-sonnet-4-20250514",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "Hello! How can I help you today?"
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 12,
    "completion_tokens": 8,
    "total_tokens": 20
  }
}

Messages (Anthropic)

POST /v1/messages

Native Anthropic Messages API. Fully compatible with the Anthropic SDK — just change the base_url. Supports system prompts, multi-turn, tool use, and streaming.

Parameters

ParameterTypeDescription
modelstringRequiredModel alias
messagesarrayRequiredArray of {role, content} objects
max_tokensintegerRequiredMaximum output tokens
systemstringSystem prompt
streambooleanEnable SSE streaming
temperaturefloatSampling temperature 0-1
toolsarrayTool definitions
Request
curl https://api.tokensea.dev/v1/messages \
  -H "x-api-key: tsk-..." \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-20250514",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Hello!"}
    ]
  }'

List Models

GET /v1/models

List all models available to your API key. Returns model IDs and ownership info in OpenAI format.

Response
{
  "object": "list",
  "data": [
    { "id": "claude-sonnet-4-20250514", "object": "model", "owned_by": "tokensea" },
    { "id": "claude-opus-4-20250514", "object": "model", "owned_by": "tokensea" },
    { "id": "gpt-4.1", "object": "model", "owned_by": "tokensea" }
  ]
}

Register

POST /api/auth/register

Create a new account. Returns user object and JWT token.

ParameterTypeDescription
usernamestringRequired3-32 alphanumeric characters
passwordstringRequiredMinimum 6 characters
emailstringOptional email address

Login

POST /api/auth/login

Authenticate with username and password. Returns JWT token valid for 7 days.

ParameterTypeDescription
usernamestringRequiredAccount username
passwordstringRequiredAccount password

List Tokens

GET /api/token/?page=1&pageSize=20

List your API keys with pagination. Requires authentication.

Create Token

POST /api/token/

Create a new API key. The full key is only returned once — store it securely.

ParameterTypeDescription
namestringRequiredHuman-readable key name
planIdnumberBind to a specific plan
quotanumberCustom quota in cents
modelsstring[]Restrict to specific models
expiresAtstringISO date when key expires
Response
{
  "apiKey": { "id": "...", "keyPrefix": "tsk-a1b2", "name": "My Key", "status": "active" },
  "key": "tsk-a1b2c3d4e5f6..."
}

Update Token

PUT /api/token/:id

Update an API key's name, status, or quota. Set status to disabled to temporarily disable a key.

Delete Token

DELETE /api/token/:id

Permanently delete an API key. This action cannot be undone.

Get Self

GET /api/user/self

Get the authenticated user's profile, quota, and usage information.

Response
{
  "id": "1",
  "username": "developer",
  "email": "dev@example.com",
  "role": "user",
  "status": "active",
  "quota": "100000",
  "usedQuota": "2345",
  "requestCount": "42",
  "inviteCode": "A1B2C3D4"
}

Update Self

PUT /api/user/self

Update display name or email address.

ParameterTypeDescription
namestringDisplay name
emailstringEmail address

Usage Logs

GET /api/log/self?page=1

Get paginated request logs for the authenticated user. Each log entry includes model, tokens, cost, latency, and status.

Usage Stats

GET /api/log/self/stats?period=7d

Get usage statistics with daily breakdown and model-level aggregation. Periods: 24h, 7d, 30d.

Response
{
  "totalRequests": 156,
  "dailyBreakdown": [
    { "date": "2026-05-10", "requestCount": 28, "promptTokens": 12000, "completionTokens": 8000, "cost": "560" }
  ],
  "modelBreakdown": [
    { "model": "claude-sonnet-4-20250514", "requestCount": 100, "promptTokens": 50000, "completionTokens": 30000, "cost": "4200" }
  ]
}