跳到內容

30 秒把 SpendGuard 接進來(base URL 工具,一行設定搞定)

如果你的 agent stack 已經在用 OpenAI 相容的 client,那 SpendGuard 只要改一個 base URL 就接得進來。把 SpendGuard 的 egress proxy 起在 http://localhost:9000/v1,把工具指過去,之後每一次 model call 都會先走過 SpendGuard 的 pre-call budget gate 和 KMS-signed 稽核鏈,才真正打到上游 供應商。不用裝 SDK、不用改程式碼、也不用重 build。在下面的對照表找到你的工具, 照它官方文件指定的那一行抄過來,下一次呼叫就受管控了。

這些工具本來就支援自訂 OpenAI 相容的 base URL。SpendGuard 自己也跑了一個 OpenAI 相容的 endpoint;只要設好環境變數(或一行設定),工具的流量在送到 OpenAI / Anthropic / Bedrock 之前就會先繞進 SpendGuard。Pattern 2 跟另外兩種模式不一樣: Pattern 1 是 in-process SDK middleware(adapter 整合用的那種),Pattern 3 則是 egress proxy 加裝 CA(給 Claude Code、Codex 這類封閉的 BYOK CLI 用)。

Terminal window
git clone https://github.com/m24927605/agentic-spendguard.git
cd agentic-spendguard
export OPENAI_API_KEY=sk-...
make demo-up DEMO_MODE=proxy

egress proxy 會綁在 http://localhost:9000/v1。下面任何一個工具都指到這個 URL 就行。

找到你的工具

這張對照表列的是每個工具官方文件指定的環境變數名稱或設定 key。已驗證 這一欄 是要區分三種狀態:我們真的對 egress proxy 端到端跑過的(Live)、設定跟官方 公開文件一致但我們自己沒實際 smoke 過的(Spec)、以及工具自家 changelog 原生 就有記載、不需要針對 SpendGuard 另外測的(Vendor-native)。

可以先用下面的快速篩選器照設定型態(環境變數、設定檔、或 admin UI)縮小範圍、 用工具名稱搜尋,然後直接跳到對應工具的段落。

Filter by setting type

Showing all 14 tools.

Tool Vendor Setting type What to set Verified Jump
LiteLLM (proxy mode) LiteLLM Env var export OPENAI_API_BASE=http://localhost:9000/v1 Spec Jump ↓
Aider Aider Env var export OPENAI_API_BASE=http://localhost:9000/v1 Spec Jump ↓
Continue Continue Config file apiBase: http://localhost:9000/v1 Spec Jump ↓
Cline / Roo Code (BYOK) Cline Admin UI OpenAI Compatible provider, Base URL http://localhost:9000/v1 Spec Jump ↓
OpenHands (BYOK) All Hands AI Admin UI Settings → LLM → Custom Provider → Endpoint Spec Jump ↓
Goose Block Env var export OPENAI_HOST=http://localhost:9000 Spec Jump ↓
Zed AI Zed Config file api_url = "http://localhost:9000/v1" Vendor-native Jump ↓
GitHub Copilot CLI (BYOK) GitHub Env var export COPILOT_PROVIDER_BASE_URL=http://localhost:9000/v1 Vendor-native Jump ↓
Tabnine Enterprise Tabnine Admin UI Admin → AI Models → Connect Custom LLM → Endpoint URL Spec Jump ↓
AnythingLLM Mintplex Labs Admin UI Admin → LLM Configuration → Custom OpenAI-compatible base URL Spec Jump ↓
LobeChat LobeHub Admin UI Settings → Language Model → Custom Base URL Spec Jump ↓
Cody self-hosted Sourcegraph Config file cody.completions.endpoint in site-config.json Spec Jump ↓
Augment (BYOK) Augment Admin UI Settings → BYOK → LLM Custom Endpoint Spec Jump ↓
Dify Dify Config file Custom Model Provider plugin manifest: base_url Spec Jump ↓

下面這張靜態對照表附了上游來源連結,以及本頁後面會引用的列號;上面的篩選器只是 同一份資料的快速篩選層。

