콘텐츠로 이동
무료 가입
API 레퍼런스

OpenAI Chat Completions API 사용

BetterToken의 OpenAI 호환 Chat Completions API를 사용하세요. 요청 URL, Bearer API Key, curl, Python, JavaScript 예제를 보세요.

POST https://bettertoken.ai/v1/chat/completions로 OpenAI-compatible Chat Completions를 호출하세요. 대부분의 external tools는 Base URL https://bettertoken.ai/v1을 사용하고 /chat/completions를 자체적으로 추가합니다.

주요 설정

필드값
API KeyBetterToken API Key
Full request URLhttps://bettertoken.ai/v1/chat/completions
ModelYOUR_MODEL_ID

사전 요구 사항

설치

curl

curl에는 SDK가 필요하지 않습니다. terminal에서 curl --version이 작동하는지 확인하세요.

Python

터미널 창
python -m pip install openai

JavaScript

터미널 창
npm install openai

수동 설정

curl

터미널 창
curl "https://bettertoken.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_MODEL_ID",
"messages": [
{
"role": "user",
"content": "Hello"
}
]
}'

Python SDK

from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://bettertoken.ai/v1",
)
response = client.chat.completions.create(
model="YOUR_MODEL_ID",
messages=[
{"role": "user", "content": "Hello"},
],
)
print(response.choices[0].message.content)

JavaScript SDK

import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://bettertoken.ai/v1",
});
const response = await client.chat.completions.create({
model: "YOUR_MODEL_ID",
messages: [{ role: "user", content: "Hello" }],
});
console.log(response.choices[0].message.content);

연결 확인

오른쪽 Playground에서 다음을 수행하세요.

  1. Authorization 아래에 YOUR_API_KEY를 입력하세요.
  2. model을 YOUR_MODEL_ID로 바꾸세요.
  3. messages를 수정하고 request를 보내세요.

Playground는 이미 전체 URL https://bettertoken.ai/v1/chat/completions을 사용합니다.

200 response에 choices[0].message.content의 model output이 포함되면 연결이 확인됩니다.

모델 전환

YOUR_MODEL_ID를 모델 광장 또는 Setup dialog의 전체 Model ID로 바꾸세요. display name을 기준으로 Model ID를 줄이지 마세요.

자주 발생하는 오류

오류해결 방법
401Authorization: Bearer YOUR_API_KEY를 확인한 다음 BetterToken API Key를 다시 복사하세요.
404direct HTTP calls는 https://bettertoken.ai/v1/chat/completions을 사용하며 SDK base_url은 https://bettertoken.ai/v1을 사용합니다.
Model not found모델 광장 또는 Setup dialog의 전체 Model ID를 사용하세요.
Invalid requestmessages가 array이고 모든 item에 role과 content가 있는지 확인하세요.

기술 세부 정보

Base URL 및 전체 request URL

GitHub Copilot 및 TRAE처럼 전체 request URL이 필요한 tools는 https://bettertoken.ai/v1/chat/completions을 사용합니다. Cursor, Cline, OpenCode, n8n 및 Dify처럼 path를 자체적으로 추가하는 tools는 https://bettertoken.ai/v1만 사용합니다.

POST/v1/chat/completions

인증

Authorizationstringheader필수

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

본문 application/json

modelstring필수

A model ID currently available in the model plaza. Check the model plaza for the latest options.

예제:"YOUR_MODEL_ID"
messagesobject[]필수

Conversation messages. Each item should contain role and content.

Minimum array length: 1

Show child attributes
messages[].rolestring필수
예제:"user"
messages[].contentstring필수
예제:"Hello"
streamboolean기본값: false

Whether to request a streaming response.

응답

200The Chat Completions result from the selected model.
400Invalid request format or parameters.
401The BetterToken API Key is missing or invalid.
402The account has insufficient credit or balance.
429The request exceeded a rate or concurrency limit, or the upstream service is busy.
500The gateway or upstream service returned an error.