APIリファレンス

V1 LLM API

LLMエージェント、自動化スクリプト、インテグレーション向けの読み取り専用APIです。Notionのワークスペースのグラフデータにアクセスし、検索、ノードの詳細やページのコンテンツの取得、グラフの探索ができます。$1.99でProを1週間利用できるプランを含む、ProおよびMaxプランでご利用いただけます。

概要

プロパティ 値
ベースURL /v1/graph/
認証 サービストークン(Authorization: Bearer ivg_*)
対象プラン ProおよびMax($1.99のPro週間プランを含む)
形式 JSON
レート制限 バースト時:10秒あたり20リクエスト、15分間のウィンドウあたり600リクエスト
自己記述型の仕様 GET /v1/(認証不要)

料金プラン

AIエージェント向けAPIは、ProプランとMaxプラン(月払い・年払い)、および$1.99のPro 1週間プランに含まれています。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日間プランが引き続き有効です。$1.99のPro 1週間プランの後の最初の支払いに失敗した場合は、アカウントがただちにFreeに移行します。
  • 無効なトークン、失効させたトークン、有効期限切れのトークンは、引き続き 401 を返します。プランの確認は、有効なトークンに対してのみ行われます。
  • どのプランでもトークンを失効させることができます。

共通パラメータ

すべてのエンドポイントでworkspace_idが必要です。

パラメーター 型 必須 説明
workspace_id string (UUID) はい NotionワークスペースのUUIDです。トークンで許可されたworkspace_idsに含まれている必要があります。

エンドポイント


GET /v1/graph/search/

ワークスペース全体のノードをタイトルで検索できます。Elasticsearchが利用可能な場合はそれを使用し、利用できない場合はメモリ内で照合します。

スコープ: graph:search

パラメーター:

パラメーター 型 必須 デフォルト 説明
q string はい — 検索クエリ(最大256文字)
workspace_id string はい — 対象ワークスペースのUUID
limit int いいえ 20 1ページあたりの検索結果数(最大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、アイコン、接続数、ページランク、プロパティ)を含む単一のノードを取得します。

スコープ: 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(URLパス内)
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で2つのノード間の最短経路を検索します。経路上のノードを順番に並べたリストを返します。指定された最大深度内に経路が存在しない場合は、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/ は、API仕様全体をJSON形式で返します。認証は不要です。

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

これにより、すべてのエンドポイント、パラメータ、レスポンススキーマ、レート制限、スコープ、APIを利用できるプランを含む、機械可読なJSONが返されます。LLMエージェントがプログラムを通じてAPIを把握するのに役立ちます。