快速入門
幾分鐘內執行您的第一次生成。所有 1,496 個模型都接受相同類型的請求,並針對圖像、影片和音訊回傳相同的請求物件:在這裡學會一次即可。
1. 取得 API 金鑰
在 https://doitong.com/developers/dashboard#keys 建立金鑰,並將它存放在環境變數中:金鑰只會顯示一次。每個金鑰都可以有自己的預算,因此您可以將一個金鑰交給代理程式,而不必冒整個帳戶遭到使用的風險。GET /account 會回傳您的 API 餘額。
export DOITONG_API_KEY="doitong_..."
curl "https://api.doitong.com/v1/account" \
-H "Authorization: Bearer $DOITONG_API_KEY"
const res = await fetch("https://api.doitong.com/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.com/v1/account",
headers={"Authorization": f"Bearer {os.environ['DOITONG_API_KEY']}"},
)
print(r.json())
執行費用會從您帳戶的 API 餘額 中以 API 點數支付:1,000 API 點數 = $1,每個模型的費用都恰好是其製作者設定的價格。在 https://doitong.com/developers/dashboard#balance 儲值。
2. 先取得報價,再執行
POST /quote/{model_id} 接受輸入 JSON 並回傳確切價格。不需要金鑰,也不收費。使用相同輸入執行時,費用就正好是該報價:報價即為收費金額。(按用量計費的模型例外:其報價是該次執行可能產生的最高費用,未使用的部分會在執行完成後退款。)
curl -X POST "https://api.doitong.com/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.com/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.com/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.com/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.com/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.com/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. 追蹤狀態
如果等待結束時模型仍在處理,您會收到 202 Accepted,其中包含請求的 id 和目前的 status。每個請求都會經歷相同的生命週期:
-
queued已接受並扣款,正在等待工作執行者 -
running模型正在生成內容 -
最終狀態:
succeeded已扣除報價金額;outputs[] 包含我們儲存空間中的 URLfailed已自動退款;錯誤訊息會說明原因canceled在產生結果前停止;已退款
使用其 id 再次讀取請求。這裡同樣支援 ?wait=20,因此簡單的迴圈就足夠:
curl "https://api.doitong.com/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.com/v1/requests/req_8k2m4q7x1z9c3v5b6n0p2r4t?wait=20", { headers })).json();
while (request.status === "queued" || request.status === "running") {
const res = await fetch(`https://api.doitong.com/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.com/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.com/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.com/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 點數表示,並會在執行前顯示於每個模型頁面。每個請求都會帶有 cost,其中包含 credits、usd、charged 和 refunded。請求獲接受時會收費;failed 和 canceled 的請求會自動退款。有些模型會完全依據輸入定價,有些依據您傳送的檔案長度或大小計費,其他模型則收取每次執行的預估價格:無論哪種方式,您支付的都是報價。少數模型(語言和視覺模型、語音、處理時間工具)會按用量計費:報價是該次執行可能產生的最高費用,執行未使用的部分會自動退款。請參閱 定價。
MCP 和 AI 代理程式
使用相同的 Bearer 金鑰,將任何 MCP 用戶端連線至 https://api.doitong.com/v1/mcp。您的代理程式可以搜尋目錄、取得報價並執行模型,也可以將所有文件頁面讀取為 Markdown。
claude mcp add --transport http doitong-models https://api.doitong.com/v1/mcp \
--header "Authorization: Bearer YOUR_API_KEY"
下一步
- 瀏覽 所有模型。每個頁面都有請求建立器,會替您產生程式碼。
- 了解請求生命週期:請求。
- 在每個模型上使用相同的參數名稱:參數。
- 正在使用 AI 程式設計代理程式?提供 https://doitong.com/developers/llms.txt 給它,或連線至 MCP 伺服器。