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

  1. Sign up at inferencebrake.dev
  2. Get your API key from the Dashboard

Python SDK

Install the inferencebrake package and start monitoring your agents.

Install
pip install inferencebrake

Basic Usage

Python
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}")
        break

Batch Check

Python
statuses = guard.check_batch(
    reasoning_list=["step1", "step2", "step3"],
    session_id="agent-session-1"
)

Session History

Python
history = guard.get_session_history(
    session_id="agent-session-1",
    limit=50
)

Configuration

Python
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.

Install
npm install inferencebrake

Basic Usage

JavaScript
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

JavaScript
const guard = new InferenceBrake({
    apiKey: 'ib_your_key',
    timeout: 10000,
    maxRetries: 3,
    retryDelay: 1000,
    retryBackoff: 2,
    circuitBreakerThreshold: 5,
    circuitBreakerTimeout: 30000,
});

Monitor Helper

JavaScript
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

Shell
curl https://ocnjiyiqeifllbyqohks.supabase.co/functions/v1/health

Check Reasoning

Shell
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

JSON
{
  "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

FieldTypeDescription
actionstring"KILL" if loop detected, "PROCEED" otherwise
loop_detectedbooleanWhether a reasoning loop was detected
similarityfloatMax cosine similarity against recent steps (0.0 - 1.0)
action_repeat_countintNumber of consecutive identical actions
ngram_overlapfloatN-gram overlap ratio with recent steps
confidencefloatWeighted voting confidence (0.0 - 1.0)
statusstring"safe", "warning", or "danger"
messagestringHuman-readable status message
test_modebooleanWhether request used test mode API key

Detector Fields

DetectorMethodBest For
semanticEmbedding cosine similarityParaphrased repetition
token_repeatExact repeated token spansVerbatim loops (Antidoom / OpenRouter failure mode)
actionTool call patternsRepeated tool invocations
ngramText overlapPhrase-level repetition
editdistNormalized LevenshteinNear-identical mirror loops
compressionNormalized Compression DistanceStructural / 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 limit
  • X-RateLimit-Remaining - Checks remaining this month
  • X-RateLimit-Period - month
  • X-RateLimit-Reset - Unix timestamp when the quota resets

Error Codes

StatusErrorCause
401Invalid API KeyMissing or invalid Authorization header
402Subscription past duePayment required
429Rate limit exceededDaily check limit reached
500Internal errorServer-side failure, retry with backoff

Framework Integrations

LangChain (Python)

Python
from inferencebrake import InferenceBrakeCallbackHandler

handler = InferenceBrakeCallbackHandler(api_key="ib_your_key")

agent = AgentExecutor(agent=agent, tools=tools, callbacks=[handler])

CrewAI (Python)

Python
from inferencebrake import create_crewai_callback

callback = create_crewai_callback(api_key="ib_your_key")

agent.callbacks = [callback]

Python Decorator

Python
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

JavaScript
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.

Python
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 loops

Order of precedence on detection:

  1. escalate(status, attempt) while under max_escalations
  2. on_loop(status)
  3. raise LoopDetectedError when auto_stop is 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
curl -H "Authorization: Bearer ib_your_key" \
  "https://ocnjiyiqeifllbyqohks.supabase.co/functions/v1/analytics-summary?days=30"
Response
{
  "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.