# TokenDance API integration guide Documentation: https://tokendance.delia.love/docs/ Machine-readable guide: https://tokendance.delia.love/llms.txt OpenAPI specification: https://tokendance.delia.love/openapi.json ## Client configuration Protocols: OpenAI-compatible Chat Completions and Anthropic-compatible Messages. Choose the protocol required by the client. Claude Code uses the Messages instructions below. Base URL: https://tokendance.delia.love/v1 Authentication: Authorization: Bearer . Messages also accepts x-api-key. The user provides a TokenDance relay key. It is NOT a DeepSeek key and NOT an admin key. Store it in the client's secret settings or an environment variable; never put it in a URL. The documentation is public; all /v1 endpoints require a relay key. For clients exposing fields: provider=OpenAI compatible, base URL=https://tokendance.delia.love/v1, API key=, model=. For clients requiring a full endpoint URL: https://tokendance.delia.love/v1/chat/completions. Avoid appending /v1 twice. Environment variable names are client-specific: TOKENDANCE_API_KEY is used below; OPENAI_API_KEY / OPENAI_BASE_URL work only if the client reads them. ## Model discovery GET https://tokendance.delia.love/v1/models with the Authorization header. Use the exact id returned in data[].id. Current DeepSeek examples include deepseek-flash and deepseek-v4-pro; the live model list is authoritative. If configuration permits only one model, use deepseek-flash after confirming it appears in the list. ## Chat completion POST https://tokendance.delia.love/v1/chat/completions Content-Type: application/json Authorization: Bearer Example JSON: {"model":"deepseek-flash","messages":[{"role":"user","content":"Reply with OK"}],"stream":false} The response follows OpenAI Chat Completions: choices[].message.content, usage, and choices[].finish_reason. Upstream reasoning_content and tool_calls are preserved. Model-specific parameters (e.g. thinking, reasoning_effort, tools) pass through unchanged. Only use parameters supported by the selected upstream model. ## Streaming Set stream=true. The response is text/event-stream, using data: events and data: [DONE] at completion. Join choices[].delta.content to reconstruct output. Preserve reasoning_content and incremental tool_calls separately if the client supports them. Token usage may appear in the final event; do not assume each event has content. HTTP success does not by itself guarantee the stream completed; handle missing [DONE] and stream errors. ## Python (OpenAI SDK) import os from openai import OpenAI client = OpenAI(api_key=os.environ["TOKENDANCE_API_KEY"], base_url="https://tokendance.delia.love/v1") models = client.models.list() response = client.chat.completions.create( model="deepseek-flash", messages=[{"role": "user", "content": "Reply with OK"}], ) print(response.choices[0].message.content) ## JavaScript (OpenAI SDK) import OpenAI from "openai"; const client = new OpenAI({ apiKey: process.env.TOKENDANCE_API_KEY, baseURL: "https://tokendance.delia.love/v1", }); const response = await client.chat.completions.create({ model: "deepseek-flash", messages: [{ role: "user", content: "Reply with OK" }], }); console.log(response.choices[0].message.content); ## Claude Code CLI / Anthropic Messages Install the official CLI using its current official installation instructions: https://code.claude.com/docs/en/setup The npm distribution can be installed with: npm install -g @anthropic-ai/claude-code Check that the installed executable works with: claude --version Configure these values in the terminal environment (or merge the equivalent env block into the user's existing Claude Code settings without discarding unrelated settings): export ANTHROPIC_BASE_URL="https://tokendance.delia.love" export ANTHROPIC_API_KEY="$TOKENDANCE_API_KEY" export ANTHROPIC_MODEL="deepseek-flash" export ANTHROPIC_DEFAULT_HAIKU_MODEL="deepseek-flash" export ANTHROPIC_DEFAULT_SONNET_MODEL="deepseek-flash" export ANTHROPIC_DEFAULT_OPUS_MODEL="deepseek-flash" export CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1 ANTHROPIC_BASE_URL is the domain ROOT: do not append /v1 or /anthropic. ANTHROPIC_API_KEY is the user's TokenDance relay key, never the upstream DeepSeek key. If ANTHROPIC_AUTH_TOKEN is already set for another service, resolve that conflict for this session; do not silently overwrite a user's unrelated provider configuration. Clients using ANTHROPIC_AUTH_TOKEN instead send Authorization: Bearer . PowerShell users must set the same environment variables using PowerShell syntax. Verify with: claude -p "Reply with exactly: TOKENDANCE_OK" --model deepseek-flash Then start interactive mode in the intended local project with: claude --model deepseek-flash Use normal tool permissions; a working gateway does not require bypassing permissions. POST https://tokendance.delia.love/v1/messages (also accepts ?beta=true) x-api-key: or Authorization: Bearer anthropic-version: 2023-06-01 Content-Type: application/json Example body: {"model":"deepseek-flash","max_tokens":256,"messages":[{"role":"user","content":"Reply with OK"}],"stream":true} This route forwards to DeepSeek's native Anthropic-compatible endpoint, preserving system, tools, tool_choice, tool_use, tool_result and thinking content blocks. The client executes local tools; the gateway forwards the resulting next-turn messages and records the traffic. Messages SSE uses event/data pairs, ends with message_delta then message_stop, and has no [DONE]. Usage has input_tokens/output_tokens, merged from message_start and message_delta. Both anthropic-version and anthropic-beta headers pass through unchanged. GET /v1/models also accepts x-api-key. HEAD /api/hello returns 204 for connection warming. The optional /v1/messages/count_tokens endpoint returns 404; Claude Code estimates locally. The CLI is Claude Code, but the model behind this gateway is DeepSeek, NOT Claude. Use explicit DeepSeek model IDs. DeepSeek can map claude-opus* aliases to deepseek-v4-pro and other claude* aliases to deepseek-flash; these are upstream aliases and do not provide Claude. This is third-party compatibility, not an Anthropic-supported non-Claude configuration. DeepSeek may ignore or reject advanced Claude-only features; do not promise feature parity. ## Other configured upstreams By default requests route to DeepSeek. Additional upstreams must first be configured by the gateway owner. To select one, use model="provider-id::real-model-id" or the X-Tokendance-Provider header. GET /v1/models?provider=provider-id queries that provider. Do not guess provider IDs. The prefix is removed before forwarding the request upstream. Messages requires that provider's anthropicBaseUrl to be configured; Chat Completions-only upstreams are not automatically converted into Anthropic endpoints. ## Errors and limits 401: missing/invalid relay key. 400: invalid JSON/parameters/provider. 413: request body exceeds 8 MiB. 429: upstream rate limit; respect Retry-After when present. 502: upstream/network failure. 503: service/configuration unavailable. 504: upstream timeout. Other upstream HTTP statuses and error bodies pass through. Responses include X-Tokendance-Request-Id for trace correlation. Default upstream timeout is 10 minutes; clients should set an appropriate timeout. The gateway does not automatically retry requests. Avoid blind retries that can incur duplicate charges. ## Compatibility boundaries Supported: GET /v1/models, POST /v1/chat/completions, POST /v1/messages, JSON and SSE. Not implemented: /v1/responses, /v1/messages/count_tokens, embeddings, image/audio/file APIs, Azure-specific deployment routes, OAuth login, automatic protocol conversion. Clients that require OpenAI Responses (including configurations that cannot select Chat Completions) cannot connect directly using this version of the gateway. Claude Code uses /v1/messages. Inspect the client's supported protocols before changing its configuration. ## Trace storage and privacy Calls are forwarded immediately; complete API request/response bodies and metadata are recorded asynchronously in the owner's D1 database. HTTP credential headers are redacted; body contents are preserved. Records are best effort and may be incomplete on storage failures. The private workspace at https://tokendance.delia.love/ requires a separate admin key. Relay keys grant model usage but cannot read private trace endpoints. The guide and OpenAPI schema contain no keys. Do not send a user's key to documentation endpoints or any third-party host; send it only in the Authorization header of this gateway's API.