跳至主要內容

API、CLI 與 MCP

你在應用程式裡能做的事,也能透過程式碼和代理程式完成:提交連結、上傳檔案或整個帳號,等貼文標記完成後查看結果。三種使用方式,共用同一套規格。工作會以非同步方式處理,重複送出不會重複扣款,而且處理前後都能查看費用。

第一次使用 Garfunkel?看看貼文如何分析。

快速開始

在應用程式的設定 → 開發者建立 API 金鑰,將金鑰設為 GARFUNKEL_API_KEY,再選擇使用方式。MCP 用戶端也可以透過 OAuth 登入,不必使用金鑰。

export GARFUNKEL_API_KEY=gma_live_…
garfunkel submit urls.txt --category sports --dry-run
garfunkel submit urls.txt --category sports --wait
garfunkel results export job_… --format jsonl

驗證

傳送 Authorization: Bearer gma_live_…,也就是組織專用的 API 金鑰,可在API 金鑰頁面取得。CLI 和 MCP 會讀取 GARFUNKEL_API_KEY。每個 POST 請求都接受 Idempotency-Key;重送會回傳原本的回應,不會重複扣款。

提交工作

提交後會立即回傳工作 ID(202)。priority 可設為 standard(費用較低,處理時間從幾分鐘到幾小時不等)或 fast。設定 dry_run: true,即可免費估價並逐項驗證資料。

curl -X POST https://garfunkel.gar-ai.com/api/v1/jobs \
  -H "Authorization: Bearer $GARFUNKEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: $(uuidgen)" \
  -d '{
    "items": [{ "url": "https://www.tiktok.com/@user/video/7412345678901234567" }],
    "options": { "translate_to": "en" },
    "dry_run": true
  }'

項目狀態:queued → fetching → processing → succeeded | failed | canceled。

帳號工作

「自 2025-01-01 起,@handle 的每篇貼文。」每 20 篇團隊尚未計數的新貼文收取 2¢,與分析費分開計算。接著工作會進入 awaiting_confirmation,並顯示各帳號的 posts_found、oldest_post_at、reached_since 和 notices(例如平台只能提供較晚日期之後的貼文)。使用 POST /jobs/{id}/confirm 確認:可用 "selection": { "latest": 50 } 選取最新貼文,或用 "selection": { "top": { "metric": "views", "n": 50 } } 依某項指標選取熱門貼文。也可以設定 options.max_credits,讓系統自動確認。

{
  "items": [
    { "account": "@nike", "platform": "tiktok", "since": "2025-01-01", "max_posts": 1000 },
    { "account": "https://x.com/nasa", "since": "2025-01-01" }
  ],
  "options": { "max_credits": 50000 }
}

上傳

檔案會直接上傳至儲存空間,不會經過 API。上傳後 24 小時內未附加至工作的檔案會被刪除。

POST /api/v1/uploads
{ "filename": "clip.mp4", "content_type": "video/mp4", "size_bytes": 1234567 }
→ { "id": "upl_…", "upload_url": "<presigned PUT>", "method": "PUT", "headers": {…}, "expires_at": "…" }

# PUT the bytes straight to storage, then submit { "upload_id": "upl_…" } as a job item.

結果

一篇已分析的貼文。只有指定 ?include=embedding 時才會回傳嵌入向量。pacing 是透過鏡頭偵測取得的資訊(測試版)。

{
  "item_id": "itm_01J…",
  "job_id": "job_01J…",
  "source": { "platform": "tiktok", "url": "…", "author": "…", "posted_at": "…",
              "metrics": { "views": 0, "likes": 0, "comments": 0, "shares": 0 } },
  "caption": "…",
  "language": "es",
  "transcript": { "text": "…", "segments": [{ "start": 0.0, "end": 2.1, "text": "…" }] },
  "translation": { "language": "en", "caption": "…", "transcript": "…", "on_screen_text": "…" },
  "summary": "…",
  "tags": { "format": "…", "theme": "…", "tone": ["…"], "topics": ["…"], "keywords": ["…"] },
  "hook": { "type": "…", "timing_s": 1.2, "confidence": 0.8 },
  "pacing": { "beta": true, "shot_count": 14, "avg_shot_s": 2.1, "cuts_per_s": 0.47, "first_cut_s": 0.9 },
  "embedding": { "dims": 1024 },
  "credits_charged": 50,
  "processed_at": "…"
}

端點

