x402 Weather Insurance Agent

x402 · ai-agents · stablecoins

A Flare Confidential Compute extension that settles parametric rainfall insurance with OpenWeatherMap data fetched inside a TEE.

The HTTP layer speaks 402. Tokens move on Coston2 with feeToken.transferFrom in the same transaction as getWeather. The enclave will not call OpenWeatherMap until it sees FeeCollected, so the API key never sits in the Next.js process.

Stack

  • Solidity
  • Next.js
  • x402 / HTTP 402
  • Flare Confidential Compute
  • OpenAI tools
  • MCP

Architecture

x402 gateway

Next.js routes at /x402/weather/fetch and /x402/weather/settle. If allowance is short they return HTTP 402. The client approves, retries, and the gateway calls onlyGateway contract functions.

On-chain fee

approve sets allowance. _collectFee pulls an ERC-20 (test USDT0 or FXRP) via transferFrom. That is the payment. HTTP 402 is only the invoice.

TEE

Flare Confidential Compute holds the OpenWeatherMap key, verifies FeeCollected, fetches weather over HTTPS, and returns a signed report. Settlement uses the same loop.

Agent and MCP

An in-app OpenAI assistant and an MCP server at /api/mcp expose the same paid tools: pool stats, weather fetch, buy policy, settle.

Links