Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SITCH — Backend

Pay-per-query startup intelligence agent. PitchBook-level research for the people priced out: founders, students, small funds. No subscription. No API key. Pay per query in USDC on Base via x402.

Hackathon: Microsoft × Coinbase × Tavily Agentic Commerce Hackathon, 2026. Scope: backend only. Frontend lives elsewhere.


What this backend does

  1. Accept a natural-language query ("top Series A edtech startups 2025").
  2. Return HTTP 402 Payment Required with x402 payment terms.
  3. Verify USDC payment on Base via x402 facilitator.
  4. Run Tavily multi-source search (Crunchbase, TechCrunch, SEC EDGAR, LinkedIn, open web).
  5. Synthesize results into a structured one-page brief via Azure OpenAI (OpenAI direct as fallback).
  6. Return JSON brief.

Total latency target: <10s. Cost per query: ~$0.005 USDC.


Architecture

┌──────────────┐       POST /query (no payment)        ┌────────────────┐
│ Caller       │ ─────────────────────────────────────▶│  /query route  │
│ (agent or    │                                       │   (Express)    │
│  human via   │ ◀────  402 Payment Required ──────────│                │
│  frontend)   │       (x-payment-required hdr)        └────────────────┘
└──────┬───────┘                                                │
       │                                                        │
       │  POST /query  +  X-PAYMENT header                      │
       │  (signed USDC transfer on Base)                        │
       ▼                                                        ▼
┌────────────────────────┐         ┌──────────────────────────────────┐
│  x402-express          │ ───────▶│  Orchestrator                    │
│  middleware:           │         │  - validate query                │
│  - parse X-PAYMENT     │         │  - dispatch Tavily search        │
│  - verify via          │         │  - dispatch OpenAI synthesis     │
│    facilitator         │         │  - return structured brief       │
│  - settle on Base      │         └────────┬─────────────────────────┘
└────────────────────────┘                  │
                                            ├──▶ Tavily Search SDK
                                            ├──▶ Azure OpenAI (gpt-4o-mini; OpenAI fallback)
                                            └──▶ Postgres (query log, briefs cache)

Caller wallet:  Coinbase CDP Agentic Wallet (autonomously signs the X-PAYMENT)
Server wallet:  Coinbase CDP wallet (receives settled USDC on Base)

Tech stack

Layer Choice
Runtime Node 20 + TypeScript
HTTP Express (x402 middleware compat)
Search Tavily SDK (@tavily/core)
LLM Azure OpenAI (gpt-4o-mini, primary) — OpenAI direct as fallback via env
Wallet (caller side, demo) Coinbase CDP Agentic Wallets (launch ref)
Wallet (server side) Coinbase CDP wallet — receives settled USDC
Payments x402-express middleware, USDC on Base Sepolia (demo) / Base mainnet (prod)
DB Postgres (Neon) — query log, brief cache
Host Azure Container Apps (Microsoft sponsor credits)
Local chain Anvil (Foundry) optional, for offline x402 dev

Repo layout

sitch-backend/
├── README.md
├── package.json
├── tsconfig.json
├── .env.example                # template only — never commit .env
├── .gitignore
├── src/
│   ├── index.ts                # Express app entry
│   ├── routes/
│   │   └── query.ts            # POST /query — main paid endpoint
│   ├── x402/
│   │   └── middleware.ts       # x402-express config + pricing
│   ├── orchestrator/
│   │   └── orchestrator.ts     # query → search → synthesis pipeline
│   ├── tavily/
│   │   └── search.ts           # Tavily multi-source search
│   ├── synthesis/
│   │   └── brief.ts            # OpenAI tool-use → structured brief
│   ├── wallet/
│   │   └── cdp.ts              # Coinbase CDP server wallet
│   ├── agents/
│   │   └── (reserved for future multi-agent expansion)
│   └── db/
│       └── client.ts           # Postgres client + migrations
├── tests/
└── scripts/
    └── seed.ts                 # seed demo data

API

POST /query

First call (no payment):

POST /query
Content-Type: application/json

