Dokumentasi API
SDK kompatibel OpenAI. Akses DeepSeek, Qwen, Claude, Gemini, GPT-4, dan lainnya melalui satu endpoint.
URL Dasar
https://opencodex.hk/api/v1Autentikasi
Semua permintaan API harus menyertakan Kunci API di header HTTP Authorization. Buat Kunci API di dasbor.
Authorization: Bearer YOUR_API_KEYQuick Start
Test API connection quickly with cURL or PowerShell
cURL Example
curl -X POST https://opencodex.hk/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-live-YOUR_API_KEY" \
-d '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "Hello!"}]
}'PowerShell Example
Invoke-RestMethod -Uri "https://opencodex.hk/api/v1/chat/completions" -Method POST -Headers @{'Authorization'='Bearer sk-live-YOUR_API_KEY';'Content-Type'='application/json'} -Body '{"model":"deepseek-chat","messages":[{"role":"user","content":"Hello!"}]}'Code Examples
Python
from openai import OpenAI
client = OpenAI(
api_key="sk-live-YOUR_API_KEY",
base_url="https://opencodex.hk/api/v1"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
temperature=0.7,
max_tokens=2048
)
print(response.choices[0].message.content)JavaScript / TypeScript
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: 'sk-live-YOUR_API_KEY',
baseURL: 'https://opencodex.hk/api/v1'
});
const response = await client.chat.completions.create({
model: 'deepseek-chat',
messages: [
{ role: 'system', content: 'You are a helpful assistant.' },
{ role: 'user', content: 'Hello!' }
],
temperature: 0.7,
max_tokens: 2048
});
console.log(response.choices[0].message.content);cURL
curl -X POST https://opencodex.hk/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-live-YOUR_API_KEY" \
-d '{
"model": "deepseek-chat",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
"temperature": 0.7,
"max_tokens": 2048
}'Kode Error
Common error codes that the API may return
| Status Code | Error Code | Description |
|---|---|---|
| 400 | Bad Request | Bad Request (e.g. missing required fields, invalid format) |
| 401 | Unauthorized | Invalid, expired, or malformed API Key (must start with sk-live-) |
| 402 | Payment Required | Insufficient Credits — please top up and try again |
| 429 | Too Many Requests | Too many requests — rate limit triggered, please retry later |
| 500 | Internal Server Error | Internal server error — please retry later or contact support |
Best Practices
🔑 API Key Security
- Never hardcode API Keys in frontend code; use environment variables
- Rotate API Keys regularly to prevent unauthorized access
- Create separate API Keys for different applications for easier management and revocation
⚡ Performance Tips
- Reuse connection pools to avoid frequent HTTPS connection establishment
- Set max_tokens appropriately to avoid generating overly long responses
- Use streaming output to enhance user experience and reduce wait time
🔧 Compatible Tools
Our API is fully compatible with the following popular AI coding tools:
Support
If you have any questions, feel free to contact us through:
Chat Completions
Kirim daftar pesan ke model dan terima respons. Sepenuhnya kompatibel dengan format OpenAI /v1/chat/completions.
Endpoint
POST /v1/chat/completionsRequest Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | ✓ | 模型 ID,如 deepseek-chat, gpt-4o, claude-3-sonnet |
| messages | array | ✓ | 对话消息数组,包含 role (system/user/assistant) 和 content |
| max_tokens | integer | 最大生成 token 数,默认 4096 | |
| temperature | number | 温度参数 (0-2),控制随机性,默认 1 | |
| top_p | number | 核采样参数 (0-1),默认 1 | |
| stream | boolean | 是否使用流式输出,默认 false | |
| stop | array|string | 停止序列,遇到此内容时停止生成 |
Body Permintaan
{
"model": "deepseek-chat",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Hello!" }
],
"temperature": 0.7,
"max_tokens": 2048,
"stream": false
}Respons
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1700000000,
"model": "deepseek-chat",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! How can I help you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 20,
"completion_tokens": 10,
"total_tokens": 30
}
}Streaming
Atur stream: true untuk menerima output model token per token, ideal untuk antarmuka chat real-time.
Body Permintaan
{
"model": "deepseek-chat",
"messages": [{ "role": "user", "content": "Hello!" }],
"stream": true
}Stream Response Example
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1700000000,"model":"deepseek-chat","choices":[{"index":0,"delta":{"content":"Hello"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1700000000,"model":"deepseek-chat","choices":[{"index":0,"delta":{"content":"!"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","created":1700000000,"model":"deepseek-chat","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}
data: [DONE]Daftar Model
Dapatkan daftar semua ID model yang dapat diakses oleh akun Anda.
GET /v1/modelsCek Saldo
Periksa sisa saldo Credit akun Anda.
GET /v1/balanceContoh SDK
Python
from openai import OpenAI
client = OpenAI(
base_url="https://opencodex.hk/api/v1",
api_key="YOUR_API_KEY"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)Node.js
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://opencodex.hk/api/v1",
apiKey: process.env.OPENCODEX_API_KEY,
});
const response = await client.chat.completions.create({
model: "deepseek-chat",
messages: [{ role: "user", content: "Hello!" }],
});
console.log(response.choices[0].message.content);Kode Error
| Kode | Arti |
|---|---|
| 200 | Sukses |
| 400 | Permintaan Buruk (misalnya field yang wajib diisi kosong) |
| 401 | Kunci API tidak valid atau kedaluwarsa |
| 402 | Credit tidak mencukupi — silakan isi ulang |
| 429 | Terlalu banyak permintaan — batas rate terpicu |
| 500 | Kesalahan server internal |
Siap mulai membangun?
Dapatkan 500 Credit gratis saat daftar. Tanpa kartu kredit.
Daftar Gratis