API Reference
Dukou API provides OpenAI-compatible HTTP endpoints. Most integrations only need a different base URL and API key.
Base URL
https://dukouapi.com| Operation | Method | Path |
|---|---|---|
| Chat completions | POST | /v1/chat/completions |
| List models | GET | /v1/models |
| Check usage | GET | /api/user/self |
With the official OpenAI SDK, set base_url = "https://dukouapi.com/v1". Do not append another /v1 to the endpoint.
Authentication
Create a key in the API Keys section of the console, then send it in the request header:
Authorization: Bearer YOUR_API_KEY- Keys are assigned to a group; available models and rates vary by group.
- You can set a key's usage limit, expiry and model allowlist.
- Never put an API key in browser-side code or a public repository.
First request: cURL
curl https://dukouapi.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4.1-flash",
"messages": [{"role": "user", "content": "Hello"}],
"max_tokens": 300
}'Python
from openai import OpenAI
client = OpenAI(
api_key="YOUR_API_KEY",
base_url="https://dukouapi.com/v1",
)
response = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Hello"}],
max_tokens=300,
)
print(response.choices[0].message.content)If you already use the openai package, update base_url and api_key.
Node.js
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_API_KEY",
baseURL: "https://dukouapi.com/v1",
});
const response = await client.chat.completions.create({
model: "deepseek-v4.1-flash",
messages: [{ role: "user", content: "Hello" }],
max_tokens: 300,
});
console.log(response.choices[0].message.content);Streaming
Set "stream": true to receive server-sent events (SSE).
stream = client.chat.completions.create(
model="deepseek-v4.1-flash",
messages=[{"role": "user", "content": "Tell me a short story"}],
stream=True,
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")About max_tokens: Some models, including deepseek-v4.1-flash, perform internal reasoning first. If the limit is too low (for example, 50), reasoning may consume it before any text is returned. We recommend at least 256, or 1,000+ for longer answers.
Anthropic Messages API
The Anthropic Messages API is also supported, so you can use the Anthropic SDK:
import anthropic
client = anthropic.Anthropic(
api_key="YOUR_API_KEY",
base_url="https://dukouapi.com",
)
message = client.messages.create(
model="claude-fable-5",
max_tokens=300,
messages=[{"role": "user", "content": "Hello"}],
)
print(message.content[0].text)Endpoint: POST /v1/messages. Authentication accepts both x-api-key and Authorization: Bearer.
Models and rates
Available models depend on your key's group. See the Model Catalog for the full list, group multipliers and current rates. You can also call GET /v1/models to list models available to your key.
Billing
- Charges are based on actual token usage. There is no monthly fee or minimum spend.
- Rates are listed in CNY per million tokens; input and output are priced separately.
- Requests are declined with HTTP 403 when your prepaid balance is insufficient.
- Request-level model, token and charge details appear in the console logs.
Some models have time-based rates. During off-peak periods, the rate is lower; the catalog shows the applicable range.
Charge = (input tokens × input rate + output tokens × output rate) ÷ 1,000,000 × group multiplier. Check the usage log for each request's breakdown.
Error codes
| Status | Meaning | What to do |
|---|---|---|
| 401 | Key is invalid or deleted | Check that the full key was copied. |
| 403 | Insufficient balance or model unavailable in this group | Top up or choose a model in your group. |
| 429 | Too many requests | Reduce concurrency or retry later. |
| 500 / 502 | Upstream error | Retry later; contact support if it persists. |
| 503 | No available channel for this group | Try another model or contact support. |
FAQ
A request returns 200, but the response is empty
The max_tokens limit may be too low. Some models use part of it for internal reasoning. Raising it to at least 256 usually resolves the issue.
“No available channel for model X under group Y”
Your key's group has no channel for that model. Check the models supported by your group in the console, or create a key for another group.
Can I use both OpenAI and Anthropic SDKs?
Yes. The same key can call /v1/chat/completions and /v1/messages; billing is consistent.
How do I check my balance?
Your console dashboard shows your balance and usage. You can also call GET /api/user/self using your API key.
How do I top up?
Use the Wallet page in the console. Bank card payments are supported and converted at the current exchange rate.
Why are responses slow or timing out?
Route reliability and latency vary by group, as do rates. If latency is important, choose a group with a more stable route.