| # | 工具 | Provider 欄位 | 確切值 | 上游來源 | 已驗證 | Recipe | |---|------|----------------|-------------|-----------------|----------|--------| | 1 | LiteLLM (proxy mode) | 環境變數 | OPENAI_API_BASE=http://localhost:9000/v1 | docs.litellm.ai | Spec | 開啟 ↗ | | 2 | Aider | 環境變數 | OPENAI_API_BASE=http://localhost:9000/v1 | aider.chat | Spec | 開啟 ↗ | | 3 | Continue | YAML apiBase | apiBase: http://localhost:9000/v1 | docs.continue.dev | Spec | 開啟 ↗ | | 4 | Cline / Roo Code (BYOK) | UI 欄位 | Custom OpenAI provider,Base URL http://localhost:9000/v1 | docs.cline.bot | Spec | 開啟 ↗ | | 5 | OpenHands (BYOK) | UI 欄位 | LLM custom endpoint http://localhost:9000/v1 | docs.all-hands.dev | Spec | 開啟 ↗ | | 6 | Goose | 環境變數 | OPENAI_HOST=http://localhost:9000 | block.github.io/goose | Spec | 開啟 ↗ | | 7 | Zed AI | TOML key | api_url = "http://localhost:9000/v1" | zed.dev | Vendor-native | 開啟 ↗ | | 8 | GitHub Copilot CLI (BYOK) | 環境變數 | COPILOT_PROVIDER_BASE_URL=http://localhost:9000/v1 | docs.github.com | Vendor-native | 開啟 ↗ | | 9 | Tabnine Enterprise | Admin UI | BYO LLM endpoint http://localhost:9000/v1 | docs.tabnine.com | Spec | 開啟 ↗ | | 10 | AnythingLLM | Admin UI | Generic OpenAI provider,Base URL http://localhost:9000/v1 | docs.anythingllm.com | Live | 開啟 ↗ | | 11 | LobeChat | 環境變數 | OPENAI_PROXY_URL=http://localhost:9000/v1 | lobehub.com | Live | 開啟 ↗ | | 12 | Cody self-hosted Enterprise | Site config | Sourcegraph relay endpoint http://localhost:9000/v1 | sourcegraph.com | Spec | 開啟 ↗ | | 13 | Augment (BYOK) | UI 欄位 | LLM custom endpoint http://localhost:9000/v1 | docs.augmentcode.com | Spec | 開啟 ↗ | | 14 | Dify | Plugin manifest | Custom Model Provider plugin → base URL http://localhost:9000/v1 | docs.dify.ai | Spec | 開啟 ↗ | | 15 | CrewAI Studio (via LiteLLM) | 間接 | 用第 1 列 —— 把 CrewAI 指向 LiteLLM proxy,再把 LiteLLM 指向 SpendGuard | docs.litellm.ai | Spec | 開啟 ↗ | | 16 | OpenClaw | 設定檔 | models.providers.spendguard.baseUrl: http://localhost:9000/v1,搭配 api: "openai-completions" | github.com/openclaw/openclaw | Live | 開啟 ↗ |

已經在 production 跑 SpendGuard 了嗎?把 http://localhost:9000/v1 換成你自己 SpendGuard egress proxy 的 URL —— 可能是 Kubernetes Service URL、pod 內的 sidecar URL、或一個 hosted 的 SpendGuard URL。相對路徑永遠是 /v1。production hostname 的寫法可以看 Helm 部署指南

下面每一段都是上面對照表連過來的 H3 anchor。把 code block 抄起來、設到你的 shell 或設定檔裡,那個工具下一次呼叫就會走 SpendGuard。完整的操作流程 —— 驗證步驟和 已知的雷 —— 在 sidebar 裡每個工具自己的 recipe 頁面。

LiteLLM

LiteLLM proxy mode 在你設了 OpenAI provider、但 route 上沒明確指定 base URL 時, 就會去讀 OPENAI_API_BASE 當上游 endpoint。在跑 litellm --config config.yaml 之前先 export 這個變數(或寫進 config.yaml 的 environment 區塊)。

Terminal window
export OPENAI_API_BASE=http://localhost:9000/v1

來源:LiteLLM proxy config settings

Aider

Aider 會從環境抓 OPENAI_API_BASE,每一次 chat completion 都走它。在你啟動 aider 的那個 shell 裡設好這個環境變數就好。

Terminal window
export OPENAI_API_BASE=http://localhost:9000/v1

來源:Aider OpenAI-compatible APIs guide

Continue

Continue 會從 config.yaml 裡每個 model entry 讀 apiBase(OpenAI provider 是放在該 model 的 config 區塊底下)。改完 YAML,再重新載入 IDE extension。

models:
- name: SpendGuard-gated GPT-4o
provider: openai
model: gpt-4o
config:
apiBase: http://localhost:9000/v1

來源:Continue model customization

Cline / Roo Code (BYOK)

在 Cline 或 Roo Code 的 extension 設定裡,選 OpenAI Compatible 這個 provider, 然後填 Base URL 欄位。不用環境變數 —— 這是純 UI 設定,會存在 workspace 設定裡。

Provider: OpenAI Compatible
Base URL: http://localhost:9000/v1
API Key: <any value the proxy will forward upstream>

來源:Cline BYOK guide

OpenHands (BYOK)

OpenHands 的 UI 在 Settings → LLM → Custom Provider 底下有個 Custom LLM endpoint 欄位。把 SpendGuard 的 egress URL 填進去,OpenHands 之後 workspace 裡每一次 model call 都會用它。

Settings → LLM → Custom Provider → Endpoint
http://localhost:9000/v1

來源:OpenHands custom LLM configs

Goose

Goose 讀的是 OPENAI_HOST(是 host,不是完整 base URL —— OpenAI provider 的 /v1 是 Goose 自己接上去的)。在你啟動 goose 的那個 shell 裡 export 這個變數。

Terminal window
export OPENAI_HOST=http://localhost:9000

來源:Goose installation guide

Zed AI

