{"id":22488979,"url":"https://github.com/token-js/token.js","last_synced_at":"2025-09-16T14:09:32.070Z","repository":{"id":248194396,"uuid":"822839116","full_name":"token-js/token.js","owner":"token-js","description":"Integrate 200+ LLMs with one TypeScript SDK using OpenAI's format.","archived":false,"fork":false,"pushed_at":"2025-04-21T17:44:58.000Z","size":764,"stargazers_count":284,"open_issues_count":9,"forks_count":41,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-08-15T19:58:06.876Z","etag":null,"topics":["llm","openai","typescript"],"latest_commit_sha":null,"homepage":"https://docs.tokenjs.ai/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/token-js.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-07-01T23:58:00.000Z","updated_at":"2025-08-11T19:13:20.000Z","dependencies_parsed_at":"2025-01-14T02:41:14.020Z","dependency_job_id":"82a98876-22d9-4558-88e3-f07289721174","html_url":"https://github.com/token-js/token.js","commit_stats":null,"previous_names":["token-js/token.js"],"tags_count":36,"template":false,"template_full_name":null,"purl":"pkg:github/token-js/token.js","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/token-js%2Ftoken.js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/token-js%2Ftoken.js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/token-js%2Ftoken.js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/token-js%2Ftoken.js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/token-js","download_url":"https://codeload.github.com/token-js/token.js/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/token-js%2Ftoken.js/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":275432395,"owners_count":25463758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-16T02:00:10.229Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["llm","openai","typescript"],"created_at":"2024-12-06T17:19:01.135Z","updated_at":"2025-09-16T14:09:31.998Z","avatar_url":"https://github.com/token-js.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Token.js\n\nIntegrate 200+ LLMs with one TypeScript SDK using OpenAI's format. Free and open source. No proxy server required.\n\n## Features\n\n* Use OpenAI's format to call 200+ LLMs from 10+ providers.\n* Supports tools, JSON outputs, image inputs, streaming, and more.\n* Runs completely on the client side. No proxy server needed.\n* Free and open source under MIT.\n\n## Supported Providers\n\n* AI21\n* Anthropic\n* AWS Bedrock\n* Cohere\n* Gemini\n* Groq\n* Mistral\n* OpenAI\n* Perplexity\n* OpenRouter\n* Any other model provider with an OpenAI compatible API\n\n## [Documentation](https://docs.tokenjs.ai/)\n\n## Setup\n\n### Installation\n\n```bash\nnpm install token.js\n```\n\n### Usage\n\nImport 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.\n\n```bash\nOPENAI_API_KEY=\u003copenai api key\u003e\n```\n```ts\nimport { 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: 'openai',\n    model: 'gpt-4o',\n    // Define your message\n    messages: [\n      {\n        role: 'user',\n        content: 'Hello!',\n      },\n    ],\n  })\n  console.log(completion.choices[0])\n}\nmain()\n```\n\n### Access Credentials\n\nWe recommend using environment variables to configure the credentials for each LLM provider.\n\n```bash\n# OpenAI\nOPENAI_API_KEY=\n# AI21\nAI21_API_KEY=\n# Anthropic\nANTHROPIC_API_KEY=\n# Cohere\nCOHERE_API_KEY=\n# Gemini\nGEMINI_API_KEY=\n# Groq\nGROQ_API_KEY=\n# Mistral\nMISTRAL_API_KEY=\n# Perplexity\nPERPLEXITY_API_KEY=\n# OpenRouter\nOPENROUTER_API_KEY=\n# AWS Bedrock\nAWS_REGION_NAME=\nAWS_ACCESS_KEY_ID=\nAWS_SECRET_ACCESS_KEY=\n# OpenAI Compatible\nOPENAI_COMPATIBLE_API_KEY=\n```\n\n### Streaming\n\nToken.js supports streaming responses for all providers that offer it.\n\n```ts\nimport { TokenJS } from 'token.js'\n\nconst tokenjs = new TokenJS()\n\nasync function main() {\n  const result = await tokenjs.chat.completions.create({\n    stream: true,\n    provider: 'openai',\n    model: 'gpt-4o',\n    messages: [\n      {\n        role: 'user',\n        content: `Tell me about yourself.`,\n      },\n    ],\n  })\n\n  for await (const part of result) {\n    process.stdout.write(part.choices[0]?.delta?.content || '')\n  }\n}\nmain()\n```\n\n### Function Calling\n\nToken.js supports the function calling tool for all providers and models that offer it.\n\n```ts\nimport { TokenJS, ChatCompletionTool } from 'token.js'\n\nconst tokenjs = new TokenJS()\n\nasync function main() {\n  const tools: ChatCompletionTool[] = [\n    {\n      type: 'function',\n      function: {\n        name: 'get_current_weather',\n        description: 'Get the current weather in a given location',\n        parameters: {\n          type: 'object',\n          properties: {\n            location: {\n              type: 'string',\n              description: 'The city and state, e.g. San Francisco, CA',\n            },\n          },\n          required: ['location'],\n        },\n      },\n    },\n  ]\n\n  const result = await tokenjs.chat.completions.create({\n    provider: 'gemini',\n    model: 'gemini-1.5-pro',\n    messages: [\n      {\n        role: 'user',\n        content: `What's the weather like in San Francisco?`,\n      },\n    ],\n    tools,\n    tool_choice: 'auto',\n  })\n\n  console.log(result.choices[0].message.tool_calls)\n}\nmain()\n```\n\n### Extending Model Support\n\nToken.js allows you to extend the predefined model list using the `extendModelList` method. Here are some example scenarios where this is useful:\n1. Adding AWS Bedrock models with regional prefixes like `us.anthropic.claude-3-sonnet`\n2. Supporting new model versions before they're added to the predefined list\n3. Using custom model deployments with unique names\n4. Adding experimental or beta models during testing\n\n```ts\nimport { TokenJS } from 'token.js'\n\n// Example in 2 steps: Adding AWS Bedrock Claude models with region prefix\nconst tokenjs = new TokenJS();\n// Step 1: Register the new model name\ntokenjs.extendModelList(\n  \"bedrock\",\n  'us.anthropic.claude-3-5-sonnet-20241022-v2:0',\n  \"anthropic.claude-3-sonnet-20240229-v1:0\" // Copy features from existing model\n);\n\n// Step 2: Using the extended model in a chat completion\nconst result = await tokenjs.chat.completions.create({\n  stream: true,\n  provider: 'bedrock',\n  model: 'us.anthropic.claude-3-5-sonnet-20241022-v2:0' as any, // Type casting as 'any' required\n  messages: [\n    {\n      role: 'user',\n      content: 'Tell me about yourself.',\n    },\n  ],\n});\n```\n\nNote: When using extended models, type casting (`as any`) is required\n\nThe `featureSupport` parameter can be either:\n- A string matching an existing model name from the same provider to copy its feature support\n- An object specifying which features the model supports:\n  | Feature    | Type    | Description                                  |\n  |------------|---------|----------------------------------------------|\n  | streaming  | boolean | Whether the model supports streaming responses|\n  | json       | boolean | Whether the model supports JSON mode         |\n  | toolCalls  | boolean | Whether the model supports function calling  |\n  | images     | boolean | Whether the model supports image inputs      |\n\n## Feature Compatibility\n\nThis table provides an overview of the features that Token.js supports from each LLM provider.\n\n| Provider   | Chat Completion           | Streaming            | Function Calling Tool                | JSON Output          | Image Input          |\n| ---------- | -------------------- | -------------------- | -------------------- | -------------------- | -------------------- |\n| OpenAI     | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: |\n| Anthropic  | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: |\n| Bedrock    | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: |\n| Mistral    | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: |  :heavy_minus_sign:  |\n| Cohere     | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: |  :heavy_minus_sign:  |  :heavy_minus_sign:  |\n| AI21       | :white\\_check\\_mark: | :white\\_check\\_mark: |  :heavy_minus_sign:  |  :heavy_minus_sign:  |  :heavy_minus_sign:  |\n| Gemini     | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: | :white\\_check\\_mark: |\n| Groq       | :white\\_check\\_mark: | :white\\_check\\_mark: |  :heavy_minus_sign:  | :white\\_check\\_mark: |  :heavy_minus_sign:  |\n| Perplexity | :white\\_check\\_mark: | :white\\_check\\_mark: |  :heavy_minus_sign:  |  :heavy_minus_sign:  |  :heavy_minus_sign:  |\n| OpenRouter | :white\\_check\\_mark: | :white\\_check\\_mark: |  :white\\_check\\_mark:  |  :white\\_check\\_mark: |  :white\\_check\\_mark:  |\n| OpenAI Compatible | :white\\_check\\_mark: | :white\\_check\\_mark: |  :white\\_check\\_mark:  |  :white\\_check\\_mark: |  :white\\_check\\_mark:  |\n\n### Legend\n| Symbol             | Description                           |\n|--------------------|---------------------------------------|\n| :white_check_mark: | Supported by Token.js                 |\n| :heavy_minus_sign: | Not supported by the LLM provider, so Token.js cannot support it     |\n\n**Note**: Certain LLMs, particularly older or weaker models, do not support some features in this table. For details about these restrictions, see our [LLM provider documentation](https://docs.tokenjs.ai/providers).\n\n## Contributing\n\nSee our [Contributing guide](./CONTRIBUTING.md) to learn how to contribute to Token.js.\n\n## Issues\n\nPlease let us know if there's any way that we can improve Token.js by opening an issue!\n\n## License\n\nToken.js is free and open source software licensed under [MIT](https://github.com/token-js/token.js/blob/main/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoken-js%2Ftoken.js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoken-js%2Ftoken.js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoken-js%2Ftoken.js/lists"}