Integrate 200+ LLMs with one TypeScript SDK using OpenAI's format. Free and open source. No proxy server required.
Features
Use OpenAI's format to call 200+ LLMs from 10 providers.
Supports tools, JSON outputs, image inputs, streaming, and more.
Runs completely on the client side. No proxy server needed.
Free and open source under MIT.
Supported Providers
AI21
Anthropic
AWS Bedrock
Cohere
Gemini
Groq
Mistral
OpenAI
Perplexity
OpenRouter
Any other model provider with an OpenAI compatible API
Setup
Installation
npm install token.js
pnpm install token.js
yarn add token.js
bun add token.js
Usage
Import the Token.js client and call the create function with a prompt in OpenAI's format. Specify the model and LLM provider using their respective fields.
.env
OPENAI_API_KEY=<openai api key>
import { TokenJS } from 'token.js'
// Create the Token.js client
const tokenjs = new TokenJS()
async function main() {
// Create a model response
const completion = await tokenjs.chat.completions.create({
// Specify the provider and model
provider: 'openai',
model: 'gpt-4o',
// Define your message
messages: [
{
role: 'user',
content: 'Hello!',
},
],
})
console.log(completion.choices[0])
}
main()
.env
ANTHROPIC_API_KEY=<anthropic api key>
import { TokenJS } from 'token.js'
// Create the Token.js client
const tokenjs = new TokenJS()
async function main() {
// Create a model response
const completion = await tokenjs.chat.completions.create({
// Specify the provider and model
provider: 'anthropic',
model: 'claude-3-sonnet-20240229',
// Define your message
messages: [
{
role: 'user',
content: 'Hello!',
},
],
})
console.log(completion.choices[0])
}
main()
.env
GEMINI_API_KEY=<gemini api key>
import { TokenJS } from 'token.js'
// Create the Token.js client
const tokenjs = new TokenJS()
async function main() {
// Create a model response
const completion = await tokenjs.chat.completions.create({
// Specify the provider and model
provider: 'gemini',
model: 'gemini-1.5-pro',
// Define your message
messages: [
{
role: 'user',
content: 'Hello!',
},
],
})
console.log(completion.choices[0])
}
main()