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
| Field | Value |
|---|---|
| API Key | BetterToken API Key |
| Full request URL | https://bettertoken.ai/v1/chat/completions |
| Model | YOUR_MODEL_ID |
Prerequisites
- Create a BetterToken API Key
- Copy a Model ID from the model plaza or the key Setup dialog
- Prepare a terminal with
curl, or Python 3 / Node.js
Install
curl
curl needs no SDK. Confirm that curl --version works in your terminal.
Python
python -m pip install openaiJavaScript
npm install openaiManual setup
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);Verify the connection
In the Playground on the right:
- Enter
YOUR_API_KEYunder Authorization. - Replace
modelwithYOUR_MODEL_ID. - Edit
messagesand 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
| Error | Fix |
|---|---|
401 | Confirm Authorization: Bearer YOUR_API_KEY, then copy the BetterToken API Key again. |
404 | Direct HTTP calls use https://bettertoken.ai/v1/chat/completions; SDK base_url uses https://bettertoken.ai/v1. |
| Model not found | Use the complete Model ID from the model plaza or Setup dialog. |
| Invalid request | Confirm 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.
/v1/chat/completionsAuthorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body application/json
A model ID currently available in the model plaza. Check the model plaza for the latest options.
"YOUR_MODEL_ID"Conversation messages. Each item should contain role and content.
Show child attributes
"user""Hello"Whether to request a streaming response.

