給 AI 代理
給撰寫 VibeQL 整合的程式碼代理與 LLM 的精簡參考,涵蓋正確的呼叫、輪詢與重試規則。
本頁供撰寫 VibeQL 相關程式的程式碼代理與 LLM 使用,以簡要形式列出事實與規則。
基本資訊
- 基礎 URL:
https://vibeql.com。沒有另外的免費或測試主機。 - 驗證標頭:
Authorization: DeepL-Auth-Key $VIBEQL_API_KEY。Authorization: Bearer $VIBEQL_API_KEY也可以。 - 金鑰格式:
vql_後接 40 個字母與數字。請從VIBEQL_API_KEY環境變數讀取。切勿寫死在程式碼中,也不要傳送到瀏覽器。 - 格式:DOCX、PPTX、PDF、TXT。輸出格式與輸入格式相同。
- 語言:34 個目標語言代碼,例如
DE、PT-BR、EN-US、ZH-HANS。EN代表EN-US,PT代表PT-PT,ZH代表ZH-HANS。完整清單:語言。 - 用量以來源字元數計算。每份文件沒有最低用量。
- 不支援:詞彙表、正式語氣、掃描 PDF 的 OCR。請勿產生依賴這些功能的程式碼。
選擇 API 形式
| 情況 | 使用 |
|---|---|
| 新程式碼 | DeepL v2:/v2/translate, /v2/document |
| 使用 DeepL 用戶端程式庫的程式碼 | DeepL v2。將伺服器 URL 設為 https://vibeql.com。 |
| 呼叫 Google Translate v2 的程式碼 | https://vibeql.com/language/translate/v2 |
| 呼叫 Azure Translator v3 的程式碼 | https://vibeql.com 搭配 api-version=3.0 |
| 具備 MCP 工具的代理 | https://vibeql.com/mcp |
翻譯文字
curl https://vibeql.com/v2/translate \
-H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
-H "Content-Type: application/json" \
-d '{"text": ["Hello", "Goodbye"], "target_lang": "DE", "source_lang": "EN"}'
回應:{"translations": [{"detected_source_language": "EN", "text": "Hallo"}, ...]},每個輸入各一項,順序相同。每次請求最多 50 個 text 值與 128 KB。較大的輸入請分批處理。
翻譯文件
POST /v2/document,multipart,欄位為file與target_lang。傳回document_id與document_key。POST /v2/document/{document_id}搭配document_key。傳回status:queued、translating、done或error。- 當
status為done時,以document_key呼叫POST /v2/document/{document_id}/result。回應主體即為檔案。
含退避的輪詢迴圈:
import os, random, time, requests
BASE = "https://vibeql.com"
H = {"Authorization": f"DeepL-Auth-Key {os.environ['VIBEQL_API_KEY']}"}
def translate_file(path: str, out_path: str, target: str, timeout_s: int = 1800) -> None:
with open(path, "rb") as f:
r = requests.post(f"{BASE}/v2/document", headers=H, files={"file": f},
data={"target_lang": target}, timeout=120)
r.raise_for_status()
doc = r.json()
key = {"document_key": doc["document_key"]}
delay, deadline = 2.0, time.monotonic() + timeout_s
while time.monotonic() < deadline:
s = requests.post(f"{BASE}/v2/document/{doc['document_id']}", headers=H, data=key, timeout=30)
s.raise_for_status()
state = s.json()
if state["status"] == "done":
break
if state["status"] == "error":
raise RuntimeError(state.get("error_message", "Translation failed"))
time.sleep(delay + random.uniform(0, 1))
delay = min(delay * 1.5, 30)
else:
raise TimeoutError("Document not done in time")
out = requests.post(f"{BASE}/v2/document/{doc['document_id']}/result", headers=H, data=key, timeout=120)
out.raise_for_status()
with open(out_path, "wb") as f:
f.write(out.content)
檔案會在上傳後 24 小時刪除。請在此之前下載結果。
錯誤與重試
| 狀態 | 是否重試? | 動作 |
|---|---|---|
400 |
不支援 | 修正參數。請參閱 message。 |
403 |
不支援 | 金鑰錯誤、缺少或已撤銷。 |
404 |
不支援 | 文件 ID 或金鑰錯誤,或檔案已過期。 |
413 |
不支援 | 檔案或請求過大。請拆分或改用較小的檔案。 |
456 |
不支援 | 已達到方案每月上限。請停止並告知使用者。 |
429 |
有 | 指數退避加上隨機抖動。 |
500, 502, 504 |
有 | 指數退避加上隨機抖動,重試數次。 |
503 |
有 | 收到 /result 時:文件尚未處理完成。請再次輪詢狀態。 |
DeepL 端點以 {"message": "..."} 形式傳回錯誤。Google 與 Azure 端點則使用各自的錯誤格式。請參閱限制與錯誤。
檔案大小限制
| 方案 | 檔案大小上限 |
|---|---|
| 免費 | 10 MB,10 頁 |
| Beta | 20 MB,300 頁 |
| 付費方案 | 50 MB |
所有方案的限制請見限制與錯誤。
MCP 工具順序
伺服器:https://vibeql.com/mcp,可串流 HTTP,Authorization: Bearer <key>。
translate_document搭配target_lang,以及file_url或file_base64加上filename。它會回傳文件id和狀態。get_document使用該id。每次呼叫之間稍作停頓並重複,直到狀態為done或error。- 將
download_url交給使用者。有效期為 24 小時。
若為短字串,請呼叫 translate_text。呼叫 list_languages 檢查代碼,呼叫 get_usage 檢查剩餘字元。設定方式:MCP 設定。
純文字版文件
- /llms.txt:文件索引。
- /llms-full.txt:所有文件集結成一個檔案。
- 在任一文件網址加上
.md,即可取得 Markdown 格式的頁面。範例:/docs.md、/docs/quickstart.md、/docs/for-ai-agents.md。