trackmcp
Back to directory
rtahabas

gatewards-sdk

View on GitHub

Pipeline gateway SDK for multi-agent systems — budget enforcement, loop detection, dedup cache (drop-in proxy)

0 stars TypeScriptOthers Updated Jun 27, 2026
agent-governanceai-agentsautogencrewailangchainmulti-agenttypescriptusdcx402budget-enforcementcachellm-gatewayproxypipeline-gatewaymcpmodel-context-protocol

Documentation

Gatewards SDK

Your agents can't burn more than you let them.

Official SDKs for Gatewards — a pipeline gateway for multi-agent systems. Caps fleet spend, detects runaway loops, dedups duplicate API calls across agents — drop-in proxy, no decorator, no code change inside your agents. Optional on-chain settlement via the open x402 protocol when you need it.

Why

AI agents fail while continuing to work. A retry loop, a verification chain with no terminator, a tool call that never resolves — these don't crash. They silently compound. One widely-discussed 2025 incident saw four agents stuck in an infinite conversation for eleven days before anyone noticed the invoice.

Dashboards and alerts tell you after it happens. Gatewards stops it mid-chain.

  • Drop-in proxy. Point your agent at the gateway URL with a bearer token. No decorator, no callback handler, no framework adapter. Works with any framework that makes HTTP calls.
  • Fleet budget enforcement. Cap what an entire pipeline of agents can spend. Breach once — every agent in the pipeline pauses.
  • Multi-agent dedup cache. Five agents in the same pipeline call the same upstream API. The first request hits upstream; the next four are served from cache. Dedup happens across the pipeline, not per-agent.
  • Runaway loop detection. Two agents in an infinite back-and-forth get flagged before the bill compounds.
  • Optional: x402 settlement. When you do want on-chain payment for paid APIs — USDC on Base, sub-cent fees, sub-2-second settlement — the SDK implements the open x402 protocol end-to-end.

See it

You set a daily cap on a fleet. The fleet starts working. The cap hits.

The gateway atomically blocks the rest and lands a signed webhook at your

URL — all in one continuous run.

Each of the three guards is shown in isolation below.

Fleet budget cap

10 agents fire concurrent calls against a fleet capped at $0.50/day. Each

call costs $0.10. Total intent: $1.00 — twice the cap. The gateway lets

through exactly $0.50 worth and blocks the rest, atomically:

code
$ npx tsx scripts/demo-budget-enforcement.ts

  Gatewards — Fleet Kill Switch Demo

  You set the cap. Your fleet tries to overrun it.
  Watch the gateway hold the line.

  Your cap:    $0.50/day
  Fleet size:  10 agents
  They want:   $1.00  (200% of your cap)

  Fleet fires 10 concurrent calls...

  Agent-001  $0.10  ✅ allowed   (your cap: $0.50, used: $0.10)
  Agent-002  $0.10  ✅ allowed   (your cap: $0.50, used: $0.20)
  Agent-003  $0.10  ✅ allowed   (your cap: $0.50, used: $0.30)
  Agent-004  $0.10  ✅ allowed   (your cap: $0.50, used: $0.40)
  Agent-005  $0.10  ✅ allowed   (your cap: $0.50, used: $0.50)
  Agent-006  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)
  Agent-007  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)
  Agent-008  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)
  Agent-009  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)
  Agent-010  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)

  Result
    allowed:     5/10 calls
    blocked:     5/10 calls
    you spent:   $0.50  (your cap was $0.50 — not a cent over)
    overage:     $0.00  ← would have been $0.50 without the gateway

  You set the cap. The gateway enforced it atomically,
  even with 10 agents firing at the same instant.
  No 3am surprise.

The script runs the production guard code against an in-memory store —

zero network, zero on-chain, ~1 second on a laptop. Source lives in the

gateway repo.

Multi-agent loop

A verification crew of 6 agents takes turns calling the same upstream

resource — the shape of a CrewAI/AutoGen conversation that won't terminate,

or two verifiers handing the same task back and forth. With a dedup

threshold of 3 in a 60-second window, the gateway lets the first 3 settle

and rejects the rest:

The dedup guard runs in the same DB transaction as the settlement insert,

