Docs/Introduction

Quickstart

Get started with AllToken
AllToken provides a unified API that gives you access to hundreds of AI models through a single endpoint, while automatically handling fallbacks and selecting the most cost-effective options. Get started with just a few lines of code using your preferred SDK or framework.

Using the AllToken SDK (Beta)

First, install the SDK:
npm install @alltoken/sdk
Then use it in your code:
import { AllToken } from '@alltoken/sdk';

const allToken = new AllToken({
  apiKey: '<ALLTOKEN_API_KEY>',
});

const completion = await allToken.chat.send({
  model: 'minimax-m2.5',
  messages: [
    {
      role: 'user',
      content: 'What is the meaning of life?',
    },
  ],
  stream: false,
});

console.log(completion.choices[0].message.content);

Using the OpenAI SDK

AllToken is fully compatible with the OpenAI SDK. Just point the base_url to AllToken.
import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: 'https://api.alltoken.ai/api-chat/v1',
  apiKey: '<ALLTOKEN_API_KEY>',
});

async function main() {
  const completion = await openai.chat.completions.create({
    model: 'minimax-m2.5',
    messages: [
      {
        role: 'user',
        content: 'What is the meaning of life?',
      },
    ],
  });

  console.log(completion.choices[0].message);
}

main();

Using the AllToken API directly

You can also call the API using standard HTTP requests without any SDK.
import requests
import json

response = requests.post(
    url="https://api.alltoken.ai/api-chat/v1/chat/completions",
    headers={
        "Authorization": "Bearer <ALLTOKEN_API_KEY>",
    },
    data=json.dumps({
        "model": "minimax-m2.5",
        "messages": [
            {
                "role": "user",
                "content": "What is the meaning of life?"
            }
        ]
    })
)

Streaming

The API also supports streaming. See the streaming documentation for details.

Next Steps

API Reference · Streaming · Routing