{
  "markdown": "# Gatewards SDK\n\n**Your agents can't burn more than you let them.**\n\nOfficial SDKs for [Gatewards](https://github.com/rtahabas/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.\n\n## Why\n\nAI 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.\n\nDashboards and alerts tell you after it happens. Gatewards stops it mid-chain.\n\n- **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.\n- **Fleet budget enforcement.** Cap what an entire pipeline of agents can spend. Breach once — every agent in the pipeline pauses.\n- **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.\n- **Runaway loop detection.** Two agents in an infinite back-and-forth get flagged before the bill compounds.\n- **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.\n\n## See it\n\nYou set a daily cap on a fleet. The fleet starts working. The cap hits.\nThe gateway atomically blocks the rest and lands a signed webhook at your\nURL — all in one continuous run.\n\nEach of the three guards is shown in isolation below.\n\n### Fleet budget cap\n\n10 agents fire concurrent calls against a fleet capped at $0.50/day. Each\ncall costs $0.10. Total intent: $1.00 — twice the cap. The gateway lets\nthrough exactly $0.50 worth and blocks the rest, atomically:\n\n<p align=\"center\">\n  <img src=\"./assets/kill-switch-demo.gif\" alt=\"Gatewards fleet kill switch demo — 10 agents try to spend $1, gateway lets $0.50 through and blocks the rest\" width=\"720\"/>\n</p>\n\n```\n$ npx tsx scripts/demo-budget-enforcement.ts\n\n  Gatewards — Fleet Kill Switch Demo\n\n  You set the cap. Your fleet tries to overrun it.\n  Watch the gateway hold the line.\n\n  Your cap:    $0.50/day\n  Fleet size:  10 agents\n  They want:   $1.00  (200% of your cap)\n\n  Fleet fires 10 concurrent calls...\n\n  Agent-001  $0.10  ✅ allowed   (your cap: $0.50, used: $0.10)\n  Agent-002  $0.10  ✅ allowed   (your cap: $0.50, used: $0.20)\n  Agent-003  $0.10  ✅ allowed   (your cap: $0.50, used: $0.30)\n  Agent-004  $0.10  ✅ allowed   (your cap: $0.50, used: $0.40)\n  Agent-005  $0.10  ✅ allowed   (your cap: $0.50, used: $0.50)\n  Agent-006  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)\n  Agent-007  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)\n  Agent-008  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)\n  Agent-009  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)\n  Agent-010  $0.10  ❌ BLOCKED   (your cap hit — pipeline paused)\n\n  Result\n    allowed:     5/10 calls\n    blocked:     5/10 calls\n    you spent:   $0.50  (your cap was $0.50 — not a cent over)\n    overage:     $0.00  ← would have been $0.50 without the gateway\n\n  You set the cap. The gateway enforced it atomically,\n  even with 10 agents firing at the same instant.\n  No 3am surprise.\n```\n\nThe script runs the production guard code against an in-memory store —\nzero network, zero on-chain, ~1 second on a laptop. Source lives in the\n[gateway repo](https://github.com/rtahabas/gatewards).\n\n### Multi-agent loop\n\nA verification crew of 6 agents takes turns calling the same upstream\nresource — the shape of a CrewAI/AutoGen conversation that won't terminate,\nor two verifiers handing the same task back and forth. With a dedup\nthreshold of 3 in a 60-second window, the gateway lets the first 3 settle\nand rejects the rest:\n\n<p align=\"center\">\n  <img src=\"./assets/loop-detection-demo.gif\" alt=\"Gatewards multi-agent loop detection demo — 6 agents call the same resource, gateway lets 3 through and blocks the rest\" width=\"720\"/>\n</p>\n\nThe dedup guard runs in the same DB transaction as the settlement insert,\nso concurrent retries can't slip past the threshold. Source: same gateway\nrepo, [`scripts/demo-loop-detection.ts`](https://github.com/rtahabas/gatewards/blob/main/scripts/demo-loop-detection.ts).\n\n### Operator notification (webhook)\n\nWhen a guard fires, the gateway delivers a signed webhook to your URL\nof choice — what wakes you up at 3am instead of the API invoice. The\ndemo intercepts the outbound POST so you can see the exact payload\nyour receiver would log.\n\nHMAC-SHA256 over the JSON body with a per-pipeline secret (AES-GCM at\nrest), idempotency via `X-Gatewards-Event-Id`, and SSRF guard on the target\nURL. Source: [`scripts/demo-webhook-on-breach.ts`](https://github.com/rtahabas/gatewards/blob/main/scripts/demo-webhook-on-breach.ts).\n\n## Flow\n\n```\nAgent request ──► Gateway: budget + cache check ──► Upstream (or cache hit)\n                       │                                    │\n                       └── loop / overspend ────────────────┴──► pipeline pauses, webhook fires\n```\n\n## Packages\n\n| Package                                             | Description                                                                  | npm                                                                                                                 |\n| --------------------------------------------------- | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------- |\n| [`@gatewards/agent-sdk`](./packages/agent-sdk)       | Pipeline gateway client for AI agents — drop-in proxy + budget + dedup cache | [![npm](https://img.shields.io/npm/v/@gatewards/agent-sdk)](https://www.npmjs.com/package/@gatewards/agent-sdk)       |\n| [`@gatewards/merchant-sdk`](./packages/merchant-sdk) | Optional Express middleware — charge for your API on-chain via x402          | [![npm](https://img.shields.io/npm/v/@gatewards/merchant-sdk)](https://www.npmjs.com/package/@gatewards/merchant-sdk) |\n| [`@gatewards/contracts`](./packages/contracts)       | Solidity contracts — used only when x402 settlement mode is on               | [![npm](https://img.shields.io/npm/v/@gatewards/contracts)](https://www.npmjs.com/package/@gatewards/contracts)       |\n\n## Quick Start\n\n### Agent (consumer) — proxy mode, default\n\n```bash\nnpm install @gatewards/agent-sdk\n```\n\n```ts\nimport { createPaymentClient } from \"@gatewards/agent-sdk\";\n\nconst { client } = createPaymentClient({\n  gatewayUrl: process.env.GATEWARDS_GATEWAY!,\n  apiKey: process.env.GATEWARDS_API_KEY!,\n  network: \"base\",\n  proxy: true, // drop-in proxy mode — no on-chain settlement required\n  budgetPolicy: {\n    maxSpendPerCall: \"1.00\", // hard cap per request (USD-equivalent)\n    dailyLimit: \"10.00\", // hard cap per day\n  },\n});\n\n// Pipeline budget, loop detection, and dedup cache happen at the gateway.\n// If the cap is breached, the call throws — it doesn't leak spend.\nconst res = await client.get(\"https://your-upstream.com/api/data?q=...\");\n```\n\nLangChain integration: `import { createGatewardsTools } from \"@gatewards/agent-sdk/langchain\"`.\n\n### Merchant (API provider) — optional, only when you sell paid APIs via x402\n\n```bash\nnpm install @gatewards/merchant-sdk\n```\n\n```ts\nimport express from \"express\";\nimport { createPaymentRequiredMiddleware } from \"@gatewards/merchant-sdk\";\n\nconst app = express();\n\napp.get(\n  \"/premium/search\",\n  createPaymentRequiredMiddleware({\n    price: \"0.08\", // USDC per call\n    wallet: \"0xYourPayoutWallet\",\n    network: \"base\",\n    gatewayPublicKey: process.env.JWT_SECRET!,\n  }),\n  (req, res) =>\n    res.json({\n      results: [\n        /* … */\n      ],\n    }),\n);\n```\n\n## Pricing\n\n```\nFree        $0      1 pipeline, 3 agents, 10K events / month\nSolo        $29     3 pipelines, 10 agents, 100K events\nTeam        $99     10 pipelines, 50 agents, 1M events\nOrg         $299    unlimited pipelines, 200 agents, 5M events\nEnterprise  Custom  unlimited + on-chain settlement (x402) + compliance + SLA\n```\n\nSelf-host the gateway free under MIT — every tier feature, no caps, you run the binary. Pricing applies to the hosted gateway service.\n\n## Development\n\n```bash\ngit clone https://github.com/rtahabas/gatewards-sdk.git\ncd gatewards-sdk\nnpm install --include=dev\nnpm run build\nnpm test\n```\n\nRequires Node 20+.\n\n## Links\n\n- **Gateway + demos:** https://github.com/rtahabas/gatewards\n- **Dashboard:** https://gatewards.vercel.app\n\n## License\n\nApache-2.0 — see [LICENSE](./LICENSE) and [NOTICE](./NOTICE).\n",
  "bytes": 8935,
  "sha": "7fe1c295c2cbeb932dbe59126d8d30cb7fd1f7b452f659bdc6fbfdb6aa34d323",
  "repo_slug": "rtahabas/gatewards-sdk",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_rtahabas_gatewards_00d076d3/readme"
}