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 Key | BetterToken API Key |
| Full request URL | https://bettertoken.ai/v1/chat/completions |
| Model | YOUR_MODEL_ID |
आवश्यकताएं
- BetterToken API Key बनाएं
- model plaza या key Setup dialog से Model ID कॉपी करें
curlया Python 3 / Node.js वाला terminal तैयार रखें
इंस्टॉल करें
curl
curl के लिए SDK नहीं चाहिए। पुष्टि करें कि curl --version आपके terminal में चलता है।
Python
python -m pip install openaiJavaScript
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 में:
- Authorization के अंतर्गत
YOUR_API_KEYभरें। modelकोYOUR_MODEL_IDसे बदलें।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 को छोटा न करें।
सामान्य त्रुटियां
| त्रुटि | समाधान |
|---|---|
401 | Authorization: Bearer YOUR_API_KEY की पुष्टि करें, फिर BetterToken API Key दोबारा कॉपी करें। |
404 | direct 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 उपयोग करते हैं।
/v1/chat/completionsप्राधिकरण
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
बॉडी 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.

