इसे छोड़कर कंटेंट पर जाएं
मुफ़्त साइन अप करें
API संदर्भ

OpenAI Chat Completions API गाइड

BetterToken का OpenAI-संगत Chat Completions API चलाएं। अनुरोध URL, Bearer API Key और curl, Python व JavaScript के उदाहरण देखें।

OpenAI-compatible Chat Completions को POST https://bettertoken.ai/v1/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 नहीं चाहिए। पुष्टि करें कि curl --version आपके terminal में चलता है।

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 संपादित करें और अनुरोध भेजें।

Playground पहले से पूरा URL https://bettertoken.ai/v1/chat/completions उपयोग करता है।

मॉडल output के साथ 200 response का choices[0].message.content में होना कनेक्शन की पुष्टि करता है।

मॉडल बदलें

YOUR_MODEL_ID को model plaza या Setup dialog की पूरी Model ID से बदलें। display name के आधार पर Model ID को छोटा न करें।

सामान्य त्रुटियां

त्रुटिसमाधान
401Authorization: Bearer YOUR_API_KEY की पुष्टि करें, फिर BetterToken API Key दोबारा कॉपी करें।
404direct HTTP call https://bettertoken.ai/v1/chat/completions उपयोग करता है; SDK base_url https://bettertoken.ai/v1 उपयोग करता है।
मॉडल नहीं मिलाmodel plaza या Setup dialog की पूरी Model ID उपयोग करें।
अमान्य अनुरोधपुष्टि करें कि messages एक array है और हर item में role व content हैं।

तकनीकी विवरण

Base URL और पूर्ण request URL

पूरा request URL मांगने वाले tool, जैसे GitHub Copilot और TRAE, https://bettertoken.ai/v1/chat/completions उपयोग करते हैं। path स्वयं जोड़ने वाले tool, जैसे Cursor, Cline, OpenCode, n8n और Dify, केवल 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.