API Documentation
OpenAI-compatible. Zero migration. One API for 7 mainstream models.
1. Overview
The XABLE API is fully OpenAI-compatible. Use any OpenAI SDK or HTTP client — just change base_url and api_key to switch seamlessly.
Quick Start
Choose any of the following three:
from openai import OpenAI
client = OpenAI(
base_url="https://xable.com.cn/v1",
api_key="xb_live_<your-key>"
)
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "你好,请用中文回答"}]
)
print(response.choices[0].message.content)curl https://xable.com.cn/v1/chat/completions \
-H "Authorization: Bearer xb_live_<your-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{"role": "user", "content": "你好,请用中文回答"}
]
}'import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://xable.com.cn/v1",
apiKey: "xb_live_<your-key>"
})
const response = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [{ role: "user", content: "你好,请用中文回答" }]
})
console.log(response.choices[0].message.content)2. Authentication
All API requests must carry a Bearer Token in the HTTP Header for authentication. The token is your API Key.
Get API Key
Sign in to Console →Create a key on the «API Key» page. Key prefix: xb_live_.
Authorization: Bearer xb_live_<your-api-key>3. API Endpoints
All endpoints follow RESTful design. Base URL:
| Endpoint | Method | Description |
|---|---|---|
/v1/models | GET | List available models |
/v1/chat/completions | POST | Chat completions (core) |
Note: request paths have no /api prefix; use /v1/... directly
4. Models
Query all available models:
curl https://xable.com.cn/v1/models \
-H "Authorization: Bearer xb_live_<your-key>"| Field | Type | Description |
|---|---|---|
id | string | Model identifier (used as the model parameter) |
object | string | Fixed to "model" |
created | int | Creation timestamp |
owned_by | string | Model provider |
For detailed model info and pricing, visit Model API page .
5. Chat Completions
Use /v1/chat/completions to send a chat request.
Request Example
curl https://xable.com.cn/v1/chat/completions \
-H "Authorization: Bearer xb_live_<your-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"messages": [
{"role": "system", "content": "你是一个有用的助手"},
{"role": "user", "content": "请用中文介绍一下你自己"}
],
"temperature": 0.7,
"max_tokens": 2048,
"top_p": 1,
"frequency_penalty": 0,
"presence_penalty": 0,
"stream": false
}'6. Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Model ID, see model list |
messages | array | Yes | List of messages |
temperature | number | No | Sampling temperature, 0–2, default 1 |
top_p | number | No | Nucleus sampling, 0–1, default 1 |
n | int | No | Number of replies, default 1 |
stream | bool | No | Stream output, default false |
max_tokens | int | No | Max output tokens |
stop | string/array | No | Stop sequence |
frequency_penalty | number | No | Frequency penalty, −2 to 2, default 0 |
presence_penalty | number | No | Presence penalty, −2 to 2, default 0 |
user | string | No | User identifier (for monitoring) |
Message Object
| Parameter | Type | Required | Description |
|---|---|---|---|
role | string | Yes | system / user / assistant / tool |
content | string | Yes | Message content |
name | string | No | Author name |
tool_calls | array | No | Tool calls (assistant role) |
tool_call_id | string | No | Tool call ID (tool role) |
7. Response Format
Non-streaming responses return the full JSON:
{
"id": "chatcmpl-abc123",
"object": "chat.completion",
"created": 1717500000,
"model": "deepseek-v4-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "我是 AI 助手,很高兴为你服务!"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 20,
"total_tokens": 35
}
}| Field | Type | Description |
|---|---|---|
id | string | Unique request ID |
object | string | Fixed to chat.completion |
created | int | Creation timestamp |
model | string | Model used |
choices[].message.content | string | Reply text |
choices[].finish_reason | string | stop / length / content_filter |
usage.prompt_tokens | int | Input tokens |
usage.completion_tokens | int | Output tokens |
usage.total_tokens | int | Total tokens |
8. Streaming
Set stream: true to enable Server-Sent Events (SSE) streaming:
from openai import OpenAI
client = OpenAI(
base_url="https://xable.com.cn/v1",
api_key="xb_live_<your-key>"
)
stream = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "你好"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")Streaming format (each line starts with data: ):
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你"},"finish_reason":null}]}
data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"好"},"finish_reason":null}]}
data: [DONE]9. Image Generation
Some models support image generation. Use /v1/images/generations endpoint, compatible with the OpenAI image API.
Request Example
curl https://xable.com.cn/v1/images/generations \
-H "Authorization: Bearer xb_live_<your-key>" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-flash",
"prompt": "A futuristic city with neon lights, digital art style",
"n": 1,
"size": "1024x1024"
}'Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Image model ID |
prompt | string | Yes | Image description |
n | int | No | Images per call, default 1 |
size | string | No | Size: 256x256 / 512x512 / 1024x1024 |
quality | string | No | Quality: standard / hd (some models only) |
Python SDK Example
from openai import OpenAI
client = OpenAI(
base_url="https://xable.com.cn/v1",
api_key="xb_live_<your-key>"
)
response = client.images.generate(
model="stable-diffusion-xl-free",
prompt="A futuristic city with neon lights",
n=1,
size="1024x1024"
)
print(response.data[0].url)10. SDK Guide
The XABLE API is fully OpenAI-compatible. You can use the OpenAI SDK in any language directly. Below are complete examples for popular languages.
Python (Recommended)
Install: pip install openai
from openai import OpenAI
client = OpenAI(
base_url="https://xable.com.cn/v1",
api_key="xb_live_<your-key>"
)
# 非流式聊天
response = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[
{"role": "system", "content": "你是一个有用的助手"},
{"role": "user", "content": "请用中文介绍 XABLE 平台"}
],
temperature=0.7,
max_tokens=1024
)
print(response.choices[0].message.content)
# 流式聊天
stream = client.chat.completions.create(
model="deepseek-v4-flash",
messages=[{"role": "user", "content": "你好"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")Node.js / TypeScript
Install: npm install openai
import OpenAI from "openai"
const client = new OpenAI({
baseURL: "https://xable.com.cn/v1",
apiKey: "xb_live_<your-key>"
})
// 非流式聊天
const response = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [
{ role: "system", content: "你是一个有用的助手" },
{ role: "user", content: "请用中文介绍 XABLE 平台" }
],
temperature: 0.7,
max_tokens: 1024
})
console.log(response.choices[0].message.content)
// 流式聊天
const stream = await client.chat.completions.create({
model: "deepseek-v4-flash",
messages: [{ role: "user", content: "你好" }],
stream: true
})
for await (const chunk of stream) {
if (chunk.choices[0]?.delta?.content) {
process.stdout.write(chunk.choices[0].delta.content)
}
}Go
Install: go get github.com/sashabaranov/go-openai
package main
import (
"context"
"fmt"
openai "github.com/sashabaranov/go-openai"
)
func main() {
cfg := openai.DefaultConfig("xb_live_<your-key>")
cfg.BaseURL = "https://xable.com.cn/v1"
client := openai.NewClientWithConfig(cfg)
// 非流式聊天
resp, err := client.CreateChatCompletion(
context.Background(),
openai.ChatCompletionRequest{
Model: "deepseek-v4-flash",
Messages: []openai.ChatCompletionMessage{
{Role: "system", Content: "你是一个有用的助手"},
{Role: "user", Content: "请用中文介绍 XABLE 平台"},
},
},
)
if err != nil {
panic(err)
}
fmt.Println(resp.Choices[0].Message.Content)
}Java
Maven dependency: com.theokanning.openai-gpt3-java
import com.theokanning.openai.OpenAiService;
import com.theokanning.openai.completion.chat.*;
List<ChatMessage> messages = new ArrayList<>();
messages.add(new ChatMessage("system", "你是一个有用的助手"));
messages.add(new ChatMessage("user", "请用中文介绍 XABLE 平台"));
OpenAiService service = new OpenAiService("xb_live_<your-key>", 30);
service.setBaseUrl("https://xable.com.cn/v1");
ChatCompletionRequest request = ChatCompletionRequest.builder()
.model("deepseek-v4-flash")
.messages(messages)
.build();
service.createChatCompletion(request).getChoices()
.forEach(c -> System.out.println(c.getMessage().getContent()));11. Error Codes
| HTTP Status | Error Type | Description |
|---|---|---|
400 | invalid_request_error | Invalid request parameters |
401 | authentication_error | API Key invalid or missing |
403 | permission_error | No permission (insufficient balance or unauthenticated) |
404 | not_found | Requested resource not found |
429 | rate_limit_error | Request rate exceeded |
500 | server_error | Internal server error |
503 | service_unavailable | Service temporarily unavailable |
{
"error": {
"message": "Incorrect API key provided: xxx. You can find your API key at https://xable.com.cn/console.",
"type": "authentication_error",
"param": null,
"code": "invalid_api_key"
}
}12. Rate Limits
To ensure stability, API calls are rate limited. Exceeding the limit returns a 429 status code.
| Item | Default | Description |
|---|---|---|
| Request rate | 10 RPM | Max 10 requests per minute |
| Concurrency | 10 concurrent | Max 10 concurrent requests in flight |
| Request timeout | 120 seconds | Max wait time per request |
| Max tokens/request | Depends on model | Varies by model context length |
Enterprise customers can contact support to raise limits. Both free and paid users are served by XABLE's self-operated + partner compute backbone for stable inference.
13. Billing
XABLE uses pay-as-you-go billing, charging in real time by tokens consumed, with separate input/output pricing.
Billing Rules
| Item | Description |
|---|---|
| Billing unit | Per 1000 tokens (~700–800 Chinese characters) |
| Minimum charge | Min ¥0.005 per call |
| Billing | Usage is deducted from your balance in real time, no minimum spend; insufficient balance returns 402 XB_INSUFFICIENT_BALANCE. |
| Charging method | Deducted from balance in real time, no post-paid billing |
| Balance query | Sign in to the console to view balance and usage |
Pricing
Prices vary by model. See Model API page for each model's input/output unit price. In general, open-source/free models are cheapest; flagship models cost more but are more capable.
💡 Money-saving tips
- • Use open-source/free models (e.g. deepseek-v4-flash) for simple tasks instead of flagship models
- • Set a reasonable max_tokens to avoid overly long output
- • Use streaming (stream: true) for faster first-token latency
- • Enterprise users can contact support for exclusive pricing and higher concurrency
FAQ
How do I get an API Key?
After registering and signing in, create one on the console «API Key» page. The prefix is xb_live_; copy and save it immediately after creation.
What protocol does the API use?
Fully OpenAI-compatible. Supports the chat/completions endpoint and OpenAI Python/Node.js SDKs.
What's the difference between free and paid users?
Free users can try basic AI chat. Paid users (balance > 0) get higher concurrency, more stable service and full model access.
How is billing calculated?
Real-time billing by token usage, input and output priced separately. Minimum ¥0.005 (0.5 cents) per call.
Which SDKs are supported?
All OpenAI SDKs, including Python, Node.js, Go, Java, .NET, etc. Just change base_url and api_key.
What is the concurrency limit?
Default 10 concurrent. Enterprise customers can contact support to raise it.