端點功能
POST /api/v1/jobs提交網址、上傳檔案或帳號(設定 dry_run 可免費估價)。
GET /api/v1/jobs/{id}查看狀態、各狀態的項目數、已預留/扣除/退回的金額(美分)、帳號和通知。
GET /api/v1/jobs/{id}/items以分頁方式列出項目;使用 ?status=failed 篩選。
POST /api/v1/jobs/{id}/confirm選擇要分析哪些等待確認的帳號工作貼文:全部、最新 N 則,或依指標挑選的前 N 則。
POST /api/v1/jobs/{id}/cancel取消等待確認的訂單或加值。訂單開始後就無法取消;分析失敗的貼文不會收費。
POST /api/v1/jobs/{id}/retry重試失敗的項目(重新估價並預留費用)。
POST /api/v1/uploads透過預簽名 PUT 上傳自己的媒體檔案。
GET /api/v1/results使用 job_id, platform, tag, q 篩選。
POST /api/v1/results/search搜尋嵌入向量的語意內容。
GET /api/v1/results/export以串流方式輸出 CSV 或 JSONL。
GET /api/v1/credits餘額(美分 + balance_usd)、保留款項、儲值包、消費回饋。
DELETE /api/v1/data刪除貴組織的所有資料。

錯誤

所有非 2xx 回應都使用相同格式。錯誤代碼:unauthorized, forbidden, not_found, invalid_request, insufficient_credits, rate_limited, idempotency_conflict, counting_in_progress, internal_error。

{ "error": { "code": "insufficient_credits",
             "message": "Job needs $1.80; your balance is 42¢.",
             "details": { "required": 180, "balance": 42 },
             "retryable": false } }

單筆項目的失敗代碼固定不變,而且不會收費:

post_not_found這則貼文已不存在。
post_private這則貼文不是公開貼文。
unsupported_url這不是 TikTok、Instagram 或 X 的貼文網址。
media_unavailable平台沒有傳回媒體檔案。
media_too_large檔案超過大小上限。
upload_invalid無法讀取上傳的檔案。
provider_error上游服務發生錯誤,可以重試。
internal_error我們這邊發生錯誤,可以重試。

CLI

export GARFUNKEL_API_KEY=gma_live_…

garfunkel submit urls.txt --category sports --dry-run   # free estimate
garfunkel submit urls.txt --category sports --wait      # run it
garfunkel results export job_… --format jsonl -o results.jsonl

# Whole accounts: 2¢ per 20 new posts counted, charged separately from analysis; pick its latest 50
garfunkel submit --accounts accounts.txt --since 2025-01-01
garfunkel jobs confirm job_… --latest 50

結束代碼:0 成功、2 用法錯誤、3 驗證失敗、4 餘額不足、5 作業完成但有項目失敗、6 逾時。

MCP

將 Claude、ChatGPT、Cursor 或任何 MCP 用戶端連線到團隊已分析的貼文。這個伺服器使用遠端 MCP Streamable HTTP,網址如下:

https://garfunkel.gar-ai.com/api/mcp

兩種登入方式

  • OAuth 適用於 Claude、ChatGPT 和 Claude Code:新增伺服器位址,登入 Garfunkel,選擇團隊並核准。若要唯讀存取,請在核准畫面關閉 允許支出。您可以在 設定 → AI 助理 查看已連結的應用程式,或中斷連線。
  • API 金鑰 適用於 Cursor、指令碼和無介面代理:傳送 Authorization: Bearer gma_live_…。金鑰可執行團隊能做的所有操作,包括從帳戶餘額扣款;直到您在 設定 → 開發人員 撤銷金鑰前都有效。

Claude(網頁版和桌面版)

  1. 在 Claude 中開啟 自訂 → 連接器,選擇 + 新增,再選 新增自訂連接器。
  2. 將名稱設為 Garfunkel,貼上伺服器位址,然後選擇 繼續。
  3. 驗證方式維持 立即登入,OAuth 用戶端設為 自動註冊,然後選擇 新增。
  4. 登入 Garfunkel,選擇團隊並核准。
  5. 在聊天中開啟 + → 連接器,確認 Garfunkel 已啟用。

所有 Claude 方案都能使用自訂連接器;免費方案可新增一個。Team 和 Enterprise 方案需由擁有者先到 組織設定 → 連接器 新增連接器,再由每位成員選擇 連線。

Claude Code

claude mcp add --transport http garfunkel https://garfunkel.gar-ai.com/api/mcp

