### Install Token.js SDK Source: https://github.com/token-js/token.js/blob/main/docs/README.md Instructions for installing the Token.js SDK using various Node.js package managers. ```bash npm install token.js ``` ```bash pnpm install token.js ``` ```bash yarn add token.js ``` ```bash bun add token.js ``` -------------------------------- ### Install Token.js project dependencies Source: https://github.com/token-js/token.js/blob/main/CONTRIBUTING.md After cloning, navigate into the `token-js` directory. This command uses `pnpm` to install all required project dependencies, preparing the environment for development. ```bash cd token-js && pnpm install ``` -------------------------------- ### Install Token.js via npm Source: https://github.com/token-js/token.js/blob/main/README.md This command installs the Token.js SDK using npm, making it available for use in your project. ```bash npm install token.js ``` -------------------------------- ### Perform Basic LLM Chat Completion Source: https://github.com/token-js/token.js/blob/main/README.md This example demonstrates how to initialize the Token.js client and perform a basic chat completion using an OpenAI model. It shows how to specify the provider, model, and user message for a simple interaction. ```ts 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() ``` -------------------------------- ### Streaming Responses with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md This example demonstrates how to implement streaming responses using the Token.js library. It initializes Token.js, creates a chat completion request with `stream: true`, and then iterates over the asynchronous parts of the response to print them to the console. ```ts import { TokenJS } from 'token.js' const tokenjs = new TokenJS() async function main() { const result = await tokenjs.chat.completions.create({ stream: true, provider: 'openai', model: 'gpt-4o', messages: [ { role: 'user', content: `Tell me about yourself.`, }, ], }) for await (const part of result) { process.stdout.write(part.choices[0]?.delta?.content || '') } } main() ``` -------------------------------- ### TypeScript Chat Completion with Gemini using Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/gemini.md This TypeScript example demonstrates how to use the Token.js client to perform a chat completion using a Gemini model. It initializes the client, specifies the 'gemini-1.5-pro' model, and sends a 'Hello!' message to get a response from the AI. ```typescript 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() ``` -------------------------------- ### Create OpenAI Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/openai.md This TypeScript example demonstrates how to initialize the Token.js client and use it to create a chat completion with an OpenAI model (e.g., gpt-4o). It shows how to specify the provider, model, and user messages, then logs the completion result. ```typescript 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() ``` -------------------------------- ### Perform Chat Completion with Groq and Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/groq.md This TypeScript example demonstrates the full workflow for creating a chat completion using Token.js with a Groq model. It shows how to import the library, instantiate the client, specify the Groq provider and a model like `llama3-70b-8192`, define user messages, and log the response. ```typescript 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: 'groq', model: 'llama3-70b-8192', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### TypeScript Chat Completion with Token.js and Cohere Source: https://github.com/token-js/token.js/blob/main/docs/providers/cohere.md This TypeScript example demonstrates how to initialize the Token.js client, specify Cohere as the provider, and use the 'command-r-plus' model to create a chat completion. It includes a basic user message and logs the first choice of the completion response. ```typescript 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: 'cohere', model: 'command-r-plus', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Create OpenRouter Chat Completion with Token.js (TypeScript) Source: https://github.com/token-js/token.js/blob/main/docs/providers/openrouter.md This TypeScript example demonstrates initializing the Token.js client and making a chat completion request to OpenRouter. It specifies the provider, model, and a user message, then logs the first choice of the completion. ```typescript import { TokenJS } from 'token.js'\n\n// Create the Token.js client\nconst tokenjs = new TokenJS()\n\nasync function main() {\n // Create a model response\n const completion = await tokenjs.chat.completions.create({\n // Specify the provider and model\n provider: 'openrouter',\n model: 'nvidia/nemotron-4-340b-instruct',\n // Define your message\n messages: [\n {\n role: 'user',\n content: 'Hello!',\n },\n ],\n })\n console.log(completion.choices[0])\n}\nmain() ``` -------------------------------- ### Integrate Perplexity Chat Completions with Token.js in TypeScript Source: https://github.com/token-js/token.js/blob/main/docs/providers/perplexity.md This TypeScript example demonstrates how to initialize the Token.js client, create a chat completion request using the Perplexity provider and a specified model (e.g., 'llama-3-70b-instruct'), and log the response. It showcases basic API interaction for generating AI responses. ```typescript 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: 'perplexity', model: 'llama-3-70b-instruct', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Create Anthropic Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/anthropic.md This TypeScript example demonstrates how to use Token.js to create a chat completion request with an Anthropic model. It initializes the Token.js client, specifies the provider and model, and sends a user message to get a response. ```typescript 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() ``` -------------------------------- ### Integrate Token.js with OpenAI-compatible Provider Source: https://github.com/token-js/token.js/blob/main/docs/providers/openai-compatible.md This example demonstrates using Ollama running locally with Token.js. It shows how to create the Token.js client, specify a custom baseURL for the OpenAI v1 API compatible provider, and make a chat completion request. ```typescript import { TokenJS } from 'token.js' // Create the Token.js client and specify the baseURL for the OpenAI v1 API compatible provider const tokenjs = new TokenJS({ baseURL: 'http://127.0.0.1:11434/v1/', }) async function main() { // Create a model response const completion = await tokenjs.chat.completions.create({ // Specify the provider and model provider: 'openai-compatible', model: 'llama3.2', // Define your messages messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Integrate AWS Bedrock with Token.js for Chat Completions Source: https://github.com/token-js/token.js/blob/main/docs/providers/bedrock.md This TypeScript example demonstrates how to use Token.js to interact with AWS Bedrock for chat completions. It initializes the Token.js client, specifies the 'bedrock' provider and a Llama 3 model, and sends a user message to get a response. ```typescript 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: 'bedrock', model: 'meta.llama3-70b-instruct-v1:0', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Function Calling with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md This example illustrates how to use the function calling feature in Token.js. It defines a `get_current_weather` tool with specified parameters and then makes a chat completion request that leverages this tool, logging the tool calls returned by the model. ```ts import { TokenJS, ChatCompletionTool } from 'token.js' const tokenjs = new TokenJS() async function main() { const tools: ChatCompletionTool[] = [ { type: 'function', function: { name: 'get_current_weather', description: 'Get the current weather in a given location', parameters: { type: 'object', properties: { location: { type: 'string', description: 'The city and state, e.g. San Francisco, CA', }, }, required: ['location'], }, }, }, ] const result = await tokenjs.chat.completions.create({ provider: 'gemini', model: 'gemini-1.5-pro', messages: [ { role: 'user', content: `What's the weather like in San Francisco?`, }, ], tools, tool_choice: 'auto', }) console.log(result.choices[0].message.tool_calls) } main() ``` -------------------------------- ### Configure LLM Provider API Keys via Environment Variables Source: https://github.com/token-js/token.js/blob/main/README.md This section provides examples for setting environment variables for various LLM provider API keys, including OpenAI, AI21, Anthropic, Cohere, Gemini, Groq, Mistral, Perplexity, OpenRouter, AWS Bedrock, and generic OpenAI compatible APIs. It's the recommended way to manage credentials securely. ```bash # OpenAI OPENAI_API_KEY= # AI21 AI21_API_KEY= # Anthropic ANTHROPIC_API_KEY= # Cohere COHERE_API_KEY= # Gemini GEMINI_API_KEY= # Groq GROQ_API_KEY= # Mistral MISTRAL_API_KEY= # Perplexity PERPLEXITY_API_KEY= # OpenRouter OPENROUTER_API_KEY= # AWS Bedrock AWS_REGION_NAME= AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= # OpenAI Compatible OPENAI_COMPATIBLE_API_KEY= ``` -------------------------------- ### Stream LLM Responses with Token.js Source: https://github.com/token-js/token.js/blob/main/README.md This example illustrates how to enable and process streaming responses from an LLM using Token.js. It sets the `stream` parameter to true in the chat completion request and iterates over the incoming parts of the response to display them incrementally. ```ts import { TokenJS } from 'token.js' const tokenjs = new TokenJS() async function main() { const result = await tokenjs.chat.completions.create({ stream: true, provider: 'openai', model: 'gpt-4o', messages: [ { role: 'user', content: `Tell me about yourself.`, }, ], }) for await (const part of result) { process.stdout.write(part.choices[0]?.delta?.content || '') } } main() ``` -------------------------------- ### Create Mistral Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/mistral.md This TypeScript example demonstrates how to initialize the Token.js client and create a chat completion request using a specified Mistral model. It shows how to define the provider, model name, and user messages, then log the response from the AI model. ```typescript 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: 'mistral', model: 'mistral-large-2402', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Implement Function Calling with Token.js Source: https://github.com/token-js/token.js/blob/main/README.md This snippet demonstrates how to use the function calling feature in Token.js. It defines a tool for getting current weather, passes it to the chat completion request, and processes the tool call returned by the model to extract function arguments. ```ts import { TokenJS, ChatCompletionTool } from 'token.js' const tokenjs = new TokenJS() async function main() { const tools: ChatCompletionTool[] = [ { type: 'function', function: { name: 'get_current_weather', description: 'Get the current weather in a given location', parameters: { type: 'object', properties: { location: { type: 'string', description: 'The city and state, e.g. San Francisco, CA', }, }, required: ['location'], }, }, }, ] const result = await tokenjs.chat.completions.create({ provider: 'gemini', model: 'gemini-1.5-pro', messages: [ { role: 'user', content: `What's the weather like in San Francisco?`, }, ], tools, tool_choice: 'auto', }) console.log(result.choices[0].message.tool_calls) } main() ``` -------------------------------- ### Create OpenRouter Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md Initialize the Token.js client and generate a chat completion using the OpenRouter provider and a specified model (e.g., nvidia/nemotron-4-340b-instruct). The response includes the generated content from the LLM. -------------------------------- ### Run Token.js test suite Source: https://github.com/token-js/token.js/blob/main/CONTRIBUTING.md Execute the comprehensive test suite for the Token.js project. Running tests is crucial to verify that your changes do not introduce regressions and maintain code quality. ```bash pnpm test ``` -------------------------------- ### Configure Groq API Key in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/groq.md Illustrates how to securely store your Groq API key in a .env file, which is a common practice for managing sensitive credentials in development environments. ```bash GROQ_API_KEY= ``` -------------------------------- ### Create Bedrock Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md Initialize the Token.js client and generate a chat completion using the Bedrock provider and a specified model (e.g., meta.llama3-70b-instruct-v1:0). The response includes the generated content from the LLM. ```typescript 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: 'bedrock', model: 'meta.llama3-70b-instruct-v1:0', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Clone the Token.js repository Source: https://github.com/token-js/token.js/blob/main/CONTRIBUTING.md This command clones the Token.js project repository from GitHub to your local machine. It's the first step to setting up your development environment. ```bash git clone https://github.com/token-js/token-js.git ``` -------------------------------- ### Create OpenAI Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md Initialize the Token.js client and generate a chat completion using the OpenAI provider and a specified model (e.g., gpt-4o). The response includes the generated content from the LLM. ```typescript 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() ``` -------------------------------- ### Create Cohere Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md Initialize the Token.js client and generate a chat completion using the Cohere provider and a specified model (e.g., command-r-plus). The response includes the generated content from the LLM. ```typescript 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: 'cohere', model: 'command-r-plus', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Create Gemini Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md Initialize the Token.js client and generate a chat completion using the Gemini provider and a specified model (e.g., gemini-1.5-pro). The response includes the generated content from the LLM. ```typescript 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() ``` -------------------------------- ### Configure Gemini API Key Source: https://github.com/token-js/token.js/blob/main/docs/README.md Set the Gemini API key as an environment variable for authentication with the Token.js client. ```bash GEMINI_API_KEY= ``` -------------------------------- ### Create Mistral Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md Initialize the Token.js client and generate a chat completion using the Mistral provider and a specified model (e.g., open-mixtral-8x22b). The response includes the generated content from the LLM. ```typescript 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: 'mistral', model: 'open-mixtral-8x22b', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Gemini API Key Configuration in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/gemini.md This snippet shows how to set up the Gemini API key as an environment variable in a .env file. This key is essential for authenticating requests to the Gemini API when using Token.js. ```bash GEMINI_API_KEY= ``` -------------------------------- ### Configure OpenAI API Key Source: https://github.com/token-js/token.js/blob/main/docs/README.md Set the OpenAI API key as an environment variable for authentication with the Token.js client. ```bash OPENAI_API_KEY= ``` -------------------------------- ### Create Anthropic Chat Completion with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/README.md Initialize the Token.js client and generate a chat completion using the Anthropic provider and a specified model (e.g., claude-3-sonnet-20240229). The response includes the generated content from the LLM. ```typescript 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() ``` -------------------------------- ### Token.js LLM Provider Feature Compatibility Overview (APIDOC) Source: https://github.com/token-js/token.js/blob/main/README.md Provides a comprehensive overview of feature compatibility across various LLM providers supported by Token.js, including Chat Completion, Streaming, Function Calling, JSON Output, and Image Input. It indicates which features are supported by Token.js for each provider. ```APIDOC LLM Provider Feature Compatibility: | Provider | Chat Completion | Streaming | Function Calling Tool | JSON Output | Image Input | |-------------------|-----------------|-----------|-----------------------|-------------|-------------| | OpenAI | Supported | Supported | Supported | Supported | Supported | | Anthropic | Supported | Supported | Supported | Supported | Supported | | Bedrock | Supported | Supported | Supported | Supported | Supported | | Mistral | Supported | Supported | Supported | Not Supported | Not Supported | | Cohere | Supported | Supported | Supported | Not Supported | Not Supported | | AI21 | Supported | Supported | Not Supported | Not Supported | Not Supported | | Gemini | Supported | Supported | Supported | Supported | Supported | | Groq | Supported | Supported | Not Supported | Supported | Not Supported | | Perplexity | Supported | Supported | Not Supported | Not Supported | Not Supported | | OpenRouter | Supported | Supported | Supported | Supported | Supported | | OpenAI Compatible | Supported | Supported | Supported | Supported | Supported | Legend: - Supported: Supported by Token.js - Not Supported: Not supported by the LLM provider, so Token.js cannot support it ``` -------------------------------- ### Configure OpenRouter API Key in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/openrouter.md This snippet shows how to set up the OPENROUTER_API_KEY environment variable in a .env file, which is essential for authenticating requests to the OpenRouter API. ```bash OPENROUTER_API_KEY= ``` -------------------------------- ### Configure Perplexity API Key in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/perplexity.md This snippet shows how to set your Perplexity API key as an environment variable in a .env file, which is a common practice for securing sensitive information. ```bash PERPLEXITY_API_KEY= ``` -------------------------------- ### Configure Bedrock API Keys Source: https://github.com/token-js/token.js/blob/main/docs/README.md Set AWS region, access key ID, and secret access key as environment variables for authentication with the Bedrock provider via Token.js. ```bash AWS_REGION_NAME= AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= ``` -------------------------------- ### Configure AI21 API Key in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/ai21.md Illustrates how to set the AI21 API key as an environment variable in a .env file, which is crucial for authenticating requests to the AI21 API. ```bash AI21_API_KEY= ``` -------------------------------- ### Configure OpenAI API Key in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/openai.md This snippet shows how to set up your OpenAI API key as an environment variable in a .env file, which is required for authenticating with the OpenAI API when using Token.js. ```bash OPENAI_API_KEY= ``` -------------------------------- ### OpenAI Supported Models and Features with Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/openai.md This table lists various OpenAI models compatible with Token.js, detailing their support for features such as Chat Completion, Streaming, JSON Output, Image Input, Function Calling, and N > 1 completions. It clarifies which features are supported by Token.js and which are limitations of the LLM provider. ```APIDOC Model | Chat Completion | Streaming | JSON Output | Image Input | Function Calling | N > 1 -------------------------- | --------------- | --------- | ----------- | ----------- | ---------------- | ----- gpt-4.5-preview | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4.5-preview-2025-02-27 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4.1 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4.1-2025-04-14 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4o | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4o-mini | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4o-2024-05-13 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4o-2024-08-06 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4-turbo | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4-turbo-2024-04-09 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4-0125-preview | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4-turbo-preview | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4-1106-preview | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ gpt-4-vision-preview | ✅ | ✅ | ➖ | ✅ | ➖ | ✅ gpt-4 | ✅ | ✅ | ➖ | ➖ | ✅ | ✅ gpt-4-0314 | ✅ | ✅ | ➖ | ➖ | ➖ | ✅ gpt-4-0613 | ✅ | ✅ | ➖ | ➖ | ✅ | ✅ gpt-4-32k | ✅ | ✅ | ➖ | ➖ | ➖ | ✅ gpt-4-32k-0314 | ✅ | ✅ | ➖ | ➖ | ➖ | ✅ gpt-4-32k-0613 | ✅ | ✅ | ➖ | ➖ | ➖ | ✅ gpt-3.5-turbo | ✅ | ✅ | ✅ | ➖ | ✅ | ✅ gpt-3.5-turbo-16k | ✅ | ✅ | ➖ | ➖ | ➖ | ✅ gpt-3.5-turbo-0301 | ✅ | ✅ | ➖ | ➖ | ➖ | ✅ gpt-3.5-turbo-0613 | ✅ | ✅ | ➖ | ➖ | ✅ | ✅ gpt-3.5-turbo-1106 | ✅ | ✅ | ✅ | ➖ | ✅ | ✅ gpt-3.5-turbo-0125 | ✅ | ✅ | ✅ | ➖ | ✅ | ✅ gpt-3.5-turbo-16k-0613 | ✅ | ✅ | ➖ | ➖ | ➖ | ✅ o3-mini | ✅ | ✅ | ✅ | ➖ | ✅ | ✅ o1-mini | ✅ | ➖ | ➖ | ➖ | ➖ | ✅ o1-mini-2024-09-12 | ✅ | ➖ | ➖ | ➖ | ➖ | ✅ o1-preview | ✅ | ➖ | ➖ | ➖ | ➖ | ✅ o1-preview-2024-09-12 | ✅ | ➖ | ➖ | ➖ | ➖ | ✅ Legend: ✅: Supported by Token.js ➖: Not supported by the LLM provider, so Token.js cannot support it ``` -------------------------------- ### Configure OpenRouter API Key Source: https://github.com/token-js/token.js/blob/main/docs/README.md Set the OpenRouter API key as an environment variable for authentication with the Token.js client. ```bash OPENROUTER_API_KEY= ``` -------------------------------- ### Perform AI21 Chat Completion using Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/ai21.md Shows how to initialize the Token.js client and make an asynchronous call to create a chat completion with the AI21 Jamba-Instruct model, including defining user messages and logging the response. ```typescript 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: 'ai21', model: 'jamba-instruct', // Define your message messages: [ { role: 'user', content: 'Hello!', }, ], }) console.log(completion.choices[0]) } main() ``` -------------------------------- ### Add a changeset for Token.js release Source: https://github.com/token-js/token.js/blob/main/CONTRIBUTING.md Use this command to add a changeset, which is essential for triggering a new release with your contributions. You will be prompted to select a change level (major, minor, patch) and provide a concise description for the public changelog. ```bash pnpm changeset ``` -------------------------------- ### Configure Mistral API Key Source: https://github.com/token-js/token.js/blob/main/docs/README.md Set the Mistral API key as an environment variable for authentication with the Token.js client. ```bash MISTRAL_API_KEY= ``` -------------------------------- ### Configure Cohere API Key Source: https://github.com/token-js/token.js/blob/main/docs/README.md Set the Cohere API key as an environment variable for authentication with the Token.js client. ```bash COHERE_API_KEY= ``` -------------------------------- ### Set OpenAI Compatible API Key Environment Variable Source: https://github.com/token-js/token.js/blob/main/docs/providers/openai-compatible.md Optionally, you may specify an API key with an environment variable. Typically, you would not need to specify this with Ollama but you may need one for other model providers. ```bash OPENAI_COMPATIBLE_API_KEY= ``` -------------------------------- ### Configure Mistral API Key in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/mistral.md Instructions for securely storing your Mistral API key in an environment file, which is a common practice for managing sensitive credentials in development and production environments. ```bash MISTRAL_API_KEY= ``` -------------------------------- ### Run and fix Token.js linter suggestions Source: https://github.com/token-js/token.js/blob/main/CONTRIBUTING.md This command runs the linter to check for code style and quality issues. It attempts to automatically fix any identified problems, ensuring code consistency across the project. ```bash pnpm lint:fix ``` -------------------------------- ### Update Token.js documentation Source: https://github.com/token-js/token.js/blob/main/CONTRIBUTING.md This command updates the project's documentation. It is typically necessary when core components like the `models` object are modified to ensure the documentation remains current. ```bash pnpm docs:update ``` -------------------------------- ### Set OpenAI API Key Environment Variable Source: https://github.com/token-js/token.js/blob/main/README.md This snippet shows how to set the OpenAI API key as an environment variable, which is recommended for configuring credentials for the OpenAI provider. ```bash OPENAI_API_KEY= ``` -------------------------------- ### Configure Anthropic API Key in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/anthropic.md This snippet shows how to set up your Anthropic API key as an environment variable in a .env file, which is required for authentication with the Anthropic API. ```bash ANTHROPIC_API_KEY= ``` -------------------------------- ### Token.js Compatibility with Groq Models Source: https://github.com/token-js/token.js/blob/main/docs/providers/groq.md Detailed compatibility matrix for Groq models when used with Token.js, outlining support for features such as chat completion, streaming, JSON output, image input, function calling, and N > 1 generations. ```APIDOC Model: llama-3.3-70b-versatile Capabilities: Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Not Supported Function Calling: Not Supported N > 1: Not Supported Model: llama-3.1-8b-instant Capabilities: Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Not Supported Function Calling: Not Supported N > 1: Not Supported Model: llama3-8b-8192 Capabilities: Chat Completion: Supported Streaming: Supported JSON Output: Not Supported Image Input: Not Supported Function Calling: Not Supported N > 1: Not Supported Model: llama3-70b-8192 Capabilities: Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Not Supported Function Calling: Not Supported N > 1: Not Supported Model: mixtral-8x7b-32768 Capabilities: Chat Completion: Supported Streaming: Supported JSON Output: Not Supported Image Input: Not Supported Function Calling: Not Supported N > 1: Not Supported Model: gemma-7b-it Capabilities: Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Not Supported Function Calling: Not Supported N > 1: Not Supported Model: gemma2-9b-it Capabilities: Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Not Supported Function Calling: Not Supported N > 1: Not Supported ``` -------------------------------- ### Configure Anthropic API Key Source: https://github.com/token-js/token.js/blob/main/docs/README.md Set the Anthropic API key as an environment variable for authentication with the Token.js client. ```bash ANTHROPIC_API_KEY= ``` -------------------------------- ### Perplexity Supported Models and Capabilities via Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/perplexity.md This table outlines the compatibility of various Perplexity models when used through Token.js, detailing their support for features like Chat Completion, Streaming, JSON Output, Image Input, Function Calling, and N > 1 completions. It also includes a legend explaining the symbols used. ```APIDOC Model: llama-3.1-sonar-small-128k-online Chat Completion: Supported Streaming: Supported JSON Output: Not supported by provider Image Input: Not supported by provider Function Calling: Not supported by provider N > 1: Not supported by provider Model: llama-3.1-sonar-large-128k-online Chat Completion: Supported Streaming: Supported JSON Output: Not supported by provider Image Input: Not supported by provider Function Calling: Not supported by provider N > 1: Not supported by provider Model: llama-3.1-sonar-huge-128k-online Chat Completion: Supported Streaming: Supported JSON Output: Not supported by provider Image Input: Not supported by provider Function Calling: Not supported by provider N > 1: Not supported by provider Legend: ✅: Supported by Token.js ➖: Not supported by the LLM provider, so Token.js cannot support it ``` -------------------------------- ### Supported Gemini Models and Features via Token.js Source: https://github.com/token-js/token.js/blob/main/docs/providers/gemini.md This API documentation outlines the Gemini models supported by Token.js and their specific capabilities, including Chat Completion, Streaming, JSON Output, Image Input, Function Calling, and N > 1 support. It details which features are available for each model. ```APIDOC Model: gemini-2.0-flash-001 Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Supported Function Calling: Supported N > 1: Supported Model: gemini-2.0-flash-lite-preview-02-05 Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Supported Function Calling: Not supported by the LLM provider, so Token.js cannot support it N > 1: Supported Model: gemini-1.5-pro Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Supported Function Calling: Supported N > 1: Supported Model: gemini-1.5-flash Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Supported Function Calling: Supported N > 1: Supported Model: gemini-1.5-flash-8b Chat Completion: Supported Streaming: Supported JSON Output: Supported Image Input: Supported Function Calling: Supported N > 1: Supported Model: gemini-1.0-pro Chat Completion: Supported Streaming: Supported JSON Output: Not supported by the LLM provider, so Token.js cannot support it Image Input: Not supported by the LLM provider, so Token.js cannot support it Function Calling: Supported N > 1: Supported ``` -------------------------------- ### Configure Cohere API Key in .env Source: https://github.com/token-js/token.js/blob/main/docs/providers/cohere.md This snippet shows how to set the COHERE_API_KEY environment variable in a .env file, which is essential for authenticating requests to the Cohere API via Token.js. ```bash COHERE_API_KEY= ``` -------------------------------- ### Configure AWS Bedrock Environment Variables Source: https://github.com/token-js/token.js/blob/main/docs/providers/bedrock.md This snippet shows the necessary environment variables for authenticating with AWS Bedrock. These variables include the AWS region, access key ID, and secret access key, which are crucial for secure API calls. ```bash AWS_REGION_NAME= AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= ```