Weather forecast (US)
GET /api/weather-forecast · Cached 10mMulti-period weather forecast for a US location from api.weather.gov (NWS, public domain). Send GET /api/weather-forecast with the required fields lat and lon and pay $0.001 per call over x402 or MPP (there is no free tier). It returns a JSON object with location, lat, lon and periods.
Give latitude and longitude; returns the place plus upcoming forecast periods (temp, wind, conditions). US coverage only. ?lat=40.71&lon=-74.01
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
lat | number | yes | latitude (US) Also accepted as latitude. |
lon | number | yes | longitude (US) Also accepted as lng, long, longitude. |
Example request
curl -i "https://agent402.tools/api/weather-forecast?lat=40.71&lon=-74.01"
Without payment this returns HTTP 402 Payment Required with the exact price for weather-forecast; any x402 v2 or MPP client pays it and retries.
Example response
{
"location": {
"city": "New York",
"state": "NY"
},
"lat": 40.71,
"lon": -74.01,
"periods": [
{
"name": "Today",
"temperature": 72,
"unit": "F",
"wind": "10 mph",
"shortForecast": "Sunny"
}
]
}
| Field | Type | Always present | In the example |
|---|---|---|---|
location | object | yes | 2 fields: city, state |
lat | number | yes | 40.71 |
lon | number | yes | -74.01 |
periods | array of objects | yes | 1 item in the example |
From an MCP client
catalog.call {
"slug": "weather-forecast",
"params": {
"lat": 40.71,
"lon": -74.01
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for weather-forecast; the stdio package pays it from a wallet or from AGENT402_CREDITS_KEY. Local install: npx -y agent402-mcp.
Errors and behavior
latandlonare required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement is cancelled when the tool fails. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool reaches the network or stored state, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Cached: an identical request within 10m is answered from cache with
X-Cache: hit. - A
POSTwith a JSON body to /api/weather-forecast is served as this GET, with the body as the input. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.(false); // keep your own spending ceiling in code
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/weather-forecast?lat=40.71&lon=-74.01");
Part of these workflows
Weather forecast (US) is one step in these 2 skill packs, each sold as a single call:
- Location intel - Point at an address (or even a rough place name) and assemble the situational brief: precise coordinates, the canonical postal address, what's within walking distance, the live weather forecast, active NWS hazard alerts, and recent seismic activity. The deterministic 'what should I know about this place right now?' workup.
- Multi-stop trip planner - Plan a multi-stop journey deterministically: geocode each stop, sum the pairwise haversine distances, estimate arrival times by adding driving hours per leg, count business days from today to each arrival, and pull the weather forecast at every US stop. Six tools - three pure-CPU (math + time), three egress (geocoding + weather) - covering the deterministic skeleton of every road-trip / sales-tour / delivery-route planning problem.
Related tools
US weather alerts
GET /api/weather-alertsActive National Weather Service alerts for a US state as clean JSON: event, severity, headline, affected areas, onset/ex…
Daily forecast (global)
GET /api/weather-daily7-day daily weather forecast for any location: high/low temp, precipitation sum and probability, max wind, UV index, sun…
Hourly forecast (global)
GET /api/weather-hourly48-hour hourly weather forecast for any location: temperature, precipitation probability and amount, wind, cloud cover, …
Forecast backtest (MAPE + RMSE)
POST /api/forecast-evalBacktest a forecasting method on the input series by holding out the last `testSize` observations, forecasting them, and…
Forecast (Holt linear trend)
POST /api/forecast-holtHolt's linear trend method - level + trend (no seasonality). Two smoothing parameters: alpha (level) and beta (trend). F…
Forecast (Holt-Winters seasonal)
POST /api/forecast-holt-wintersHolt-Winters triple exponential smoothing - level + trend + seasonal component. Use for series with a repeating cycle (w…