{ "query": "top Series A AI startups in healthcare 2025" }

Response:

HTTP/1.1 402 Payment Required
X-Payment-Required: { chain: "base-sepolia", asset: "USDC", amount: "5000", recipient: "0x..." }

Second call (with payment header):

POST /query
X-Payment: <base64-signed-usdc-transfer>
Content-Type: application/json

{ "query": "top Series A AI startups in healthcare 2025" }

Response (200):

{
  "query": "top Series A AI startups in healthcare 2025",
  "brief": {
    "summary": "...",
    "key_companies": [
      { "name": "...", "stage": "Series A", "amount_raised_usd": 25000000, "lead_investors": [...], "source_urls": [...] }
    ],
    "market_trends": [...],
    "content_angles": [...]
  },
  "sources": [...],
  "payment": { "tx_hash": "0x...", "amount_usdc": "0.005", "settled_at": "..." },
  "latency_ms": 7421
}

GET /healthz

Liveness probe. No payment required.

GET /pricing

Returns current per-query pricing in USDC. No payment required.


Branching

Solo build. Branches kept for organized commits + clean PR history (judges look at repo activity).

Branch Purpose
main Demo-ready. Scaffold + merged features.
feature/x402-middleware x402-express setup + pricing config
feature/tavily-search Tavily search wrapper + source filtering
feature/agentkit-wallet Coinbase Agentic Wallet (awal) + x402 signing
feature/synthesis-agent Azure OpenAI synthesis → structured brief (OpenAI fallback)
feature/orchestrator Pipeline glue: search → synth → return

PR rule: feature → main, squash merge. No direct commits to main after scaffold.

Postgres/DB deferred to v0.2. v0 uses in-memory query log only. Judges don't need persistence for a 60-sec demo.


Environment

See .env.example. Required vars:

  • AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEY, AZURE_OPENAI_DEPLOYMENT, AZURE_OPENAI_API_VERSION (synthesis; primary)
  • OPENAI_API_KEY (fallback; only used if Azure vars unset)
  • TAVILY_API_KEY (search)
  • CDP_API_KEY_NAME, CDP_API_KEY_PRIVATE_KEY (Coinbase Developer Platform — NOT the coinbase.com exchange key)
  • X402_FACILITATOR_URL, X402_RECEIVING_ADDRESS, X402_NETWORK, X402_PRICE_USDC
  • BASE_RPC_URL
  • PORT (default 8787)

Never commit .env. It is in .gitignore. Per project security rules, no secrets in repo.


Local dev

npm install
cp .env.example .env  # fill in your keys locally
npm run dev           # tsx watch on :8787

Build plan (hackathon)

Hour Branch Deliverable
0–1 main Scaffold + README + env template (this commit)
1–3 feature/x402-middleware x402-express wired, returns 402 with correct pricing
3–5 feature/tavily-search Tavily multi-source search, returns normalized hits
5–7 feature/synthesis-agent OpenAI tool-use → structured brief JSON
7–8 feature/agentkit-wallet CDP wallet receiving + (optional) caller-side demo signer
8–10 feature/orchestrator End-to-end pipeline + Postgres logging
10–11 main Merge all PRs, deploy to Azure Container Apps
11–12 Demo script: query → 402 → pay → brief in <10s

Out of scope (v0)

  • Frontend (separate repo).
  • Brief caching dedup beyond exact-query match.
  • Multi-language (English only).
  • Streaming responses (return full JSON, no SSE for v0).
  • Non-USDC payment paths.
  • Crunchbase / PitchBook direct API integration (Tavily covers public web).

Why this fits every sponsor

  • Tavily: real-time multi-source web search is the data layer.
  • Coinbase: x402 protocol + CDP Agentic Wallets handle autonomous payment.
  • Microsoft: Azure Container Apps hosts the agent runtime; Azure OpenAI powers synthesis.
  • x402: every paid call uses HTTP 402 + USDC settlement on Base.

About

A pay-per-query startup-intelligence agent, paid in USDC on Base.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages