開發者 API

為你的產品打造科學圖。

透過一個 API,將文字、草圖或參考圖生成可直接用於發表的科學圖。

查看 API 文檔
create-figure.sh
curl https://api.figurelabs.ai/v1/images/generations \
  -H "Authorization: Bearer $FIGURELABS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "mode": "generations",
    "prompt": "PI3K–AKT signaling pathway"
  }'
202 Accepted · tsk_01JZ9F7KQ2 · processing

一個 API,多種工作流程。

輸入提示詞
文字生成科學圖 input example
輸出科學圖
文字生成科學圖 output example
POST /v1/images/generations
{
  "mode": "generations",
  "prompt": "PI3K–AKT signaling pathway"
}
202 Accepted
{
  "task_id": "tsk_01JZ9F7KQ2",
  "status": "processing"
}
一個端點,自動路由。查看示例
快速開始

提交、輪詢並獲取結果

FigureLabs 使用異步任務,讓你的產品在生成復雜科學圖時仍能保持流暢回應。

  1. 1提交生成請求。
  2. 2儲存返回的 task_id。
  3. 3持續輪詢,直到任務進入最終狀態。
  4. 4在七天內透過輸出 URL 下載結果。
import os, time, requests

headers = {
  "Authorization": f"Bearer {os.environ['FIGURELABS_API_KEY']}"
}
task_response = requests.post(
  "https://api.figurelabs.ai/v1/images/generations",
  headers=headers,
  json={"mode":"generations","prompt":"PI3K–AKT pathway"}
)
task_response.raise_for_status()
task = task_response.json()

while True:
  result_response = requests.get(
    f"https://api.figurelabs.ai/v1/tasks/{task['task_id']}",
    headers=headers
  )
  result_response.raise_for_status()
  result = result_response.json()
  if result["status"] in {"succeeded", "failed", "rejected", "canceled"}:
    break
  time.sleep(3)

if result["status"] != "succeeded":
  raise RuntimeError(result.get("error") or result["status"])
print(result["output_url"])