快速入门
几分钟内运行您的第一次生成。所有 1,496 个模型都接受相同类型的请求,并为图像、视频和音频返回 相同的请求对象:在这里学会一次即可。
1. 获取 API 密钥
在 https://doitong.com/developers/dashboard#keys 创建密钥,并将其保存到环境
变量中:它只会显示一次。每个密钥都可以拥有自己的预算,因此您可以将一个密钥交给智能体,而不必担心整个账户的风险。GET /account 会返回您的 API 余额。
export DOITONG_API_KEY="doitong_..."
curl "https://api.doitong.ru/v1/account" \
-H "Authorization: Bearer $DOITONG_API_KEY"
const res = await fetch("https://api.doitong.ru/v1/account", {
headers: { Authorization: `Bearer ${process.env.DOITONG_API_KEY}` },
});
console.log(await res.json());
import os
import requests
r = requests.get(
"https://api.doitong.ru/v1/account",
headers={"Authorization": f"Bearer {os.environ['DOITONG_API_KEY']}"},
)
print(r.json())
运行费用从您账户的 API 余额 中以 API 积分支付:1,000 API 积分 = $1,每个模型的费用完全按照其提供方的价格计算。在 https://doitong.ru/developers/dashboard#balance 充值。
2. 先获取报价,再运行
POST /quote/{model_id} 接收输入 JSON 并返回确切价格。它不需要密钥,也不产生费用。使用相同输入运行时,费用正好就是该报价:报价即为扣费金额。(按用量计费的模型例外:其报价是本次运行可能产生的最高费用,未使用部分会在运行结束后退款。)
curl -X POST "https://api.doitong.ru/v1/quote/kling-video/v3/pro/image-to-video" \
-H "Content-Type: application/json" \
-d '{"image": "https://example.com/fox.jpg", "duration": 5, "generate_audio": true}'
const res = await fetch("https://api.doitong.ru/v1/quote/kling-video/v3/pro/image-to-video", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ image: "https://example.com/fox.jpg", duration: 5, generate_audio: true }),
});
const quote = await res.json();
console.log(quote.credits, quote.usd); // 840 "0.84"
import requests
r = requests.post(
"https://api.doitong.ru/v1/quote/kling-video/v3/pro/image-to-video",
json={"image": "https://example.com/fox.jpg", "duration": 5, "generate_audio": True},
)
print(r.json()["credits"], r.json()["usd"]) # 840 0.84
{
"object": "quote",
"model": "kling-video/v3/pro/image-to-video",
"credits": 840,
"usd": "0.84",
"unit": "second",
"quantity": 5,
"unit_credits": 168,
"mode": "exact",
"breakdown": "5 s × 168 API credits"
}
然后将相同的请求体发送到 POST /run/{model_id}。添加 ?wait=20 可将连接保持最多 20 秒:快速模型会在一次往返中返回完成的结果。发送 Idempotency-Key 标头,以确保重试不会运行两次(或扣费两次)。
curl -X POST "https://api.doitong.ru/v1/run/flux/schnell?wait=20" \
-H "Authorization: Bearer $DOITONG_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: lighthouse-001" \
-d '{"prompt": "A lighthouse on a rocky coast at dusk, warm light in the window"}'
const res = await fetch("https://api.doitong.ru/v1/run/flux/schnell?wait=20", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.DOITONG_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": "lighthouse-001",
},
body: JSON.stringify({ prompt: "A lighthouse on a rocky coast at dusk, warm light in the window" }),
});
const request = await res.json();
console.log(request.status, request.outputs[0]?.url);
import os
import requests
r = requests.post(
"https://api.doitong.ru/v1/run/flux/schnell",
params={"wait": 20},
headers={
"Authorization": f"Bearer {os.environ['DOITONG_API_KEY']}",
"Idempotency-Key": "lighthouse-001",
},
json={"prompt": "A lighthouse on a rocky coast at dusk, warm light in the window"},
)
request = r.json()
print(request["status"], request["outputs"][0]["url"] if request["outputs"] else None)
响应是一个请求对象:
{
"id": "req_8k2m4q7x1z9c3v5b6n0p2r4t",
"object": "request",
"model": "flux/schnell",
"status": "succeeded",
"cost": { "credits": 3, "usd": "0.003", "charged": 3, "refunded": 0 },
"outputs": [
{ "type": "image", "url": "https://content.doitong.com/dev-api/2026/10/20/req_8k2m4q7x1z9c3v5b6n0p2r4t/0-output.jpeg",
"content_type": "image/jpeg", "width": 1024, "height": 768, "stored": true }
],
"error": null
}
3. 跟踪状态
如果等待结束时模型仍在处理,您会收到带有请求 id 和当前 status 的 202 Accepted。每个请求都会经过相同的生命周期:
-
queued已接受并扣费,等待工作进程处理 -
running模型正在生成 -
最终状态:
succeeded已扣除报价金额;outputs[] 中包含我们存储服务上的 URLfailed已自动退款;错误信息说明原因canceled在生成结果前停止;已退款
使用请求的 id 再次读取请求。这里同样支持 ?wait=20,因此简单的循环就足够了:
curl "https://api.doitong.ru/v1/requests/req_8k2m4q7x1z9c3v5b6n0p2r4t?wait=20" \
-H "Authorization: Bearer $DOITONG_API_KEY"
const headers = { Authorization: `Bearer ${process.env.DOITONG_API_KEY}` };
let request = await (await fetch("https://api.doitong.ru/v1/requests/req_8k2m4q7x1z9c3v5b6n0p2r4t?wait=20", { headers })).json();
while (request.status === "queued" || request.status === "running") {
const res = await fetch(`https://api.doitong.ru/v1/requests/${request.id}?wait=20`, { headers });
request = await res.json();
}
console.log(request.status, request.outputs[0]?.url);
import os
import requests
headers = {"Authorization": f"Bearer {os.environ['DOITONG_API_KEY']}"}
request = {"id": "req_8k2m4q7x1z9c3v5b6n0p2r4t", "status": "queued"}
while request["status"] in ("queued", "running"):
request = requests.get(
f"https://api.doitong.ru/v1/requests/{request['id']}",
params={"wait": 20},
headers=headers,
).json()
print(request["status"], request["outputs"][0]["url"] if request["outputs"] else None)
当 status 为 succeeded 时,outputs[].url 包含指向我们存储中文件的链接。如果请求 failed 或 canceled,其 API 积分会自动退款,error 会说明原因。取消仍处于 queued 或 running 状态的任何请求:
curl -X POST "https://api.doitong.ru/v1/requests/req_8k2m4q7x1z9c3v5b6n0p2r4t/cancel" \
-H "Authorization: Bearer $DOITONG_API_KEY"
对于长时间的视频任务,您可以跳过轮询,改为传入 webhook_url(参见 Webhooks)。
4. 文件
将任何公共 URL 作为输入,或通过 POST /files 获取上传 URL,将文件 PUT 到该 URL,然后使用返回的 file_url(参见 文件)。成功的请求会在 outputs[] 中列出结果,包括类型、内容类型,以及在已知时提供的尺寸和时长。
curl -X POST "https://api.doitong.ru/v1/files" \
-H "Authorization: Bearer $DOITONG_API_KEY" \
-H "Content-Type: application/json" \
-d '{"filename": "fox.jpg", "content_type": "image/jpeg", "size": 482113}'
错误
每个模型都以相同方式失败:一个包含 type、准确 code、出错的 param 以及 details 中所有问题的信封对象,使智能体无需阅读说明文字即可修复请求。无效请求不会产生任何费用。
{
"error": {
"type": "invalid_request",
"code": "invalid_input",
"message": "duration must be one of 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15.",
"param": "duration",
"details": [ { "param": "duration", "message": "duration must be one of 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15." } ],
"request_id": null,
"doc_url": "https://doitong.com/developers/docs/errors#invalid_input"
}
}
所有类型和代码都列在 错误 中。
定价
价格以 USD 和 API 积分表示,并在运行前显示在每个模型页面上。每个请求都包含带有 credits、usd、charged 和 refunded 的 cost。请求被接受时即会扣费;failed 和 canceled 请求会自动退款。有些模型完全根据输入定价,有些根据您发送的文件长度或大小定价,另一些则按每次运行的预估价格收费:无论哪种情况,报价就是您支付的金额。少数模型(语言和视觉模型、语音、处理时间工具)按用量计费:报价是本次运行可能产生的最高费用,运行未使用的部分会自动退款。参见 定价。
MCP 和 AI 智能体
使用同一个 Bearer 密钥将任何 MCP 客户端连接到 https://api.doitong.ru/v1/mcp。您的智能体可以搜索目录、获取报价并运行模型,还可以以 Markdown 格式读取所有文档页面。
claude mcp add --transport http doitong-models https://api.doitong.ru/v1/mcp \
--header "Authorization: Bearer YOUR_API_KEY"
后续步骤
- 浏览所有模型。每个页面都有一个请求构建器,可为您生成代码。
- 了解请求生命周期:请求。
- 在每个模型中使用相同的参数名称:参数。
- 正在使用 AI 编程智能体?将 https://doitong.com/developers/llms.txt 提供给它,或连接 MCP 服务器。