API Documentation
OpenAI-compatible SDK. Access DeepSeek, Qwen, Claude, Gemini, GPT-4 and more through a single endpoint.
Base URL
https://opencodex.hk/api/v1Authentication
All API requests must include an API Key in the HTTP Authorization header. Create an API Key in the dashboard.
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
}'Error Codes
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
Send a list of messages to the model and receive a response. Fully compatible with OpenAI /v1/chat/completions format.
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 | 停止序列,遇到此内容时停止生成 |
Request Body
{
"model": "deepseek-chat",
"messages": [
{ "role": "system", "content": "You are a helpful assistant." },
{ "role": "user", "content": "Hello!" }
],
"temperature": 0.7,
"max_tokens": 2048,
"stream": false
}Response
{
"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
Set stream: true to receive model output token by token, ideal for real-time chat interfaces.
Request Body
{
"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]Available Models
Get the list of all model IDs your account has access to.
GET /v1/modelsBalance Check
Query the remaining Credits balance for your account.
GET /v1/balanceSDK Examples
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);Error Codes
| Code | Meaning |
|---|---|
| 200 | Success |
| 400 | Bad Request (e.g. missing required fields) |
| 401 | Invalid or expired API Key |
| 402 | Insufficient Credits — please top up |
| 429 | Too many requests — rate limit triggered |
| 500 | Internal server error |
Ready to start building?
Get 500 free Credits on signup. No credit card required.
Sign Up Free