Skip to content
Sign Up Free
API Reference

OpenAI Chat Completions API

Use BetterToken's OpenAI-compatible Chat Completions API with a complete request URL, Bearer API Key, curl, Python, and JavaScript examples and error handling.

Call OpenAI-compatible Chat Completions with POST https://bettertoken.ai/v1/chat/completions. Most external tools take the Base URL https://bettertoken.ai/v1 and append /chat/completions themselves.

Key settings

FieldValue
API KeyBetterToken API Key
Full request URLhttps://bettertoken.ai/v1/chat/completions
ModelYOUR_MODEL_ID

Prerequisites

Install

curl

curl needs no SDK. Confirm that curl --version works in your terminal.

Python

Terminal window
python -m pip install openai

JavaScript

Terminal window
npm install openai

Manual setup

curl

Terminal window
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);

Verify the connection

In the Playground on the right:

  1. Enter YOUR_API_KEY under Authorization.
  2. Replace model with YOUR_MODEL_ID.
  3. Edit messages and send the request.

The Playground already uses the complete URL https://bettertoken.ai/v1/chat/completions.

A 200 response with model output in choices[0].message.content confirms the connection.

Switch models

Replace YOUR_MODEL_ID with the complete Model ID from the model plaza or Setup dialog. Do not shorten the Model ID based on its display name.

Common errors

ErrorFix
401Confirm Authorization: Bearer YOUR_API_KEY, then copy the BetterToken API Key again.
404Direct HTTP calls use https://bettertoken.ai/v1/chat/completions; SDK base_url uses https://bettertoken.ai/v1.
Model not foundUse the complete Model ID from the model plaza or Setup dialog.
Invalid requestConfirm that messages is an array and every item has role and content.

Technical details

Base URL and full request URL

Tools that require a complete request URL, such as GitHub Copilot and TRAE, use https://bettertoken.ai/v1/chat/completions. Tools that append the path themselves, such as Cursor, Cline, OpenCode, n8n, and Dify, use only https://bettertoken.ai/v1.

POST/v1/chat/completions

Authorizations

Authorizationstringheaderrequired

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

Body application/json

modelstringrequired

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

Example:"YOUR_MODEL_ID"
messagesobject[]required

Conversation messages. Each item should contain role and content.

Minimum array length: 1

Show child attributes
messages[].rolestringrequired
Example:"user"
messages[].contentstringrequired
Example:"Hello"
streambooleandefault: false

Whether to request a streaming response.

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.