API 參考文件

V1 LLM API

唯讀 API,供 LLM 代理、自動化腳本與整合應用使用。可存取 Notion 工作空間的圖譜資料,支援搜尋、節點詳細資訊、頁面內容讀取與圖譜走訪。Pro 與 Max 方案皆可使用,包含 US$1.99 的 Pro 週方案。

概覽

屬性 值
基底 URL /v1/graph/
驗證方式 服務權杖(Authorization: Bearer ivg_*)
方案 Pro 和 Max,包含 US$1.99 的 Pro 週方案
格式 JSON
請求頻率限制 突發流量上限為每 10 秒 20 次請求,每 15 分鐘區間上限為 600 次請求
自我描述式規格 GET /v1/(無需驗證)

方案

供 AI 代理使用的 API 包含在月繳或年繳的 Pro 和 Max 方案,以及 US$1.99 的 Pro 週方案中。使用 Free 和 Plus 方案時,所有使用服務權杖的請求都會傳回 403,建立新權杖時也會傳回相同的 403:

{
  "error": "API for AI agents is part of the Pro and Max plans. This account does not have an active Pro or Max plan. Upgrade at https://ivgraph.com/billing/ and your API keys will work right away.",
  "code": "api_plan_required",
  "upgrade_url": "https://ivgraph.com/billing/"
}
  • 請查看 code,而非文字訊息:api_plan_required 表示帳戶的方案不包含 API。
  • 使用不含 API 的方案時,權杖不會遭到刪除或撤銷,只會暫停使用。帳戶一旦使用 Pro 或 Max 方案,同一組權杖就能立即恢復使用。
  • 取消訂閱或試用結束時,權杖也會同樣暫停使用,直到方案重新生效。付款失敗時,要等帳戶轉為 Free 方案,權杖才會暫停:續訂付款失敗後,在 Stripe 重新嘗試扣款期間,方案仍會繼續生效,最長為計費週期開始後的 15 天;若 US$1.99 的 Pro 週方案之後的第一筆付款失敗,帳戶會立即轉為 Free 方案。
  • 無效、已撤銷或已過期的權杖仍會傳回 401:只有在權杖有效時,才會檢查方案。
  • 無論使用哪種方案,都可以撤銷權杖。

常用參數

所有端點皆需提供 workspace_id:

參數 型別 必填 說明
workspace_id string (UUID) 是 Notion 工作空間的 UUID。必須包含在權杖允許的 workspace_ids 中。

端點


GET /v1/graph/search/

依標題搜尋整個工作空間中的節點。若 Elasticsearch 可用,則使用 Elasticsearch,否則改用記憶體內比對。

範圍: graph:search

參數:

參數 類型 必填 預設值 說明
q string 是 — 搜尋字串(最多 256 個字元)
workspace_id string 是 — 目標工作空間的 UUID
limit int 否 20 每頁結果數(最多 50 筆)
type string 否 all 篩選條件:page、database 或 user

請求範例:

curl -H "Authorization: Bearer ivg_your_token" \
  "https://ivgraph.com/v1/graph/search/?q=project&workspace_id=abc-123&limit=5"
import requests

resp = requests.get(
    "https://ivgraph.com/v1/graph/search/",
    headers={"Authorization": "Bearer ivg_your_token"},
    params={"q": "project", "workspace_id": "abc-123", "limit": 5}
)
data = resp.json()
const resp = await fetch(
  "https://ivgraph.com/v1/graph/search/?q=project&workspace_id=abc-123&limit=5",
  { headers: { Authorization: "Bearer ivg_your_token" } }
);
const data = await resp.json();

回覆:

{
  "query": "project",
  "total": 3,
  "results": [
    {"id": "550e8400-e29b-41d4-a716-446655440001", "type": "page", "title": "Project Alpha", "score": 0.95},
    {"id": "550e8400-e29b-41d4-a716-446655440002", "type": "database", "title": "Projects Tracker", "score": 0.72},
    {"id": "550e8400-e29b-41d4-a716-446655440003", "type": "page", "title": "Project Notes", "score": 0.61}
  ]
}

錯誤:

狀態 說明
400 缺少 q 或 workspace_id、查詢過長,或含有不允許的字元
401 缺少服務權杖或權杖無效
403 方案未包含 API(api_plan_required)、權杖缺少 graph:search 權限範圍,或工作空間不在允許清單中
404 此工作空間沒有已同步的資料
429 已超過請求頻率限制

GET /v1/graph/nodes/{node_id}/

取得單一節點及其所有安全欄位:標題、類型、URL、圖示、連結數、pagerank 和屬性。

權限範圍: graph:read

參數:

參數 型別 必填 說明
node_id UUID 是 節點 ID(位於 URL 路徑中)
workspace_id string 是 目標工作空間的 UUID

請求範例:

curl -H "Authorization: Bearer ivg_your_token" \
  "https://ivgraph.com/v1/graph/nodes/550e8400-e29b-41d4-a716-446655440001/?workspace_id=abc-123"
