{"openapi":"3.1.0","info":{"title":"Tokens API","version":"1.0.0","description":"One API key for coding models behind OpenAI-compatible and Anthropic-compatible endpoints. Guides and the error list: https://tokens.bd/docs. Any other path under /v1 returns 404 unsupported_endpoint."},"servers":[{"url":"https://tokens.bd"}],"externalDocs":{"description":"Documentation","url":"https://tokens.bd/docs"},"paths":{"/v1/chat/completions":{"post":{"summary":"Chat Completions","description":"OpenAI-style chat. The body is forwarded to the model's provider; fields a model does not support are rejected by it.","security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ChatCompletionRequest"},"example":{"model":"deepseek/deepseek-v4.1-flash","messages":[{"role":"user","content":"What does HTTP 429 mean?"}],"max_tokens":300}}}},"responses":{"200":{"description":"The response. With `stream: true` it is a Server-Sent Events stream (`text/event-stream`).","headers":{"x-tokens-request-id":{"schema":{"type":"string"},"description":"Quote it to support."}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OpenAIObject"}},"text/event-stream":{"schema":{"type":"string"}}}},"400":{"description":"invalid_request: no model, not JSON, or the upstream rejected the body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"missing_api_key or invalid_api_key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"insufficient_credits, no_funding or outstanding_debt","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"The key may not do this: key_inactive, key_expired, model_not_allowed_on_key, monthly_spend_cap_exceeded, tier_permission_denied or account_suspended","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"model_not_found or unsupported_endpoint","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"rate_limited, concurrency_limit, window_exhausted or model_limit_reached. Wait Retry-After seconds.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal error. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"502":{"description":"upstream_unreachable. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/completions":{"post":{"summary":"Legacy completions","description":"Prompt in, text out. Works only for models whose provider still serves it.","security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CompletionRequest"},"example":{"model":"deepseek/deepseek-v4.1-flash","prompt":"Say hello","max_tokens":20}}}},"responses":{"200":{"description":"The response. With `stream: true` it is a Server-Sent Events stream (`text/event-stream`).","headers":{"x-tokens-request-id":{"schema":{"type":"string"},"description":"Quote it to support."}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OpenAIObject"}},"text/event-stream":{"schema":{"type":"string"}}}},"400":{"description":"invalid_request: no model, not JSON, or the upstream rejected the body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"missing_api_key or invalid_api_key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"insufficient_credits, no_funding or outstanding_debt","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"The key may not do this: key_inactive, key_expired, model_not_allowed_on_key, monthly_spend_cap_exceeded, tier_permission_denied or account_suspended","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"model_not_found or unsupported_endpoint","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"rate_limited, concurrency_limit, window_exhausted or model_limit_reached. Wait Retry-After seconds.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal error. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"502":{"description":"upstream_unreachable. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/messages":{"post":{"summary":"Messages (Anthropic API)","description":"Anthropic-style messages. Use the gateway root as the SDK's base URL; the SDKs add /v1/messages.","security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessagesRequest"},"example":{"model":"deepseek/deepseek-v4.1-flash","max_tokens":300,"messages":[{"role":"user","content":"What does HTTP 429 mean?"}]}}}},"responses":{"200":{"description":"The response. With `stream: true` it is a Server-Sent Events stream (`text/event-stream`).","headers":{"x-tokens-request-id":{"schema":{"type":"string"},"description":"Quote it to support."}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OpenAIObject"}},"text/event-stream":{"schema":{"type":"string"}}}},"400":{"description":"invalid_request: no model, not JSON, or the upstream rejected the body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"missing_api_key or invalid_api_key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"insufficient_credits, no_funding or outstanding_debt","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"The key may not do this: key_inactive, key_expired, model_not_allowed_on_key, monthly_spend_cap_exceeded, tier_permission_denied or account_suspended","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"model_not_found or unsupported_endpoint","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"rate_limited, concurrency_limit, window_exhausted or model_limit_reached. Wait Retry-After seconds.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal error. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"502":{"description":"upstream_unreachable. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/messages/count_tokens":{"post":{"summary":"Count tokens of a Messages request","description":"Not billed. Same body as /v1/messages.","security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/MessagesRequest"}}}},"responses":{"200":{"description":"`{ \"input_tokens\": number }`","content":{"application/json":{"schema":{"$ref":"#/components/schemas/OpenAIObject"}}}},"401":{"description":"missing_api_key or invalid_api_key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"insufficient_credits, no_funding or outstanding_debt","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"The key may not do this: key_inactive, key_expired, model_not_allowed_on_key, monthly_spend_cap_exceeded, tier_permission_denied or account_suspended","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"model_not_found or unsupported_endpoint","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"rate_limited, concurrency_limit, window_exhausted or model_limit_reached. Wait Retry-After seconds.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal error. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"502":{"description":"upstream_unreachable. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/embeddings":{"post":{"summary":"Embeddings","description":"Only for catalog models that are embedding models.","security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/EmbeddingsRequest"},"example":{"model":"<an embedding model id>","input":"text to embed"}}}},"responses":{"200":{"description":"The response. With `stream: true` it is a Server-Sent Events stream (`text/event-stream`).","headers":{"x-tokens-request-id":{"schema":{"type":"string"},"description":"Quote it to support."}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OpenAIObject"}},"text/event-stream":{"schema":{"type":"string"}}}},"400":{"description":"invalid_request: no model, not JSON, or the upstream rejected the body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"missing_api_key or invalid_api_key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"insufficient_credits, no_funding or outstanding_debt","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"The key may not do this: key_inactive, key_expired, model_not_allowed_on_key, monthly_spend_cap_exceeded, tier_permission_denied or account_suspended","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"model_not_found or unsupported_endpoint","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"rate_limited, concurrency_limit, window_exhausted or model_limit_reached. Wait Retry-After seconds.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal error. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"502":{"description":"upstream_unreachable. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/responses":{"post":{"summary":"Responses API","description":"OpenAI's Responses API, for tools such as Codex CLI. Works when the model's upstream supports it.","security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/ResponsesRequest"},"example":{"model":"deepseek/deepseek-v4.1-flash","input":"What does HTTP 429 mean?"}}}},"responses":{"200":{"description":"The response. With `stream: true` it is a Server-Sent Events stream (`text/event-stream`).","headers":{"x-tokens-request-id":{"schema":{"type":"string"},"description":"Quote it to support."}},"content":{"application/json":{"schema":{"$ref":"#/components/schemas/OpenAIObject"}},"text/event-stream":{"schema":{"type":"string"}}}},"400":{"description":"invalid_request: no model, not JSON, or the upstream rejected the body","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"401":{"description":"missing_api_key or invalid_api_key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"402":{"description":"insufficient_credits, no_funding or outstanding_debt","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"403":{"description":"The key may not do this: key_inactive, key_expired, model_not_allowed_on_key, monthly_spend_cap_exceeded, tier_permission_denied or account_suspended","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"404":{"description":"model_not_found or unsupported_endpoint","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"429":{"description":"rate_limited, concurrency_limit, window_exhausted or model_limit_reached. Wait Retry-After seconds.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"500":{"description":"Internal error. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}},"502":{"description":"upstream_unreachable. Retry with backoff.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/models":{"get":{"summary":"List the models this key can call","description":"Filtered by the key's allowed models, your plan and your wallet. Not billed.","security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"responses":{"200":{"description":"The models","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ModelList"}}}},"401":{"description":"missing_api_key or invalid_api_key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}},"/v1/tokens/usage":{"get":{"summary":"Remaining plan windows, wallet balance and key limits","description":"Specific to Tokens. Not billed and not counted toward your request limit.","security":[{"bearerAuth":[]},{"apiKeyHeader":[]}],"responses":{"200":{"description":"The key's usage","content":{"application/json":{"schema":{"$ref":"#/components/schemas/TokensUsage"}}}},"401":{"description":"missing_api_key or invalid_api_key","content":{"application/json":{"schema":{"$ref":"#/components/schemas/Error"}}}}}}}},"components":{"securitySchemes":{"bearerAuth":{"type":"http","scheme":"bearer","description":"Authorization: Bearer <key>"},"apiKeyHeader":{"type":"apiKey","in":"header","name":"x-api-key","description":"The same key, for Anthropic-style tools"}},"schemas":{"Error":{"type":"object","required":["error"],"properties":{"error":{"type":"object","properties":{"message":{"type":"string"},"type":{"type":"string","description":"authentication_error, permission_denied_error, insufficient_quota, rate_limit_error, invalid_request_error, api_error, server_error or tokens_error"},"code":{"type":"string","description":"Stable and machine-readable. Branch on this."},"param":{"type":["string","null"]},"request_id":{"type":"string","description":"Same as the x-tokens-request-id header."}}}}},"OpenAIObject":{"type":"object","description":"A response in the provider's own format, passed through.","additionalProperties":true},"ChatCompletionRequest":{"type":"object","description":"OpenAI chat completions request.","additionalProperties":true,"required":["model","messages"],"properties":{"model":{"type":"string","description":"A catalog id such as provider/model. See GET /v1/models."},"messages":{"type":"array","items":{"type":"object","additionalProperties":true}},"stream":{"type":"boolean"},"max_tokens":{"type":"integer"},"temperature":{"type":"number"},"tools":{"type":"array","items":{"type":"object","additionalProperties":true}},"tool_choice":{},"response_format":{"type":"object","additionalProperties":true},"stream_options":{"type":"object","description":"Set include_usage to true for a usage chunk at the end of a stream.","additionalProperties":true}}},"CompletionRequest":{"type":"object","description":"Legacy completions request.","additionalProperties":true,"required":["model","prompt"],"properties":{"model":{"type":"string"},"prompt":{"type":["string","array"]},"max_tokens":{"type":"integer"},"stream":{"type":"boolean"}}},"MessagesRequest":{"type":"object","description":"Anthropic Messages request.","additionalProperties":true,"required":["model","max_tokens","messages"],"properties":{"model":{"type":"string"},"max_tokens":{"type":"integer"},"messages":{"type":"array","items":{"type":"object","additionalProperties":true}},"system":{"type":["string","array"]},"stream":{"type":"boolean"},"tools":{"type":"array","items":{"type":"object","additionalProperties":true}}}},"EmbeddingsRequest":{"type":"object","description":"OpenAI embeddings request.","additionalProperties":true,"required":["model","input"],"properties":{"model":{"type":"string"},"input":{"type":["string","array"]}}},"ResponsesRequest":{"type":"object","description":"OpenAI Responses request.","additionalProperties":true,"required":["model","input"],"properties":{"model":{"type":"string"},"input":{"type":["string","array"]},"stream":{"type":"boolean"}}},"ModelList":{"type":"object","properties":{"object":{"const":"list"},"data":{"type":"array","items":{"type":"object","properties":{"id":{"type":"string","description":"Send this as `model`."},"object":{"const":"model"},"created":{"type":"integer"},"owned_by":{"type":"string"}},"additionalProperties":true}}}},"TokensUsage":{"type":"object","properties":{"object":{"const":"tokens.usage"},"plan":{"type":["object","null"],"properties":{"name":{"type":"string"},"tier":{"type":"string"},"periodEnd":{"type":["string","null"],"format":"date-time"}}},"windows":{"type":"array","items":{"type":"object","properties":{"type":{"enum":["session_5h","weekly","monthly"]},"label":{"type":"string"},"unit":{"enum":["usd","requests"]},"limit":{"type":"number"},"used":{"type":"number"},"remaining":{"type":"number"},"percentUsed":{"type":"integer"},"resetsAt":{"type":"string","format":"date-time"}}}},"wallet":{"type":["object","null"],"properties":{"balanceUsd":{"type":["number","null"]}}},"key":{"type":"object","properties":{"monthlySpendCapUsd":{"type":["number","null"]},"allowedModels":{"type":["array","null"],"items":{"type":"string"}}}}}}}}}