Integration Documentation
Connect InferenceBrake to your AI agents in minutes. The Free plan includes 5,000 checks/month; paid plans scale to 100k and 500k per month.
Runnable examples: InferenceBrake/inferencebrake-examples.
Before You Start
- Sign up at inferencebrake.dev
- Get your API key from the Dashboard
Python SDK
Install the inferencebrake package and start monitoring your agents.
pip install inferencebrakeBasic Usage
from inferencebrake import InferenceBrake
guard = InferenceBrake(api_key="ib_your_key")
for step in agent.run():
status = guard.check(
reasoning=step.reasoning,
session_id="agent-session-1",
action=step.tool, # optional, enables action repetition
model="gpt-4o-mini", # optional, recorded for attribution
prompt="weather task", # optional, recorded for attribution
)
if status.should_stop:
print(f"Loop detected! {status.detector_triggered}")
breakBatch Check
statuses = guard.check_batch(
reasoning_list=["step1", "step2", "step3"],
session_id="agent-session-1"
)Session History
history = guard.get_session_history(
session_id="agent-session-1",
limit=50
)Configuration
guard = InferenceBrake(
api_key="ib_your_key",
timeout=10,
auto_stop=False
)JavaScript / Node.js SDK
Built-in resilience: retry logic, circuit breaker, and offline queue.
npm install inferencebrakeBasic Usage
const { InferenceBrake } = require('inferencebrake');
const guard = new InferenceBrake({ apiKey: 'ib_your_key' });
const status = await guard.check(
'reasoning text',
'session-1'
);
if (status.shouldStop) {
console.log('Loop detected!', status.message);
}Resilience Configuration
const guard = new InferenceBrake({
apiKey: 'ib_your_key',
timeout: 10000,
maxRetries: 3,
retryDelay: 1000,
retryBackoff: 2,
circuitBreakerThreshold: 5,
circuitBreakerTimeout: 30000,
});Monitor Helper
const { inferencebrakeMonitor } = require('inferencebrake');
const monitor = inferencebrakeMonitor({ apiKey: 'ib_your_key' });
const status = await monitor.check(reasoning);
monitor.reset('new-session-id');REST API
Use directly from any language or framework via HTTP.
Health Check
curl https://ocnjiyiqeifllbyqohks.supabase.co/functions/v1/healthCheck Reasoning
curl -X POST https://ocnjiyiqeifllbyqohks.supabase.co/functions/v1/check \
-H "Authorization: Bearer ib_your_key" \
-H "Content-Type: application/json" \
-d '{
"session_id": "agent-123",
"reasoning": "I should check the weather in NYC"
}'Response
{
"action": "PROCEED",
"loop_detected": false,
"similarity": 0.42,
"confidence": 0.18,
"detectors": {
"semantic": false,
"token_repeat": false,
"action": false,
"ngram": false,
"editdist": false,
"compression": false
},
"estimated_cost_saved": 0,
"status": "safe",
"message": "Reasoning sound",
"usage": {
"today": 42,
"month": 42,
"limit": 5000,
"remaining": 4958
}
}API Reference
CheckStatus Fields
| Field | Type | Description |
|---|---|---|
action | string | "KILL" if loop detected, "PROCEED" otherwise |
loop_detected | boolean | Whether a reasoning loop was detected |
similarity | float | Max cosine similarity against recent steps (0.0 - 1.0) |
action_repeat_count | int | Number of consecutive identical actions |
ngram_overlap | float | N-gram overlap ratio with recent steps |
confidence | float | Weighted voting confidence (0.0 - 1.0) |
status | string | "safe", "warning", or "danger" |
message | string | Human-readable status message |
test_mode | boolean | Whether request used test mode API key |
Detector Fields
| Detector | Method | Best For |
|---|---|---|
semantic | Embedding cosine similarity | Paraphrased repetition |
token_repeat | Exact repeated token spans | Verbatim loops (Antidoom / OpenRouter failure mode) |
action | Tool call patterns | Repeated tool invocations |
ngram | Text overlap | Phrase-level repetition |
editdist | Normalized Levenshtein | Near-identical mirror loops |
compression | Normalized Compression Distance | Structural / information theory |
Rate Limits
Free plan: 5,000 checks per month per account. Paid plans raise the limit. Counters reset on the 1st.
Rate limit headers are returned with every response:
X-RateLimit-Limit- Monthly limitX-RateLimit-Remaining- Checks remaining this monthX-RateLimit-Period-monthX-RateLimit-Reset- Unix timestamp when the quota resets
Error Codes
| Status | Error | Cause |
|---|---|---|
| 401 | Invalid API Key | Missing or invalid Authorization header |
| 402 | Subscription past due | Payment required |
| 429 | Rate limit exceeded | Daily check limit reached |
| 500 | Internal error | Server-side failure, retry with backoff |
Framework Integrations
LangChain (Python)
from inferencebrake import InferenceBrakeCallbackHandler
handler = InferenceBrakeCallbackHandler(api_key="ib_your_key")
agent = AgentExecutor(agent=agent, tools=tools, callbacks=[handler])CrewAI (Python)
from inferencebrake import create_crewai_callback
callback = create_crewai_callback(api_key="ib_your_key")
agent.callbacks = [callback]Python Decorator
from inferencebrake import guard_agent_loop
@guard_agent_loop(
api_key="ib_your_key",
session_id="agent-1",
action=lambda r: r["tool"],
)
def call_model(prompt):
return client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}],
)JavaScript Monitor
const { InferenceBrakeCallbackHandler } = require('inferencebrake');
const handler = new InferenceBrakeCallbackHandler({
apiKey: 'ib_your_key',
sessionId: 'my-agent'
});
const result = await chain.invoke(input, { callbacks: [handler] });Escalation
Instead of stopping on the first loop, give the agent a chance to recover on a stronger model, then stop if it still loops. The SDK does not pick models; you provide the hook.
from inferencebrake import guard_agent_loop
@guard_agent_loop(
api_key="ib_your_key",
session_id="agent-1",
escalate=lambda status, attempt: switch_model("claude-opus"),
max_escalations=2,
)
def call_model(prompt):
... # on a loop the agent retries on the stronger model,
# then stops if it still loopsOrder of precedence on detection:
escalate(status, attempt)while undermax_escalationson_loop(status)- raise
LoopDetectedErrorwhenauto_stopis set
Use steering_message(status) for a ready-to-inject nudge, and LoopPolicy to apply the same behavior outside a decorator.
Analytics
Attribute loops to the model, tool, and prompt that produced them, not just a total count.
curl -H "Authorization: Bearer ib_your_key" \
"https://ocnjiyiqeifllbyqohks.supabase.co/functions/v1/analytics-summary?days=30"{
"total_checks": 78,
"loops_blocked": 9,
"estimated_usd_saved": 0.0146,
"by_model": [
{ "model": "gpt-4o-mini", "checks": 30, "loops": 4, "saved": 0.006 }
],
"by_action": [
{ "action": "get_balance", "checks": 12, "loops": 3, "saved": 0.004 }
],
"by_detector": [
{ "detector": "semantic", "loops": 6 },
{ "detector": "token_repeat", "loops": 3 }
],
"recent_loops": [
{
"session_id": "agent-1",
"model": "gpt-4o-mini",
"action": "get_balance",
"confidence": 0.85,
"saved": 0.0019,
"created_at": "2026-09-20T03:24:44Z"
}
]
}Attribution comes from the model, action, and prompt you pass to check(). Totals reflect retained metrics, so the window is bounded by your plan's retention.