API Reference
Complete endpoint documentation for the TokenSea platform.
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
| Parameter | Type | Description | |
|---|---|---|---|
| model | string | Required | Model alias (e.g. claude-sonnet-4-20250514, gpt-4.1) |
| messages | array | Required | Array of {role, content} message objects |
| max_tokens | integer | Required | Maximum tokens to generate in the response |
| stream | boolean | Enable SSE streaming (default: false) | |
| temperature | float | Sampling temperature 0-1 (default: 1) | |
| top_p | float | Nucleus sampling threshold | |
| tools | array | Tool/function definitions for function calling | |
| tool_choice | string | Tool choice mode: auto, none, or specific tool |
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!"}
]
}'
{
"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)
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
| Parameter | Type | Description | |
|---|---|---|---|
| model | string | Required | Model alias |
| messages | array | Required | Array of {role, content} objects |
| max_tokens | integer | Required | Maximum output tokens |
| system | string | System prompt | |
| stream | boolean | Enable SSE streaming | |
| temperature | float | Sampling temperature 0-1 | |
| tools | array | Tool definitions |
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
List all models available to your API key. Returns model IDs and ownership info in OpenAI format.
{
"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
Create a new account. Returns user object and JWT token.
| Parameter | Type | Description | |
|---|---|---|---|
| username | string | Required | 3-32 alphanumeric characters |
| password | string | Required | Minimum 6 characters |
| string | Optional email address |
Login
Authenticate with username and password. Returns JWT token valid for 7 days.
| Parameter | Type | Description | |
|---|---|---|---|
| username | string | Required | Account username |
| password | string | Required | Account password |
List Tokens
List your API keys with pagination. Requires authentication.
Create Token
Create a new API key. The full key is only returned once — store it securely.
| Parameter | Type | Description | |
|---|---|---|---|
| name | string | Required | Human-readable key name |
| planId | number | Bind to a specific plan | |
| quota | number | Custom quota in cents | |
| models | string[] | Restrict to specific models | |
| expiresAt | string | ISO date when key expires |
{
"apiKey": { "id": "...", "keyPrefix": "tsk-a1b2", "name": "My Key", "status": "active" },
"key": "tsk-a1b2c3d4e5f6..."
}
Update Token
Update an API key's name, status, or quota. Set status to disabled to temporarily disable a key.
Delete Token
Permanently delete an API key. This action cannot be undone.
Get Self
Get the authenticated user's profile, quota, and usage information.
{
"id": "1",
"username": "developer",
"email": "dev@example.com",
"role": "user",
"status": "active",
"quota": "100000",
"usedQuota": "2345",
"requestCount": "42",
"inviteCode": "A1B2C3D4"
}
Update Self
Update display name or email address.
| Parameter | Type | Description | |
|---|---|---|---|
| name | string | Display name | |
| string | Email address |
Usage Logs
Get paginated request logs for the authenticated user. Each log entry includes model, tokens, cost, latency, and status.
Usage Stats
Get usage statistics with daily breakdown and model-level aggregation. Periods: 24h, 7d, 30d.
{
"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" }
]
}
