API Reference

JoyToken currently exposes an OpenAI-compatible model gateway for developers. Applications can keep using OpenAI SDKs, LangChain, Cursor, Claude Code, Codex CLI, and other OpenAI-compatible tools. JoyToken adds API key validation, policy constraints, model routing, wallet freeze, and usage recording at the gateway layer.

This page only describes public interfaces that are present in the current project. Console, API key management, policy configuration, billing management, and similar backend APIs are currently used by JoyToken Console and are not documented as stable developer APIs.

Base URLs

ScenarioBase URL
OpenAI-compatible model callshttps://api-dev.joytokens.ai/openai/v1
Public model cataloghttps://api-dev.joytokens.ai

Authentication

Model calls require a JoyToken API key. Use the Authorization header because it matches OpenAI SDKs and common AI tool configuration.

Recommended
Authorization: Bearer $JOY_TOKEN_API_KEY

The gateway currently also accepts X-API-Key, mainly for legacy clients and hand-written HTTP calls.

Compatibility
X-API-Key: $JOY_TOKEN_API_KEY

If both headers are present, the current gateway reads X-API-Key first. When migrating to Bearer authentication, do not keep the old X-API-Key on the same request.

Current Public Endpoints

EndpointAPI key requiredPurpose
POST /openai/v1/chat/completionsYesOpenAI-compatible Chat Completions, with non-streaming and SSE streaming support
GET /api/v1/modelsNoPublic model catalog for the model marketplace, model picker, and integration discovery

Request Headers

HeaderRequiredDescription
AuthorizationRequired for model callsBearer $JOY_TOKEN_API_KEY
X-API-KeyOptionalCompatibility authentication header; not recommended for new integrations
Content-TypeRecommendedapplication/json
X-Request-IDOptionalUsed for logs, billing troubleshooting, and trace correlation; when absent, the gateway generates an internal request ID

Response Headers

HeaderScenarioDescription
X-DAOE-Used-ModelSuccessful model callActual model used
X-DAOE-Used-ProviderSuccessful model callProvider that served the request
X-DAOE-FailoverStreaming call with provider failover1 means provider failover occurred

Response Metadata

For non-streaming successful calls, the gateway merges JoyToken metadata into the OpenAI-compatible JSON metadata field when possible. For streaming calls, it appends a metadata SSE record before [DONE].

Common fields:

FieldDescription
modelJoyToken-selected model
tierActual billing/routing tier
scoreRouter score
model_recommendationCandidate model recommendation details, when returned by router
latencyRouting, provider, and streaming stage latency
billing.credits_usedCredits calculated for this request
billing.input_tokens / billing.output_tokensInput/output tokens used for billing

Error Shape

Model call errors use an OpenAI-compatible structure:

Error response
1{
2 "error": {
3 "message": "missing api key",
4 "type": "missing_api_key"
5 }
6}

When debugging, record X-Request-ID, request model / tier, HTTP status, error.type, and on successful responses the X-DAOE-Used-Model and X-DAOE-Used-Provider headers.