Authentication
JoyToken’s OpenAI-compatible API uses API key authentication. The model invocation entry point is POST /openai/v1/chat/completions. The gateway validates the key before policy checks, routing, wallet freeze, provider invocation, usage recording, and billing attribution.
API keys represent real wallet credits and policy permissions. Do not put plaintext keys in browsers, mobile bundles, public repositories, logs, or issue screenshots. Production requests should originate from your server.
Use an API Key
New integrations should use Authorization: Bearer:
If you already use the OpenAI SDK, only replace apiKey and baseURL:
Headers
X-API-Key is a compatibility path, not the preferred default for new projects. Standardizing on Bearer tokens reduces special handling in proxies and SDKs.
Gateway Validation Flow
api-gateway extracts the plaintext key from request headers and validates it through apikey-service ValidateApiKey. Only after validation does the gateway build policy, call the router, and invoke the provider.
The validation result is used for routing and billing:
Policy and Wallet Checks
Successful authentication does not guarantee execution. The gateway continues checking:
Error responses keep the OpenAI-compatible shape:
Governance Signals
Successful responses preserve OpenAI-compatible choices and usage. JoyToken adds headers and metadata:
Non-streaming responses merge metadata into the JSON body. Streaming responses append a metadata event before [DONE]:
Server-Side Proxy
Browsers and mobile clients should not hold JoyToken API keys. Send requests to your backend and inject the key there:
In production, do not let clients submit arbitrary apiKey values. If you need multi-tenant billing, choose the JoyToken key on your server based on user, team, or project.
Rotate API Keys
- Create a new key with the same or stricter policy.
- Write the new key to your server-side secret manager or environment variables.
- Send a validation request with a new
X-Request-ID. - Confirm that the new key has traffic in JoyToken Logs / Usage.
- Disable or revoke the old key.
- Check for old-key failure logs during the transition window.
Security Guidance
- Use a separate key per application, environment, and agent workflow.
- Bind production keys to budget, tier, model policy, and IP allowlists when needed.
- Do not put keys in frontend
.env, browser localStorage, mobile bundles, or logs. - Send
X-Request-IDfor high-risk agent calls, including workflow ID and step ID. - If a key leaks, revoke it, create a new key, and inspect Usage and Billing.