Quickstart

Prerequisites

ItemValue
API keyJOY_TOKEN_API_KEY
API Base URLJOY_TOKEN_API_BASE_URL from Environments
OpenAI Base URLJOY_TOKEN_OPENAI_BASE_URL from Environments
Modelauto
TypeScriptNode.js 18+
GoGo 1.22+

Step 1: Set the Environment

$export JOY_TOKEN_API_KEY="jt_xxx"
$export JOY_TOKEN_API_BASE_URL="https://api-dev.joytokens.ai"
$export JOY_TOKEN_OPENAI_BASE_URL="https://api-dev.joytokens.ai/openai/v1"

Step 2: Install an SDK

TypeScript:

$npm install @joytoken/client-sdk-ts

Go:

$go get github.com/joytoken/client-sdk-golang

Step 3: Make a Request

TypeScript:

1import { JoyTokenClient } from "@joytoken/client-sdk-ts";
2
3const joytoken = new JoyTokenClient({
4 apiKey: process.env.JOY_TOKEN_API_KEY,
5 apiBaseUrl: process.env.JOY_TOKEN_API_BASE_URL,
6 openAIBaseUrl: process.env.JOY_TOKEN_OPENAI_BASE_URL,
7});
8
9const completion = await joytoken.chat.completions.create({
10 model: "auto",
11 messages: [{ role: "user", content: "Reply with exactly: pong" }],
12});
13
14console.log(completion.choices[0]?.message?.content);

Go:

1client := joytoken.NewClient(
2 joytoken.WithAPIKey(os.Getenv("JOY_TOKEN_API_KEY")),
3 joytoken.WithAPIBaseURL(os.Getenv("JOY_TOKEN_API_BASE_URL")),
4 joytoken.WithOpenAIBaseURL(os.Getenv("JOY_TOKEN_OPENAI_BASE_URL")),
5)
6
7completion, err := client.CreateChatCompletion(ctx, joytoken.ChatCompletionRequest{
8 Model: "auto",
9 Messages: []joytoken.ChatMessage{
10 {Role: "user", Content: "Reply with exactly: pong"},
11 },
12})
13if err != nil {
14 return err
15}
16fmt.Println(completion.Choices[0].Message.Content)

Step 4: Check the Result

PlaceExpected result
Program outputpong
JoyToken LogsRequest path is /openai/v1/chat/completions
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