接著在 Claude Code 執行 /mcp,選擇 garfunkel,再選 驗證。瀏覽器會開啟一次,讓您登入並核准。

如果是在沒有瀏覽器的環境(例如 CI 或遠端機器)使用,請改傳送 API 金鑰:

claude mcp add --transport http garfunkel https://garfunkel.gar-ai.com/api/mcp \
  --header "Authorization: Bearer $GARFUNKEL_API_KEY"

加入 --scope user 即可在所有專案中使用。--scope project 會將伺服器設定寫入 .mcp.json,供儲存庫中的所有人使用;在這裡分享時請使用 OAuth,絕不可放入金鑰。

ChatGPT

  1. 在 ChatGPT 中開啟 外掛程式,選擇 +,再選 新增自訂 MCP 伺服器。
  2. 將名稱設為 Garfunkel。在 連線 區選擇公開端點,並貼上伺服器位址。
  3. 驗證方式選擇 OAuth,並將用戶端欄位留空,ChatGPT 會自動註冊。接受警告後,選擇 建立為外掛程式。
  4. 登入 Garfunkel,選擇團隊並核准。
  5. 在新聊天中輸入 @,然後選擇 Garfunkel。

能否使用自訂 MCP 伺服器,取決於您的方案和工作空間政策。如果找不到這個選項,請洽詢工作空間管理員。每次工具要從您的餘額扣款前,ChatGPT 都會先詢問您。請在 Garfunkel 儲值:ChatGPT 沒有結帳功能。

Cursor

Cursor 使用 API 金鑰連線,因為 Garfunkel 的 OAuth 無法返回 Cursor 的登入回呼網址。請在 設定 → 開發人員 建立金鑰,並將以下內容加入 ~/.cursor/mcp.json(供所有專案使用),或 .cursor/mcp.json(僅供目前專案使用):

{
  "mcpServers": {
    "garfunkel": {
      "url": "https://garfunkel.gar-ai.com/api/mcp",
      "headers": {
        "Authorization": "Bearer gma_live_…"
      }
    }
  }
}

檔案 .cursor/mcp.json 含有金鑰時,請勿將它提交到 git。

其他用戶端

任何支援以 Streamable HTTP 連線遠端 MCP 的用戶端都能使用。使用 OAuth 時,用戶端會根據伺服器位址自行找到登入方式(透過 PKCE 動態註冊用戶端),因此請將用戶端 ID 和密鑰留空。不使用 OAuth 時,請傳送 API 金鑰標頭。讀取 mcpServers 檔案的用戶端可使用以下設定:

{
  "mcpServers": {
    "garfunkel": {
      "type": "http",
      "url": "https://garfunkel.gar-ai.com/api/mcp",
      "headers": {
        "Authorization": "Bearer gma_live_…"
      }
    }
  }
}

若要測試連線,請執行 npx @modelcontextprotocol/inspector,選擇 Streamable HTTP,貼上伺服器位址,再使用 快速 OAuth 流程或新增標頭。

試用看看

直接用一般說法提問。產生任何費用前,助理會先顯示價格,等您確認後才會繼續。

  • 「估算標記這 3 支 TikTok 的費用,再告訴我它們用了哪些吸睛開場類型。」
  • 「在我們分析過的貼文中,哪些吸睛開場最適合 @nba?」
  • 「這篇貼文為什麼有效?」並附上連結或項目 ID。

Claude 也提供可直接使用的斜線指令:audit_account, why_post_worked, comment_insights, compare_accounts, what_to_make_next。資源 garfunkel://guide 說明了每個結果欄位。

工具:estimate_job, submit_job, create_upload, confirm_job, list_job_posts, get_job, get_team, wait_for_job, list_results, get_result, list_accounts, get_account, analyze_comments, refresh_metrics, get_comments, search_results, export_results, chat_with_data, get_credit_balance, show_post, create_checkout。

無法連線時

  • 找不到新增伺服器的選項:您的方案或工作空間目前不允許使用自訂連接器。請洽詢工作空間管理員。
  • 401 或「需要驗證」:請重新登入(在 Claude Code 中執行 /mcp → 驗證)。如果使用金鑰,請確認金鑰開頭是 gma_live_,而且尚未撤銷。
  • 工具要求更多權限:您核准時關閉了支出權限。請中斷應用程式連線,再重新連線並開啟 允許支出。
  • 看不到新工具:請重新整理連線(在 ChatGPT 中選擇外掛程式上的 重新整理),或重新連線。用戶端會快取工具清單。