Quickstart

Get a single request running end-to-end. For the full catalog of runnable snippets (streaming, Anthropic, model list, error handling), see Examples.

Prerequisites

ItemValue
API keyJOY_TOKEN_API_KEY
API Base URLJOY_TOKEN_API_BASE_URL from Environments
Modelauto (not configurable)
TypeScriptNode.js 18+
GoGo 1.22+

Step 1: Set the environment

export JOY_TOKEN_API_KEY="sk-xxx"
export JOY_TOKEN_OPENAI_BASE_URL="https://api.joytokens.ai/openai/v1"

Both SDKs default to a 60-second request/stream timeout. Override it only when a workload needs a different limit �?TypeScript timeoutMs, Go WithTimeout.

Step 2: Install

TypeScript is distributed from GitHub, not the npm registry. Add the package subdirectory to package.json:

{
"type": "module",
"dependencies": {
"@joytoken/client-sdk-ts": "git+https://github.com/jd-opensource/joytoken-sdk-ts.git#path:/client-sdk-ts"
}
}
pnpm install

Pin a release tag or commit for reproducible builds instead of following the default branch.

Step 3: Make your first request

import { JoyTokenClient } from "@joytoken/client-sdk-ts";
const apiKey = process.env.JOY_TOKEN_API_KEY;
if (!apiKey) throw new Error("JOY_TOKEN_API_KEY is required");
const joytoken = new JoyTokenClient({
apiKey,
openAIBaseUrl: process.env.JOY_TOKEN_OPENAI_BASE_URL,
});
const completion = await joytoken.chat.completions.create({
model: "auto",
messages: [{ role: "user", content: "Reply with exactly: pong" }],
});
console.log(completion.choices[0]?.message?.content);

Verify the result

PlaceExpected result
Program outputpong
JoyToken LogsRequest reaches the OpenAI Chat Completions endpoint
JoyToken UsageTokens and credits are recorded

Common errors

ErrorFix
401 UnauthorizedCheck that JOY_TOKEN_API_KEY exists and is complete
403 ForbiddenCheck whether the API key policy allows auto or the target model
402 insufficient_quotaCheck wallet balance and key budget
TimeoutIncrease the SDK timeout or check connectivity to the selected environment

Next steps