Quickstart

Prerequisites

ItemValue
Node.js18+
API keyJOY_TOKEN_API_KEY
Modelauto

Step 1: Install

$npm install @joytoken/agent-sdk-ts

Step 2: Set the API Key

$export JOY_TOKEN_API_KEY="jt_xxx"

Step 3: Create an Agent

1import { Agent, createJoyTokenProvider, stepCountIs } from "@joytoken/agent-sdk-ts";
2
3const agent = new Agent({
4 model: createJoyTokenProvider(),
5 modelName: "auto",
6 system: "You are a concise assistant.",
7 stopWhen: [stepCountIs(4)],
8});
9
10const result = await agent.run("Reply with exactly: pong");
11
12console.log(result.finalText);
13console.log(result.usage.totalTokens);

Step 4: Check the Result

PlaceExpected result
Program outputpong
JoyToken LogsRequest path is /openai/v1/chat/completions
JoyToken UsageTokens and credits are attributed to this key

Common Errors

ErrorFix
401 UnauthorizedCheck JOY_TOKEN_API_KEY
Agent does not stopAdd stepCountIs or maxToolCalls
finalText is emptyCheck whether the model returned a tool call, or inspect result.messages

Next Steps