编码 Agent 使用

当你希望 Codex、Claude Code、OpenClaw、Hermes 或其他编码 Agent 修改接入 JoyToken 客户端 SDK 的应用代码时,可以把本页作为上下文。

Agent 需要知道什么

主题指令
包选择TypeScript 项目使用 @joytoken/client-sdk-ts,Go 项目使用 github.com/joytoken/client-sdk-golang
API Key从服务端环境变量 JOY_TOKEN_API_KEY 读取
模型默认使用 auto;只有工作流需要固定模型时才使用具体 JoyToken 模型 key
流式响应metadata 的分块是观测数据,不是 assistant 文本
错误TypeScript 处理 JoyTokenAPIError,Go 处理 APIError
浏览器代码不要把 JoyToken API Key 放进前端包

TypeScript Prompt 片段

agent-instructions.md
Use @joytoken/client-sdk-ts for JoyToken model calls.
Create a JoyTokenClient with JOY_TOKEN_API_KEY from server-side env.
Use chat.completions.create() for non-streaming calls.
Use chat.completions.stream() for SSE streaming.
Do not expose JOY_TOKEN_API_KEY in browser code.
Handle JoyTokenAPIError and log status, requestId, and body.

Go Prompt 片段

agent-instructions.md
Use github.com/joytoken/client-sdk-golang for JoyToken model calls.
Create a client with joytoken.NewClient(joytoken.WithAPIKey(os.Getenv("JOY_TOKEN_API_KEY"))).
Use CreateChatCompletion for non-streaming calls.
Use StreamChatCompletion for SSE streaming and close the stream.
Handle *joytoken.APIError with errors.As.

代码审查清单

检查为什么重要
API Key 只在服务端避免密钥泄露
Request ID方便关联网关日志、用量和应用日志
流式元数据处理避免 metadata JSON 出现在 UI 中
错误分类区分策略、额度、认证和提供方错误
模型选择除非工作流需要固定模型,否则保持路由灵活

编码 Agent 产品本身的配置放在实战指南。本页只说明 Agent 修改 JoyToken 客户端 SDK 代码时应遵守的约束。