import requests

node_id = "550e8400-e29b-41d4-a716-446655440001"
resp = requests.get(
    f"https://ivgraph.com/v1/graph/nodes/{node_id}/",
    headers={"Authorization": "Bearer ivg_your_token"},
    params={"workspace_id": "abc-123"}
)
node = resp.json()["node"]
const nodeId = "550e8400-e29b-41d4-a716-446655440001";
const resp = await fetch(
  `https://ivgraph.com/v1/graph/nodes/${nodeId}/?workspace_id=abc-123`,
  { headers: { Authorization: "Bearer ivg_your_token" } }
);
const { node } = await resp.json();

回覆:

{
  "node": {
    "id": "550e8400-e29b-41d4-a716-446655440001",
    "type": "page",
    "title": "Project Alpha",
    "url": "https://www.notion.so/Project-Alpha-550e8400e29b41d4a716446655440001",
    "icon": {"type": "emoji", "emoji": "\ud83d\ude80"},
    "connections_in": 5,
    "connections_out": 12,
    "connections_total": 17,
    "pagerank": 0.42,
    "properties": {}
  }
}

錯誤:

狀態碼 說明
400 node_id 格式無效或缺少 workspace_id
401 服務權杖遺漏或無效
403 方案未包含 API(api_plan_required)、權杖缺少 graph:read 權限範圍,或工作空間未獲授權
404 找不到節點,或工作空間沒有已同步的資料
429 已超過請求頻率限制

GET /v1/graph/content/{page_id}/

以 Markdown 和純文字格式取得頁面內容。內容擷取自透過 Airbyte 同步的 Notion 區塊。

權限範圍: graph:read

參數:

參數 類型 必填 說明
page_id UUID 是 頁面 ID(位於網址路徑中)
workspace_id string 是 目標工作空間的 UUID

請求範例:

curl -H "Authorization: Bearer ivg_your_token" \
  "https://ivgraph.com/v1/graph/content/550e8400-e29b-41d4-a716-446655440001/?workspace_id=abc-123"
import requests

page_id = "550e8400-e29b-41d4-a716-446655440001"
resp = requests.get(
    f"https://ivgraph.com/v1/graph/content/{page_id}/",
    headers={"Authorization": "Bearer ivg_your_token"},
    params={"workspace_id": "abc-123"}
)
content = resp.json()
print(content["markdown"])
const pageId = "550e8400-e29b-41d4-a716-446655440001";
const resp = await fetch(
  `https://ivgraph.com/v1/graph/content/${pageId}/?workspace_id=abc-123`,
  { headers: { Authorization: "Bearer ivg_your_token" } }
);
const { markdown, plain_text } = await resp.json();

回覆:

{
  "page_id": "550e8400-e29b-41d4-a716-446655440001",
  "title": "Project Alpha",
  "markdown": "# Project Alpha\n\nThis is the main project page.\n\n## Goals\n\n- Launch beta by Q2\n- Reach 100 users",
  "plain_text": "Project Alpha\nThis is the main project page.\nGoals\nLaunch beta by Q2\nReach 100 users",
  "has_content": true
}

錯誤:

狀態碼 說明
400 page_id 格式無效或缺少 workspace_id
401 缺少服務權杖或服務權杖無效
403 方案不包含 API(api_plan_required)、權杖缺少 graph:read 權限範圍,或工作空間未獲授權
404 找不到頁面,或工作空間沒有已同步的資料
429 已超過請求頻率限制

GET /v1/graph/neighbors/{node_id}/

透過 BFS 走訪,傳回指定深度內的相鄰節點與邊。適合用來探索節點周圍的局部圖譜結構。

範圍: graph:neighbors

參數:

參數 型別 必填 預設值 說明
node_id UUID 是 — 起始節點 ID(位於 URL 路徑中)
workspace_id string 是 — 目標工作空間 UUID
depth int 否 1 遍歷深度(上限為 3)
limit int 否 20 回傳的相鄰節點數上限(最多 50 個)
direction string 否 both 邊的方向:in、out 或 both

請求範例:

curl -H "Authorization: Bearer ivg_your_token" \
  "https://ivgraph.com/v1/graph/neighbors/550e8400-e29b-41d4-a716-446655440001/?workspace_id=abc-123&depth=2&limit=10"
import requests

node_id = "550e8400-e29b-41d4-a716-446655440001"
resp = requests.get(
    f"https://ivgraph.com/v1/graph/neighbors/{node_id}/",
    headers={"Authorization": "Bearer ivg_your_token"},
    params={"workspace_id": "abc-123", "depth": 2, "limit": 10}
)
data = resp.json()
print(f"Found {data['total']} neighbors")
const nodeId = "550e8400-e29b-41d4-a716-446655440001";
const resp = await fetch(
  `https://ivgraph.com/v1/graph/neighbors/${nodeId}/?workspace_id=abc-123&depth=2&limit=10`,
  { headers: { Authorization: "Bearer ivg_your_token" } }
);
const { neighbors, edges, total } = await resp.json();