so concurrent retries can't slip past the threshold. Source: same gateway

repo, `scripts/demo-loop-detection.ts`.

Operator notification (webhook)

When a guard fires, the gateway delivers a signed webhook to your URL

of choice — what wakes you up at 3am instead of the API invoice. The

demo intercepts the outbound POST so you can see the exact payload

your receiver would log.

HMAC-SHA256 over the JSON body with a per-pipeline secret (AES-GCM at

rest), idempotency via `X-Gatewards-Event-Id`, and SSRF guard on the target

URL. Source: `scripts/demo-webhook-on-breach.ts`.

Flow

code
Agent request ──► Gateway: budget + cache check ──► Upstream (or cache hit)
                       │                                    │
                       └── loop / overspend ────────────────┴──► pipeline pauses, webhook fires

Packages

PackageDescriptionnpm
`@gatewards/agent-sdk`Pipeline gateway client for AI agents — drop-in proxy + budget + dedup cache![npm](https://www.npmjs.com/package/@gatewards/agent-sdk)
`@gatewards/merchant-sdk`Optional Express middleware — charge for your API on-chain via x402![npm](https://www.npmjs.com/package/@gatewards/merchant-sdk)
`@gatewards/contracts`Solidity contracts — used only when x402 settlement mode is on![npm](https://www.npmjs.com/package/@gatewards/contracts)

Quick Start

Agent (consumer) — proxy mode, default

bash
npm install @gatewards/agent-sdk
ts
import { createPaymentClient } from "@gatewards/agent-sdk";

const { client } = createPaymentClient({
  gatewayUrl: process.env.GATEWARDS_GATEWAY!,
  apiKey: process.env.GATEWARDS_API_KEY!,
  network: "base",
  proxy: true, // drop-in proxy mode — no on-chain settlement required
  budgetPolicy: {
    maxSpendPerCall: "1.00", // hard cap per request (USD-equivalent)
    dailyLimit: "10.00", // hard cap per day
  },
});

// Pipeline budget, loop detection, and dedup cache happen at the gateway.
// If the cap is breached, the call throws — it doesn't leak spend.
const res = await client.get("https://your-upstream.com/api/data?q=...");

LangChain integration: `import { createGatewardsTools } from "@gatewards/agent-sdk/langchain"`.

Merchant (API provider) — optional, only when you sell paid APIs via x402

bash
npm install @gatewards/merchant-sdk
ts
import express from "express";
import { createPaymentRequiredMiddleware } from "@gatewards/merchant-sdk";

const app = express();

app.get(
  "/premium/search",
  createPaymentRequiredMiddleware({
    price: "0.08", // USDC per call
    wallet: "0xYourPayoutWallet",
    network: "base",
    gatewayPublicKey: process.env.JWT_SECRET!,
  }),
  (req, res) =>
    res.json({
      results: [
        /* … */
      ],
    }),
);

Pricing

code
Free        $0      1 pipeline, 3 agents, 10K events / month
Solo        $29     3 pipelines, 10 agents, 100K events
Team        $99     10 pipelines, 50 agents, 1M events
Org         $299    unlimited pipelines, 200 agents, 5M events
Enterprise  Custom  unlimited + on-chain settlement (x402) + compliance + SLA

Self-host the gateway free under MIT — every tier feature, no caps, you run the binary. Pricing applies to the hosted gateway service.

Development

bash
git clone https://github.com/rtahabas/gatewards-sdk.git
cd gatewards-sdk
npm install --include=dev
npm run build
npm test

Requires Node 20+.

  • Gateway + demos: https://github.com/rtahabas/gatewards
  • Dashboard: https://gatewards.vercel.app

License

Apache-2.0 — see LICENSE and NOTICE.

Frequently asked questions

What is gatewards-sdk?

gatewards-sdk is Pipeline gateway SDK for multi-agent systems — budget enforcement, loop detection, dedup cache (drop-in proxy)

How do I install gatewards-sdk?

Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

Is gatewards-sdk open source?

Yes — it is hosted on GitHub at https://github.com/rtahabas/gatewards-sdk.

Related MCP tools

Run your own MCP server? See who uses it and what to fix.

Measure it with TrackMCP