API 文件

渡口 AI 提供 OpenAI-compatible API。任何支援自訂 Base URL 的 OpenAI SDK、工具或框架都可以直接串接。

快速上手

控制台建立 API Key 後,把 Base URL 指向渡口即可:

https://api.dukou.ai/v1
Python(OpenAI SDK)
from openai import OpenAI

client = OpenAI(
    base_url="https://api.dukou.ai/v1",
    api_key="sk-dukou-********",  # 控制台建立
)

resp = client.chat.completions.create(
    model="deepseek-chat",
    messages=[{"role": "user", "content": "你好"}],
)
print(resp.choices[0].message.content)
Node.js(OpenAI SDK)
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.dukou.ai/v1",
  apiKey: process.env.DUKOU_API_KEY,
});

const resp = await client.chat.completions.create({
  model: "gemini-3-flash",
  messages: [{ role: "user", content: "你好" }],
});
console.log(resp.choices[0].message.content);
AI 程式開發工具
# Claude Code / Cursor / Cline 等工具中,
# 將 OpenAI-compatible Base URL 與 Key 指向渡口:
export OPENAI_BASE_URL="https://api.dukou.ai/v1"
export OPENAI_API_KEY="sk-dukou-********"

認證

所有請求透過 Authorization: Bearer sk-dukou-... 攜帶 API Key。Key 僅在建立時顯示一次,請妥善保管;外洩後請立即在控制台吊銷並建立新 Key(吊銷在 30 秒內全網生效)。

介面

首期開放以下 OpenAI-compatible 介面,後續將增加 /v1/responses/v1/embeddings:

GET/v1/models
POST/v1/chat/completions
curl · 模型列表
curl https://api.dukou.ai/v1/models \
  -H "Authorization: Bearer $DUKOU_API_KEY"
curl · 對話補全
curl https://api.dukou.ai/v1/chat/completions \
  -H "Authorization: Bearer $DUKOU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.2",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "介紹一下你自己"}
    ]
  }'

串流輸出

設定 "stream": true 後,回應以 SSE(Server-Sent Events)增量回傳,與 OpenAI 串流協定一致。

curl · 串流
curl https://api.dukou.ai/v1/chat/completions \
  -H "Authorization: Bearer $DUKOU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-5",
    "stream": true,
    "messages": [{"role": "user", "content": "寫一首關於渡口的短詩"}]
  }'

錯誤與計費

  • 錯誤回應採用 OpenAI 風格錯誤體:{"error": {"message", "type", "code"}}
  • 請求發起時按最大可能費用預佔餘額,結束後按實際 Token 用量結算並釋放差額;餘額不足會回傳 4xx 錯誤。
  • 每次請求的模型、Token 用量、費用與延遲都可以在控制台的用量統計與帳本中查詢。