- ✓Actively maintained (<30d)
- ✓Documented (README)
- !No standard license detected
- !No description
- !Install pipes a remote script into a shell (curl | sh)
git clone https://github.com/AgentMarginRouter/AgentMarginRouter && cp AgentMarginRouter/*.md ~/.claude/agents/Subagents overview
# Agent Margin Router
[](https://agent-margin-router-production.up.railway.app/health)
[](https://agentmarginrouter.com)
[](https://www.x402.org)
[](#)
[](#9-tests--projektstruktur)
> **EN — TL;DR:** Pay-per-request data broker for AI agents. One API, 7 upstream providers, automatic routing by quality × cost × latency, paid with **x402 micropayments (USDC or USDT on Base)** — no account, no API key, no subscription. 3 free requests per wallet.
>
> - **Live API:** `https://agent-margin-router-production.up.railway.app`
> - **Docs & examples:** https://agentmarginrouter.com
> - **Endpoints:** `POST /extract-clean` (URL → clean JSON, $0.02) · `POST /market-spread` (net spread between two venues after fees, $0.05) · `GET /health` (free)
>
> ```bash
> # Try it free (3 requests per wallet):
> curl -X POST https://agent-margin-router-production.up.railway.app/market-spread \
> -H "Content-Type: application/json" -H "X-WALLET: 0xYourWallet" \
> -d '{"asset":"ethereum","buy_venue":"binance","sell_venue":"coinbase"}'
> ```
>
> Full German documentation below · Vollständige deutsche Dokumentation folgt.
> Einheitliche, per **x402** bezahlte Routing-Schicht für AI-Agenten.
> Mehrere Daten-Provider → automatische Auswahl (Qualität, Preis, Latenz, Ausfallrisiko) → normalisiertes JSON → Bezahlung pro Request in **USDC oder USDT auf Base**.
```text
Agent ──POST /extract-clean──▶ Router ──▶ Provider-Scoring ──▶ bester Provider
▲ │ (Fallback, Circuit-Breaker, Mindestmarge)
│ 402 Payment Required │
│ (USDC + USDT Optionen) ▼
└──X-PAYMENT (signiert)──▶ Facilitator /verify ──▶ 200 OK + Daten ──▶ /settle on-chain
```
## Inhalt
1. [Was ist der Agent Margin Router](#1-was-ist-der-agent-margin-router)
2. [Schnellstart (lokal ohne Docker)](#2-schnellstart-lokal-ohne-docker)
3. [Deployment mit Docker-Compose auf Hetzner](#3-deployment-mit-docker-compose-auf-hetzner)
4. [Cloudflare Tunnel Setup](#4-cloudflare-tunnel-setup)
4b. [Deployment auf Railway](#4b-deployment-auf-railway)
5. [Umgebungsvariablen](#5-umgebungsvariablen)
6. [API-Endpunkte mit Beispielen](#6-api-endpunkte)
6b. [Enterprise: API-Keys, Rate-Limiting, Usage & Stats](#6b-enterprise-api-keys-rate-limiting-usage--stats)
7. [x402 Payment Flow](#7-x402-payment-flow)
8. [Provider hinzufügen](#8-provider-hinzufügen)
9. [Tests & Projektstruktur](#9-tests--projektstruktur)
---
## 1. Was ist der Agent Margin Router
Der Router ist ein **B2B-Daten-Broker für Maschinen**. Ein AI-Agent stellt eine standardisierte Anfrage, der Router
1. prüft den Cache (Redis),
2. bewertet alle passenden Provider mit `score = quality × success_probability / (price + latency_risk)`,
3. führt den Request nur aus, wenn die **Mindestmarge** (Default 20 %) erhalten bleibt,
4. fällt bei Fehlern automatisch auf den nächsten Provider zurück (**Circuit-Breaker**: 3 Fehler → 5 Minuten Pause),
5. normalisiert die Antwort und liefert sie mit Aktualitäts- und Konfidenzangabe aus,
6. protokolliert Kosten, Provider und Marge als strukturierte JSON-Logs.
Bezahlt wird **pro Request** über das x402-Protokoll (HTTP 402). Akzeptiert werden von Anfang an **USDC und USDT auf Base**. Neue Wallets erhalten 3 kostenlose Requests (Free Tier, in Redis getrackt).
**MVP-Endpunkte:**
| Endpunkt | Funktion | Preis (Default) |
|---|---|---|
| `POST /extract-clean` | URL → sauberes, schema-konformes JSON | 0,02 USD |
| `POST /market-spread` | Netto-Spread zwischen zwei Handelsplätzen nach Gebühren, Slippage & Transfer | 0,05 USD |
| `GET /health` | Status, Redis, Provider, Uptime, Fehlerrate, Cache-Hit-Rate | kostenlos |
> **Provider (echte APIs):**
>
> | Name | Capability | Anbieter | Kosten/Call (Default) | Qualität |
> |---|---|---|---|---|
> | `apify_web_scraper` | extract | Apify Actor `apify/web-scraper` (Headless-Browser, optional Proxy) | ~0,005 USD (wird aus `usageTotalUsd` nachjustiert) | 0.90 |
> | `httpx_direct` | extract | direkter HTTP-Abruf, kein JS | ~0,0002 USD | 0.60 |
> | `binance_public` | market_data | Binance Public API `/ticker/24hr` (Bid/Ask) via `data-api.binance.vision` – `api.binance.com` ist regional geo-blockiert | 0 USD, kein Key | 0.95 |
> | `coinbase_public` | market_data | Coinbase Public API `/prices/{pair}/spot` | 0 USD, kein Key | 0.90 |
> | `coingecko` | market_data | CoinGecko `/simple/price`, `/coins/{id}/tickers`, optional `/market_chart` | 0 USD (Demo-Key, Rate-Limit) | 0.88 |
> | `defillama` | market_data | DeFi Llama `coins.llama.fi/prices/current/coingecko:{id}` (Referenzpreis) + `api.llama.fi/tvl/{slug}` (DEX-Tiefe) | 0 USD, kein Key | 0.75 |
> | `coinmarketcap` | market_data | CMC `/cryptocurrency/quotes/latest` (Fallback, nur Referenzpreis) | ~0,0004 USD (Credits) | 0.70 |
>
> Ohne gesetzten API-Key wird ein Provider **nicht geroutet** (`is_configured == False`), taucht aber in `/health` mit `configured: false` auf.
> Der **Free-Tier** nutzt nur Provider mit `cost_per_request <= FREE_TIER_MAX_PROVIDER_COST_USD` (Default 0,001 USD) – also `httpx_direct` bzw. `binance_public`/`coinbase_public`/`coingecko`/`defillama`; `/market-spread` holt dabei jedes Leg vom **eigenen Exchange-Feed** (Binance Bid/Ask, Coinbase Spot), wenn Binance oder Coinbase Teil des Venue-Paars ist; teure Provider sind für kostenlose Requests gesperrt.
> `/extract-clean` prüft Ziel-URLs gegen private/interne Netze (SSRF-Guard: nur http/https, keine RFC-1918-, Loopback-, Link-Local- oder Metadata-Adressen, Prüfung pro Redirect-Hop); abgelehnte URLs liefern `422` und zählen nicht als Provider-Fehler.
>
> **Einschränkung `/market-spread`:** Das Ergebnis ist eine **Analyse**, keine ausführbare Quote. Preise sind Last-Trade-Werte der Venue-Ticker (CoinGecko) bzw. ein Referenzpreis (CMC); „Liquidität“ wird aus 24h-Volumen und einem statischen Depth-Anteil je Venue geschätzt, nicht aus dem Orderbuch. Das Feld `data_source`/`venue_data_source` (`ticker`, `mixed`, `reference`) und `note` im Response kennzeichnen die Datenbasis.
---
## 2. Schnellstart (lokal ohne Docker)
Voraussetzungen: Python ≥ 3.11, optional ein lokaler Redis (ohne Redis nutzt die App im Dev-Modus automatisch einen In-Memory-Fallback).
```bash
git clone <dein-repo> agent_margin_router
cd agent_margin_router
python -m venv .venv && source .venv/bin/activate
pip install -r requirements-dev.txt
cp .env.example .env
# Für lokale Tests ohne Wallet/Zahlung:
sed -i 's/^PAYMENT_ENABLED=.*/PAYMENT_ENABLED=false/' .env
sed -i 's#^REDIS_URL=.*#REDIS_URL=redis://localhost:6379/0#' .env
uvicorn app.main:app --reload --port 8000
```
Dann:
```bash
curl -s localhost:8000/health | jq .status
curl -s -X POST localhost:8000/extract-clean \
-H 'Content-Type: application/json' \
-d '{"url":"https://example.com/produkt/123"}' | jq
```
Interaktive API-Doku: <http://localhost:8000/docs>
Tests:
```bash
pytest -q
```
---
## 3. Deployment mit Docker-Compose auf Hetzner
Getestet für einen Hetzner Cloud Server (CX22 reicht für den Start, Ubuntu 24.04).
### 3.1 Server vorbereiten
```bash
ssh root@<SERVER-IP>
# System aktualisieren, Docker installieren
apt update && apt upgrade -y
curl -fsSL https://get.docker.com | sh
# Nicht-Root-User für den Betrieb
adduser --disabled-password --gecos "" deploy
usermod -aG docker deploy
# Firewall: nur SSH offen lassen (HTTP kommt über Cloudflare Tunnel, s. Abschnitt 4)
apt install -y ufw
ufw allow OpenSSH
ufw --force enable
```
### 3.2 Projekt deployen
```bash
su - deploy
git clone <dein-repo> agent_margin_router
cd agent_margin_router
cp .env.example .env
nano .env # RECEIVER_WALLET, ENVIRONMENT=production, REDIS_REQUIRED=true, Preise, Provider-Keys
```
Wichtige Produktionswerte in `.env`:
```dotenv
ENVIRONMENT=production
REDIS_URL=redis://redis:6379/0
REDIS_REQUIRED=true
PAYMENT_ENABLED=true
RECEIVER_WALLET=0xDeineEchteWallet
```
Starten:
```bash
docker compose up -d --build
docker compose ps
docker compose logs -f app
curl -s localhost:8000/health | jq
```
Der App-Port `8000` ist im Compose-File **nur auf 127.0.0.1** gebunden – von außen ist der Dienst ausschließlich über den Cloudflare Tunnel (oder einen eigenen Reverse Proxy) erreichbar.
### 3.3 Betrieb
```bash
docker compose pull && docker compose up -d --build # Update
docker compose logs --tail=200 app # JSON-Logs
docker compose exec redis redis-cli INFO memory # Redis prüfen
docker compose down # Stoppen (Redis-Daten bleiben im Volume)
```
Beide Services haben Healthchecks und `restart: unless-stopped`; nach einem Server-Reboot startet der Stack automatisch.
---
## 4. Cloudflare Tunnel Setup
Mit einem Cloudflare Tunnel braucht der Hetzner-Server **keinen offenen HTTP-Port**; TLS, DDoS-Schutz und WAF übernimmt Cloudflare.
1. Domain bei Cloudflare verwalten (Nameserver umstellen).
2. Cloudflare Dashboard → **Zero Trust** → **Networks** → **Tunnels** → **Create a tunnel** (Typ „Cloudflared“).
3. Namen vergeben (z. B. `agent-margin-router`) und den angezeigten **Token** kopieren.
4. Im Tunnel unter **Public Hostname** einen Eintrag anlegen:
- Subdomain: `api`, Domain: `deine-domain.tld`
- Service: `HTTP` → `app:8000` (Docker-Servicename, da cloudflared im selben Compose-Netz läuft)
5. Token in `.env` eintragen:
```dotenv
CLOUDFLARE_TUNNEL_TOKEN=eyJhIjoi...
```
6. Stack mit Tunnel-Profil starten:
```bash
docker compose --profile tunnel up -d
docker compose logs -f cloudflared # "Registered tunnel connection" = erfolgreich
curl -s https://api.deine-domain.tld/health | jq .status
```
Empfohlen zusätzlich im Cloudflare-Dashboard: **RaWhat people ask about AgentMarginRouter
What is AgentMarginRouter/AgentMarginRouter?
+
AgentMarginRouter/AgentMarginRouter is subagents for the Claude AI ecosystem with 0 GitHub stars.
How do I install AgentMarginRouter?
+
You can install AgentMarginRouter by cloning the repository (https://github.com/AgentMarginRouter/AgentMarginRouter) or following the README instructions on GitHub. ClaudeWave also provides quick install blocks on this page.
Is AgentMarginRouter/AgentMarginRouter safe to use?
+
Our security agent has analyzed AgentMarginRouter/AgentMarginRouter and assigned a Trust Score of 44/100 (tier: Caution). See the full breakdown of passed checks and flags on this page.
Who maintains AgentMarginRouter/AgentMarginRouter?
+
AgentMarginRouter/AgentMarginRouter is maintained by AgentMarginRouter. The last recorded GitHub activity is dated 2026-09-11, with 0 open issues.
Are there alternatives to AgentMarginRouter?
+
Yes. On ClaudeWave you can browse similar subagents at /categories/agents, sorted by popularity or recent activity.
Deploy AgentMarginRouter to your cloud
Ship this repo to production in minutes. Each platform spins up its own environment with editable env vars.
Maintain this repo? Add a badge to your README
Drop the badge into your GitHub README to show it's tracked on ClaudeWave. Each badge links back to this page and reflects the live Trust Score.
[](https://claudewave.com/repo/agentmarginrouter-agentmarginrouter)<a href="https://claudewave.com/repo/agentmarginrouter-agentmarginrouter"><img src="https://claudewave.com/api/badge/agentmarginrouter-agentmarginrouter" alt="Featured on ClaudeWave: AgentMarginRouter/AgentMarginRouter" width="320" height="64" /></a>More Subagents
The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.
The agent that grows with you
Java 面试 & 后端通用面试指南,覆盖计算机基础、数据库、分布式、高并发、系统设计与 AI 应用开发
Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
The agent engineering platform.
Makes your AI agent think like the laziest senior dev in the room. The best code is the code you never wrote.