TypeScript SDK
@joytoken/client-sdk-ts is a type-safe client for JoyToken’s public developer API. It is designed for server-side JavaScript runtimes: Node.js services, Next.js route handlers, workers, and agent runtimes.
Why use the TypeScript SDK
The SDK gives you a small layer over JoyToken’s API without changing the underlying Chat Completions contract.
Install
Configure
client.ts
Defaults:
Chat Completions
chat.ts
Streaming
stream.ts
JoyToken appends a metadata event near the end of streaming responses. Treat chunks with metadata as observability data, not assistant text.
Models
models.ts
Error handling
errors.ts
Next.js route example
app/api/chat/route.ts
Keep JoyToken API keys on the server side. Do not expose JOY_TOKEN_API_KEY in browser code.