回覆:

{
  "node_id": "550e8400-e29b-41d4-a716-446655440001",
  "depth": 2,
  "total": 4,
  "neighbors": [
    {"id": "550e8400-e29b-41d4-a716-446655440010", "type": "page", "title": "Sprint Planning"},
    {"id": "550e8400-e29b-41d4-a716-446655440011", "type": "database", "title": "Tasks"},
    {"id": "550e8400-e29b-41d4-a716-446655440012", "type": "page", "title": "Design Doc"},
    {"id": "550e8400-e29b-41d4-a716-446655440013", "type": "user", "title": "Alice"}
  ],
  "edges": [
    {"source": "550e8400-e29b-41d4-a716-446655440001", "target": "550e8400-e29b-41d4-a716-446655440010", "type": "reference"},
    {"source": "550e8400-e29b-41d4-a716-446655440001", "target": "550e8400-e29b-41d4-a716-446655440011", "type": "parent"},
    {"source": "550e8400-e29b-41d4-a716-446655440010", "target": "550e8400-e29b-41d4-a716-446655440012", "type": "mention"},
    {"source": "550e8400-e29b-41d4-a716-446655440012", "target": "550e8400-e29b-41d4-a716-446655440013", "type": "mention"}
  ]
}

錯誤:

狀態碼 說明
400 node_id 格式無效或缺少 workspace_id
401 缺少服務權杖或服務權杖無效
403 方案不包含 API(api_plan_required)、權杖缺少 graph:neighbors 權限範圍,或工作空間未獲授權
404 找不到節點,或工作空間沒有已同步的資料
429 已超過請求頻率限制

POST /v1/graph/traverse/

使用 BFS 找出兩個節點之間的最短路徑。以依序排列的節點清單傳回路徑;若在最大深度範圍內找不到路徑,則傳回 null。

範圍: graph:neighbors

要求本文(JSON):

參數 型別 必填 預設值 說明
start_id UUID 是 — 起始節點
target_id UUID 是 — 目標節點
workspace_id string 是 — 目標工作空間的 UUID
max_depth int 否 3 最大遍歷深度(上限為 3)

請求範例:

curl -X POST "https://ivgraph.com/v1/graph/traverse/" \
  -H "Authorization: Bearer ivg_your_token" \
  -H "Content-Type: application/json" \
  -d '{
    "start_id": "550e8400-e29b-41d4-a716-446655440001",
    "target_id": "550e8400-e29b-41d4-a716-446655440012",
    "workspace_id": "abc-123"
  }'
import requests

resp = requests.post(
    "https://ivgraph.com/v1/graph/traverse/",
    headers={
        "Authorization": "Bearer ivg_your_token",
        "Content-Type": "application/json"
    },
    json={
        "start_id": "550e8400-e29b-41d4-a716-446655440001",
        "target_id": "550e8400-e29b-41d4-a716-446655440012",
        "workspace_id": "abc-123"
    }
)
path = resp.json()["path"]
const resp = await fetch("https://ivgraph.com/v1/graph/traverse/", {
  method: "POST",
  headers: {
    Authorization: "Bearer ivg_your_token",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    start_id: "550e8400-e29b-41d4-a716-446655440001",
    target_id: "550e8400-e29b-41d4-a716-446655440012",
    workspace_id: "abc-123"
  })
});
const { path, path_length } = await resp.json();

回應(已找到路徑):

{
  "start": "550e8400-e29b-41d4-a716-446655440001",
  "target": "550e8400-e29b-41d4-a716-446655440012",
  "path_length": 2,
  "path": [
    {"id": "550e8400-e29b-41d4-a716-446655440001", "type": "page", "title": "Project Alpha"},
    {"id": "550e8400-e29b-41d4-a716-446655440010", "type": "page", "title": "Sprint Planning"},
    {"id": "550e8400-e29b-41d4-a716-446655440012", "type": "page", "title": "Design Doc"}
  ]
}

回應(無路徑):

{
  "start": "550e8400-e29b-41d4-a716-446655440001",
  "target": "550e8400-e29b-41d4-a716-446655440099",
  "path_length": null,
  "path": []
}

錯誤:

狀態碼 說明
400 缺少 start_id/target_id/workspace_id,或其值無效
401 缺少服務權杖,或權杖無效
403 方案未包含 API(api_plan_required)、權杖缺少 graph:neighbors 權限範圍,或工作空間未獲授權
404 找不到起始或目標節點,或沒有已同步的資料
429 已超過請求頻率限制

自我描述式規格

GET /v1/ 會以 JSON 格式傳回完整的 API 規格。無需身分驗證。

curl "https://ivgraph.com/v1/"

這會傳回機器可讀的 JSON,包含所有端點、參數、回應結構定義、速率限制、權限範圍,以及提供 API 的方案,方便 LLM 代理程式以程式化方式探索 API。