TokenLab

檔案與批次

建立批次 (Create Batch)

從已上傳的 JSONL 檔案建立批次。

POST
/v1/batches

概覽 (Overview)

上傳一個 purpose=batch 的 JSONL 檔案,然後將其 ID 作為 input_file_id 使用。已完成的批次會回傳輸出檔案 ID 與錯誤檔案 ID。

注意事項 (Notes)

  • 批次輸入檔案必須使用 purpose=batch。
  • completion_window 目前固定為 24h。
  • 輸出順序可能與輸入順序不同。請透過 custom_id 來匹配每個結果。
  • 批次項目內不支援串流 (Streaming)。
  • 支援的項目端點為 /v1/chat/completions 與 /v1/embeddings。不支援 /v1/responses。

範例 (Example)

請求

cURL
curl -X POST "https://api.tokenlab.sh/v1/batches" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "input_file_id": "file_abc123",
    "endpoint": "/v1/chat/completions",
    "completion_window": "24h"
  }'

批次價格可能與同步請求不同。請參考建立批次時顯示的價格以及最終帳單。

回應

200 OK
{
  "id": "batch_abc123",
  "object": "batch",
  "endpoint": "/v1/chat/completions",
  "input_file_id": "file_abc123",
  "completion_window": "24h",
  "status": "validating",
  "output_file_id": null,
  "error_file_id": null,
  "created_at": 1706000000
}

重要欄位 (Important fields)

idstring
批次 ID。
statusstring
批次狀態。
output_file_idstring|null
完成後的輸出檔案 ID。

授權

BearerAuth
AuthorizationBearer <token>

API Key 驗證。請在 Dashboard > API > API Keys 建立或管理 API 金鑰。

位置: header

請求標頭

X-TokenLab-Delivery-Policy?string

單次請求傳遞策略。會覆寫 API key 與 Workspace 的預設值。系統會自動優先嘗試 TokenLab Verified,並可能在輸出、請求接受或建立持久性資源前切換至 Official 模式一次。

可選值

  • "auto"
  • "verified"
  • "official"

請求主體

application/json

回應

application/json

application/json

application/json

application/json

application/json