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
OperationMethodPath
Chat completionsPOST/v1/chat/completions
List modelsGET/v1/models
Check usageGET/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

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

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

StatusMeaningWhat to do
401Key is invalid or deletedCheck that the full key was copied.
403Insufficient balance or model unavailable in this groupTop up or choose a model in your group.
429Too many requestsReduce concurrency or retry later.
500 / 502Upstream errorRetry later; contact support if it persists.
503No available channel for this groupTry 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.