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:

Python (OpenAI SDK)
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
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": "你好,请用中文回答"}
    ]
  }'
Node.js (OpenAI SDK)
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_.

Security tip: Keep your API Key safe and never share it with third parties. If leaked, disable or delete it in the console and create a new one.
Auth Header Format
Authorization: Bearer xb_live_<your-api-key>

3. API Endpoints

All endpoints follow RESTful design. Base URL:

https://xable.com.cn/v1
EndpointMethodDescription
/v1/modelsGETList available models
/v1/chat/completionsPOSTChat completions (core)

Note: request paths have no /api prefix; use /v1/... directly

4. Models

Query all available models:

Request
curl https://xable.com.cn/v1/models \
  -H "Authorization: Bearer xb_live_<your-key>"
FieldTypeDescription
idstringModel identifier (used as the model parameter)
objectstringFixed to "model"
createdintCreation timestamp
owned_bystringModel 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

POST /v1/chat/completions
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

ParameterTypeRequiredDescription
modelstringYesModel ID, see model list
messagesarrayYesList of messages
temperaturenumberNoSampling temperature, 0–2, default 1
top_pnumberNoNucleus sampling, 0–1, default 1
nintNoNumber of replies, default 1
streamboolNoStream output, default false
max_tokensintNoMax output tokens
stopstring/arrayNoStop sequence
frequency_penaltynumberNoFrequency penalty, −2 to 2, default 0
presence_penaltynumberNoPresence penalty, −2 to 2, default 0
userstringNoUser identifier (for monitoring)

Message Object

ParameterTypeRequiredDescription
rolestringYessystem / user / assistant / tool
contentstringYesMessage content
namestringNoAuthor name
tool_callsarrayNoTool calls (assistant role)
tool_call_idstringNoTool call ID (tool role)

7. Response Format

Non-streaming responses return the full JSON:

Response Example
{
  "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
  }
}
FieldTypeDescription
idstringUnique request ID
objectstringFixed to chat.completion
createdintCreation timestamp
modelstringModel used
choices[].message.contentstringReply text
choices[].finish_reasonstringstop / length / content_filter
usage.prompt_tokensintInput tokens
usage.completion_tokensintOutput tokens
usage.total_tokensintTotal tokens

8. Streaming

Set stream: true to enable Server-Sent Events (SSE) streaming:

Python 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: ):

SSE Streaming
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

POST /v1/images/generations
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

ParameterTypeRequiredDescription
modelstringYesImage model ID
promptstringYesImage description
nintNoImages per call, default 1
sizestringNoSize: 256x256 / 512x512 / 1024x1024
qualitystringNoQuality: standard / hd (some models only)

Python SDK Example

Python
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

Python Full Example
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

Node.js Full Example
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

Go Full Example
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

Java Full Example
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 StatusError TypeDescription
400invalid_request_errorInvalid request parameters
401authentication_errorAPI Key invalid or missing
403permission_errorNo permission (insufficient balance or unauthenticated)
404not_foundRequested resource not found
429rate_limit_errorRequest rate exceeded
500server_errorInternal server error
503service_unavailableService temporarily unavailable
Error Response Example
{
  "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.

ItemDefaultDescription
Request rate10 RPMMax 10 requests per minute
Concurrency10 concurrentMax 10 concurrent requests in flight
Request timeout120 secondsMax wait time per request
Max tokens/requestDepends on modelVaries 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

ItemDescription
Billing unitPer 1000 tokens (~700–800 Chinese characters)
Minimum chargeMin ¥0.005 per call
BillingUsage is deducted from your balance in real time, no minimum spend; insufficient balance returns 402 XB_INSUFFICIENT_BALANCE.
Charging methodDeducted from balance in real time, no post-paid billing
Balance querySign 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.

Ready to get started?

Zero-barrier AI access — pay only for what you use

Sign Up Free