快速开始

前提条件

项目
Node.js18+
API KeyJOY_TOKEN_API_KEY
模型auto

第 1 步:安装

$npm install @joytoken/agent-sdk-ts

第 2 步:设置 API Key

$export JOY_TOKEN_API_KEY="jt_xxx"

第 3 步:创建 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);

第 4 步:检查结果

位置应看到
程序输出pong
JoyToken Logs请求路径是 /openai/v1/chat/completions
JoyToken Usagetokens 和 credits 归因到这把 Key

常见错误

错误处理方式
401 Unauthorized检查 JOY_TOKEN_API_KEY
agent 没有停止添加 stepCountIsmaxToolCalls
finalText 为空检查模型是否返回 tool call,或查看 result.messages

下一步