11# floe-guard
22
3+ [ ![ PyPI version] ( https://img.shields.io/pypi/v/floe-guard.svg )] ( https://pypi.org/project/floe-guard/ )
4+ [ ![ Downloads] ( https://static.pepy.tech/badge/floe-guard/month )] ( https://pepy.tech/project/floe-guard )
5+ [ ![ Python versions] ( https://img.shields.io/pypi/pyversions/floe-guard.svg )] ( https://pypi.org/project/floe-guard/ )
6+ [ ![ License: MIT] ( https://img.shields.io/badge/license-MIT-green.svg )] ( LICENSE )
7+
38** A local budget guardrail for AI agents.** It hard-stops your agent * before its
49next LLM call* when it would cross a spend ceiling — so a runaway loop dies at
510$0.10 instead of $4,000. No account, no signup, no network. Runs in your process.
@@ -26,8 +31,9 @@ BUDGET EXCEEDED — call blocked
2631 The next call would cross your budget; floe-guard stopped your agent before it ran.
2732```
2833
29- _ Animated demo coming — run ` python examples/runaway_loop.py ` to watch it stop a loop live._
30- <!-- TODO: record docs/stop-the-loop.gif and restore the embed:  -->
34+ ![ floe-guard hard-stopping a runaway loop before it crosses a $0.10 ceiling] ( docs/stop-the-loop.gif )
35+
36+ _ Run it yourself: ` python examples/runaway_loop.py ` — no API key, no account, no network._
3137
3238## See it stop a loop (no API key needed)
3339
@@ -108,6 +114,25 @@ response = guarded_completion(guard, model="gpt-4o", messages=[...])
108114Prefer the LiteLLM-native callback? Register ` budget_guard_callback(guard) ` on
109115` litellm.callbacks ` .
110116
117+ ### LangChain
118+
119+ ``` bash
120+ pip install floe-guard[langchain] langchain-openai # langchain-openai only for the ChatOpenAI example below
121+ ```
122+
123+ ``` python
124+ from langchain_openai import ChatOpenAI
125+ from floe_guard import BudgetGuard
126+ from floe_guard.integrations.langchain import budget_guard_callback_handler
127+
128+ guard = BudgetGuard(limit_usd = 1.00 )
129+ llm = ChatOpenAI(model = " gpt-4o" , callbacks = [budget_guard_callback_handler(guard)])
130+ llm.invoke(" hello" ) # checks budget before the call, records spend after
131+ ```
132+
133+ The handler checks the budget on LLM start (raising ` BudgetExceeded ` aborts the
134+ call before it runs) and records token usage on LLM end.
135+
111136### Vercel AI SDK
112137
113138The Vercel AI SDK is TypeScript-only, so it ships as a separate npm package that
@@ -133,10 +158,6 @@ The middleware `check()`s before each call (throwing `BudgetExceeded` to halt th
133158run) and ` record() ` s priced usage after — same semantics as the Python guard. See
134159[ ` js/README.md ` ] ( js/README.md ) .
135160
136- ### Coming next
137-
138- LangChain (callback) is next. Open an issue if you want one sooner.
139-
140161## Honest about what this is
141162
142163floe-guard is a ** local, estimate-based** guardrail. It prices tokens from a
@@ -158,12 +179,45 @@ Floe moves enforcement server-side against a real credit line:
158179- ** Cross-vendor** — one budget over LLM tokens * and* paid (x402) tool calls.
159180- ** Team budgets + analytics** — shared ceilings, per-agent isolation, spend history.
160181
161- Set ` FLOE_API_KEY ` and floe-guard exposes a hook to delegate enforcement to
162- hosted Floe (see [ ` src/floe_guard/hosted.py ` ] ( src/floe_guard/hosted.py ) — wiring
163- the live endpoint is in progress; the local guard is fully functional today).
182+ Set ` FLOE_API_KEY ` (your agent key, ` floe_<hex> ` ) and floe-guard can read your
183+ agent's ** server-side remaining budget** from the live Floe endpoint:
184+
185+ ``` python
186+ from floe_guard import hosted_enforcement_available, hosted_remaining_usd
187+
188+ if hosted_enforcement_available(): # True when FLOE_API_KEY is set
189+ remaining = hosted_remaining_usd() # USD left, read from Floe's server
190+ ```
191+
192+ ` hosted_remaining_usd() ` GETs ` /v1/agents/credit-remaining ` and returns the USD
193+ remaining — the minimum of your auto-borrow headroom and your session spend
194+ remaining. It raises ` HostedEnforcementError ` on a bad/missing key (401), a
195+ closed or suspended agent (403), an unprovisioned agent (404), or a network
196+ failure.
197+
198+ Env vars:
164199
165- → ** [ dev-dashboard.floelabs.xyz] ( https://dev-dashboard.floelabs.xyz ) ** ·
166- ** [ floelabs.xyz] ( https://floelabs.xyz ) **
200+ - ` FLOE_API_KEY ` — your agent key. Required for the read.
201+ - ` FLOE_API_BASE_URL ` — override the API host (defaults to
202+ ` https://credit-api.floelabs.xyz ` ).
203+
204+ Honest scope: this call only ** reads** the remaining budget. The un-bypassable,
205+ cross-vendor * enforcement* is the hosted Floe product running server-side — not
206+ this client. Use the number to inform a local ceiling; the server stays the
207+ source of truth.
208+
209+ → ** [ dev-dashboard.floelabs.xyz] ( https://dev-dashboard.floelabs.xyz/?utm_source=floe-guard&utm_medium=readme&utm_campaign=oss ) ** ·
210+ ** [ floelabs.xyz] ( https://floelabs.xyz/?utm_source=floe-guard&utm_medium=readme&utm_campaign=oss ) **
211+
212+ ## Built with floe-guard
213+
214+ Using floe-guard in your project? Add the badge so others find it:
215+
216+ [ ![ guarded by floe-guard] ( https://img.shields.io/badge/guarded%20by-floe--guard-2f81f7.svg )] ( https://github.com/Floe-Labs/floe-guard )
217+
218+ ``` markdown
219+ [ ![ guarded by floe-guard] ( https://img.shields.io/badge/guarded%20by-floe--guard-2f81f7.svg )] ( https://github.com/Floe-Labs/floe-guard )
220+ ```
167221
168222## Development
169223
0 commit comments