Zed AI 的設定是寫在 settings.json 裡的 TOML(Zed 會看副檔名決定讀 JSON 還是 TOML)。在 OpenAI provider 區塊加一個 api_url

[ai.openai]
api_url = "http://localhost:9000/v1"

來源:Zed AI configuration

GitHub Copilot CLI (BYOK)

gh copilot 在 GA-2026-04-07 那版 BYOK release 之後,OpenAI 相容 provider 會吃 COPILOT_PROVIDER_BASE_URL。export 這個變數,gh copilot 下一次叫起來就會抓到。

Terminal window
export COPILOT_PROVIDER_BASE_URL=http://localhost:9000/v1

來源:GitHub Copilot CLI BYOK reference

Tabnine Enterprise

Tabnine Enterprise 的 admin UI 有個 Connect Custom LLM 表單,給 self-hosted endpoint 用。把 SpendGuard 的 egress URL 貼進 endpoint 欄位存檔,這個變更就會推到 該 tenant 上每一個 Tabnine seat。

Admin → AI Models → Connect Custom LLM → Endpoint URL
http://localhost:9000/v1

來源:Tabnine connect custom LLM

AnythingLLM

AnythingLLM 在 Settings → LLM Preference 底下附了一個 Generic OpenAI provider 卡片。選那張卡片,把 Base URL 設成你的 SpendGuard egress endpoint (結尾的 /v1 不能少),API Key 隨便填一個非空值就好。完整的逐步操作 —— 四個確切欄位、Docker / Desktop / Cloud 的注意事項、還有 DEMO_MODE=anythingllm_real 那個 smoke —— 都在 AnythingLLM recipe 裡。

Settings → LLM Preference → Generic OpenAI → Base URL
http://localhost:9000/v1

來源:AnythingLLM custom OpenAI base URL

LobeChat

LobeChat 會吃一個 OPENAI_PROXY_URL 環境變數,把 /api/chat/openai 上每一次 server 端 chat 的 OpenAI 上游改寫掉。在 container 啟動時設好,每一次 chat 就會 走 SpendGuard,完全不用動 LobeChat 的程式碼。完整的逐步操作 —— Docker / Vercel / Cloud / Client-mode 的注意事項、還有 DEMO_MODE=lobechat_real 那個 smoke —— 都在 LobeChat recipe 裡。

docker run -e OPENAI_PROXY_URL=http://localhost:9000/v1 \
-e ACCESS_CODE=... -p 3210:3210 lobehub/lobe-chat:1.40.0

來源:LobeChat — OPENAI_PROXY_URL env var

OpenClaw

OpenClaw 支援在 models.providers 底下放 custom provider entry。把 provider 的 baseUrl 設成 SpendGuard 的 egress endpoint,OpenAI 相容的 chat 流量就用 api: "openai-completions"。完整的逐步操作 —— fixture 設定、本機 / Docker URL、 DEMO_MODE=openclaw_base_url 那個 smoke、以及 D40b plugin 的邊界 —— 都在 OpenClaw recipe 裡。

{
"models": {
"providers": {
"spendguard": {
"baseUrl": "http://localhost:9000/v1",
"api": "openai-completions"
}
}
}
}

來源:OpenClaw model providers

Cody self-hosted Enterprise

Sourcegraph Cody self-hosted 是用一個 site-config 區塊來設 completions relay endpoint。改 site-config.json,把 relay 指向 SpendGuard。

{
"cody.completions.endpoint": "http://localhost:9000/v1"
}

來源:Cody self-hosted install guide

Augment (BYOK)

Augment 的 BYOK 流程在 workspace 設定頁上有個 LLM custom endpoint 欄位。 把 SpendGuard 的 URL 貼進去存檔,Augment 之後每一次 model call 都用它。

Settings → BYOK → LLM Custom Endpoint
http://localhost:9000/v1

來源:Augment BYOK setup

Dify

Dify 是透過它的 Model Provider Plugin 機制來接 OpenAI 相容的自訂 endpoint。 plugin manifest 裡會宣告 base URL;把它載進你的 Dify workspace,再選它當預設 provider 就好。

type: model-provider
provider: openai-compatible
base_url: http://localhost:9000/v1

來源:Dify model provider plugin

上面那張對照表就是 drop-in 範圍:截至 2026-06-06,官方文件已經公開記載 支援自訂 OpenAI 相容 base URL 的那些工具。已驗證 欄位反映的是 SpendGuard 自己對每一列的宣稱;至於那些 runtime 真的驗過的 client SDK(openai-python、 LangChain ChatOpenAI、LangGraph、openai-agents 簡寫、串流),請看 README 的 What works today 那張表。

上面 Recipe 欄位連到的各工具深入頁面,就是 SLICE-2 / D33 / D34 的逐步操作 (前置條件、確切設定區塊、驗證步驟、雷區)。在 Slice 1 階段,每個 開啟 ↗ 連結都還會落到一個 Coming soon 的 stub;那個工具的環境變數或設定那一行, 上面的對照表有,本頁各工具的 H3 段落也再寫了一次。