빠른 시작

AllToken 시작하기.

소개

AllToken은 단일 인터페이스를 통해 수백 개의 AI 모델에 접근할 수 있는 통합 API를 제공하며, 자동 장애 조치(failover)와 최적의 가성비 옵션 선택을 처리합니다.

단 몇 줄의 코드로 원하는 SDK나 프레임워크를 사용해 바로 호출할 수 있습니다.

Base URL: https://api.alltoken.ai/v1

인증 방식: Bearer API Key

호환성: OpenAI 호환 API

API Key 발급

시작하기 전에 API Key를 먼저 생성하세요:

  1. 설정 → API Keys로 이동
  2. 새 Key 생성 클릭
  3. Key를 복사하여 안전하게 보관 — 한 번만 표시됩니다

API Key를 안전하게 보관하고, 클라이언트 코드나 공개 저장소에 노출하지 마세요.

SDK 설치

AllToken은 OpenAI SDK와 완전히 호환됩니다. 원하는 패키지 매니저로 설치하세요:

npm
$ npm install openai

그런 다음 환경 변수를 설정하세요:

Shell
$ export ALLTOKEN_API_KEY="your_alltoken_api_key"

첫 번째 요청 보내기

클라이언트를 생성하고, 모델을 선택한 후 채팅 요청을 전송하세요:

TypeScript
1import OpenAI from 'openai';
2
3const client = new OpenAI({
4 apiKey: process.env.ALLTOKEN_API_KEY,
5 baseURL: 'https://api.alltoken.ai/v1',
6});
7
8const completion = await client.chat.completions.create({
9 model: 'deepseek-chat',
10 messages: [
11 {
12 role: 'user',
13 content: '인생의 의미는 무엇인가요?',
14 },
15 ],
16});
17
18console.log(completion.choices[0]?.message?.content);

Python 예제

Python
1from openai import OpenAI
2import os
3
4client = OpenAI(
5 api_key=os.environ.get("ALLTOKEN_API_KEY"),
6 base_url="https://api.alltoken.ai/v1",
7)
8
9completion = client.chat.completions.create(
10 model="deepseek-chat",
11 messages=[
12 {"role": "user", "content": "인생의 의미는 무엇인가요?"}
13 ],
14)
15
16print(completion.choices[0].message.content)

API 직접 호출

cURL이나 임의의 HTTP 클라이언트로 API를 직접 호출할 수도 있습니다:

cURL
1curl https://api.alltoken.ai/v1/chat/completions \
2 -H "Authorization: Bearer $ALLTOKEN_API_KEY" \
3 -H "Content-Type: application/json" \
4 -d '{
5 "model": "deepseek-chat",
6 "messages": [
7 {"role": "user", "content": "안녕하세요!"}
8 ]
9 }'

스트리밍 응답

stream: true를 추가하면 Server-Sent Events를 통해 토큰 단위로 응답을 수신할 수 있습니다:

TypeScript
1const stream = await client.chat.completions.create({
2 model: 'deepseek-chat',
3 messages: [{ role: 'user', content: '이야기를 하나 들려주세요' }],
4 stream: true,
5});
6
7for await (const chunk of stream) {
8 const content = chunk.choices[0]?.delta?.content;
9 if (content) process.stdout.write(content);
10}

자세한 스트리밍 문서는 스트리밍 응답을 참고하세요.

다음 단계