Quickstart
Prerequisites
| Item | Value |
|---|---|
| API key | JOY_TOKEN_API_KEY |
| API Base URL | JOY_TOKEN_API_BASE_URL from Environments |
| OpenAI Base URL | JOY_TOKEN_OPENAI_BASE_URL from Environments |
| Model | auto |
| TypeScript | Node.js 18+ |
| Go | Go 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:
1 import { JoyTokenClient } from "@joytoken/client-sdk-ts"; 2 3 const 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 9 const completion = await joytoken.chat.completions.create({ 10 model: "auto", 11 messages: [{ role: "user", content: "Reply with exactly: pong" }], 12 }); 13 14 console.log(completion.choices[0]?.message?.content);
Go:
1 client := 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 7 completion, err := client.CreateChatCompletion(ctx, joytoken.ChatCompletionRequest{ 8 Model: "auto", 9 Messages: []joytoken.ChatMessage{ 10 {Role: "user", Content: "Reply with exactly: pong"}, 11 }, 12 }) 13 if err != nil { 14 return err 15 } 16 fmt.Println(completion.Choices[0].Message.Content)
Step 4: Check the Result
| Place | Expected result |
|---|---|
| Program output | pong |
| JoyToken Logs | Request path is /openai/v1/chat/completions |
| JoyToken Usage | Tokens and credits are recorded |
Common Errors
| Error | Fix |
|---|---|
401 Unauthorized | Check that JOY_TOKEN_API_KEY exists and is complete |
403 Forbidden | Check whether the API key policy allows auto or the target model |
402 insufficient_quota | Check wallet balance and key budget |
| Timeout | Increase the SDK timeout or check connectivity to the selected environment |