AllToken Node.js SDK
Official TypeScript/JavaScript SDK with typed OpenAI and Anthropic surfaces.
Installation
npm
$ npm install @alltoken/aiRequires Node.js 18+. Also works in Deno, Bun, and Cloudflare Workers.
Quick start
One API key gives you both OpenAI-compatible and Anthropic-compatible endpoints:
TypeScript
| 1 | import { AllToken } from '@alltoken/ai'; |
| 2 | |
| 3 | const client = new AllToken({ apiKey: process.env.ALLTOKEN_API_KEY! }); |
| 4 | |
| 5 | // OpenAI-compatible (maps to /v1) |
| 6 | const { data } = await client.openai.raw.POST('/chat/completions', { |
| 7 | body: { |
| 8 | model: 'gpt-4o', |
| 9 | messages: [{ role: 'user', content: 'Hello!' }], |
| 10 | }, |
| 11 | }); |
| 12 | |
| 13 | // Anthropic-compatible (maps to /anthropic) |
| 14 | const { data: msg } = await client.anthropic.raw.POST('/messages', { |
| 15 | body: { |
| 16 | model: 'claude-sonnet-4', |
| 17 | max_tokens: 1024, |
| 18 | messages: [{ role: 'user', content: 'Hello!' }], |
| 19 | }, |
| 20 | }); |
Configuration
TypeScript
| 1 | new AllToken({ |
| 2 | apiKey: '...', // required |
| 3 | baseURL: 'https://api.alltoken.ai', // optional |
| 4 | fetch: customFetch, // optional |
| 5 | defaultHeaders: { 'X-My-Tag': 'a' }, // optional |
| 6 | }); |
API surface
.raw is a typed openapi-fetch client. All routes, request bodies, and response types are auto-generated from the OpenAPI specs with full IDE autocomplete.
| Field | Base URL |
|---|---|
client.openai.raw | https://api.alltoken.ai/v1 |
client.anthropic.raw | https://api.alltoken.ai/anthropic |