Token.js

repository·main·Indexed 43 days ago

https://github.com/token-js/token.js

A TypeScript SDK that provides a unified, OpenAI-compatible API format to integrate with over 200 LLMs from 10+ providers, including OpenAI, Anthropic, Gemini, Mistral, and AWS Bedrock. It runs entirely on the client side without requiring a proxy server and supports features such as streaming, function calling (tools), and custom model extensions via extendModelList().

Tokens
16.9K
Snippets
50
Records
61
Agent score
50%

What's inside Token.js

  1. Supported LLM Providers in Token.js

    main

    Token.js provides a unified interface to integrate various Large Language Model (LLM) providers. You can use the following providers within your application:

    • AI21
    • Anthropic
    • Bedrock
    • Cohere
    • Gemini
    • Groq
    • Mistral
    • OpenAI
    • Perplexity
    • OpenRouter
    • Requesty
    • OpenAI Compatible (for any provider following the OpenAI API specification)
  2. Requesty compatibility notes

    main
    Requesty acts as an OpenAI-compatible LLM router. Because it routes to many different underlying providers, feature support may vary depending on the specific model being accessed. It is recommended to check both the Requesty documentation and the specific model provider's documentation for compatibility details.
  3. Compatibility and support for OpenAI compatible providers

    main

    While Token.js works with any provider following the OpenAI v1 API spec, features like image input, tool use, and streaming depend on the specific capabilities of the provider and model being used. It is recommended to check the provider's documentation if these features do not behave as expected.

    Commonly used compatible providers:

    • LocalAI
    • Ollama

    Note on Official Support: Providers using the OpenAI compatible spec are not considered 'officially supported'. Official support includes dedicated integration testing, improved type support, and better documentation for specific features. If you use a compatible provider frequently, you can request official support by opening a GitHub issue.

  4. Configure AWS Bedrock credentials

    main

    To use AWS Bedrock with Token.js, you must provide your AWS credentials via environment variables. Ensure you have obtained your credentials from the AWS Console.

    Required environment variables:

    • AWS_REGION_NAME
    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY
    AWS_REGION_NAME=
    AWS_ACCESS_KEY_ID=
    AWS_SECRET_ACCESS_KEY=
  5. Configure authentication for OpenAI compatible providers

    main

    For OpenAI compatible providers that require an API key, you can provide the key via the OPENAI_COMPATIBLE_API_KEY environment variable. This is common for many third-party providers, though typically not required for local instances like Ollama.

    OPENAI_COMPATIBLE_API_KEY=your_api_key_here