# USGS NWIS Streamflow & Gage Height Monitor API by Site/State (`malonestar/usgs-nwis-streamflow-monitor`) Actor

USGS NWIS streamflow API: pull real-time river discharge (cfs) and gage height (ft) by site number or state. Flattens nested USGS WaterML-JSON into clean rows with change deltas and flood-stage threshold alerts. Keyless USGS Water Services data for irrigation, utilities, flood risk & hydrology.

- **URL**: https://apify.com/malonestar/usgs-nwis-streamflow-monitor.md
- **Developed by:** [Kyle Maloney](https://apify.com/malonestar) (community)
- **Categories:** Lead generation, Developer tools, MCP servers
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $6.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## USGS NWIS Streamflow & Gage Height Monitor

Real-time **streamflow (discharge, cfs)** and **gage height (ft)** from the U.S. Geological Survey National Water Information System (NWIS), delivered as clean, flat, one-row-per-site records. The actor does the hard part for you: it pulls the deeply nested WaterML-in-JSON response, flattens it, computes the **change vs the prior reading**, and flags any site **over a flood-stage / alert threshold** you set. Keyless, public-domain USGS data.

### Who it's for
- **Agriculture & irrigation districts** — watch intake streams and canals for low/high flow.
- **Water utilities & dam operators** — track river stage and discharge at supply and downstream points.
- **Flood / P&C insurers & risk teams** — threshold alerts on rising gages near insured exposure.
- **Environmental consultants & hydrologists** — normalized time-stamped readings ready for analysis.
- **Researchers & data engineers** — skip the WaterML parsing; get tidy rows and deltas.

### What it does
1. Accepts a list of **USGS site numbers** OR a **state code** (every gaging site in the state).
2. Pulls the latest instantaneous (`iv`) or daily (`dv`) value for one or more parameters (00060 discharge, 00065 gage height).
3. Optionally widens the window (`period`, e.g. `PT2H`) so it can compute a **change delta + direction** (rising/falling/steady) vs the prior reading.
4. Applies an optional **global threshold** or **per-site thresholds** and sets `above_threshold` + `amount_over_threshold`.
5. `onlyAlerts` mode returns only sites at or above their threshold.

### Example input
```json
{
  "sites": ["01646500", "01638500"],
  "parameterCd": "00060",
  "service": "iv",
  "period": "PT2H",
  "thresholdValue": "25000",
  "onlyAlerts": false
}
````

State-wide flood watch:

```json
{ "stateCd": "VA", "parameterCd": "00065", "thresholdValue": "10", "onlyAlerts": true }
```

### Output fields

| Field | Description |
|-------|-------------|
| `site_no` / `site_name` | USGS station number and name |
| `agency` | Reporting agency (USGS) |
| `state` / `state_fips` / `county_fips` | USPS state, FIPS state, FIPS county |
| `huc` | Hydrologic Unit Code |
| `lat` / `lon` | Site coordinates (EPSG:4326) |
| `parameter_code` / `parameter_name` / `unit` | e.g. 00060 / Discharge / ft3/s |
| `value` / `datetime` | Latest reading and its timestamp |
| `qualifier` / `provisional` | Qualifier code(s); provisional flag (P) |
| `prior_value` / `prior_datetime` | Previous reading (when a `period` is set) |
| `change` / `change_direction` | Delta vs prior; rising / falling / steady |
| `threshold_value` / `above_threshold` / `amount_over_threshold` | Threshold applied, over/under flag, and margin |

### Use as an MCP tool

This actor is callable by AI agents (Claude, Cursor, etc.) via [mcp.apify.com](https://mcp.apify.com). Its input and output schemas carry field-level descriptions, so an agent can chain it: e.g. "get the latest Potomac River streamflow and tell me if it is above 25,000 cfs" maps directly to `sites` + `thresholdValue`.

### FAQ

**Where does the data come from?** USGS Water Services (`waterservices.usgs.gov/nwis/iv` and `/dv`), public-domain, no API key.

**How do I find a site number?** Use the USGS site map or NWIS. Common example: `01646500` = Potomac River near Washington, DC (Little Falls).

**How do I get streamflow vs gage height?** `parameterCd` = `00060` for discharge (cfs), `00065` for gage height (ft). Comma-separate for both.

**Why is my value marked provisional?** Recent USGS readings carry a `P` qualifier until reviewed; `provisional` is `true` for those.

**Can I get a change/delta?** Yes — set a `period` (e.g. `PT2H` or `P1D`) so more than one reading is returned; the actor uses the last two to compute `change` and `change_direction`.

**Can I monitor a whole state for flooding?** Yes — set `stateCd`, a `thresholdValue`, and `onlyAlerts: true`.

### Notes & caveats

- A statewide (`stateCd`) query can return hundreds of sites; sites with no current reading are omitted.
- Real-time values are **provisional** and subject to USGS revision — verify before operational use.
- `change` is only populated when the response contains at least two readings (set a `period`).

# Actor input Schema

## `sites` (type: `array`):

List of USGS NWIS site (station) numbers to pull, e.g. \["01646500"] (Potomac River at Little Falls). Provide this OR a State code. Site numbers are the 8-15 digit USGS station IDs.

## `stateCd` (type: `string`):

USPS two-letter state code (e.g. "VA") to pull every gaging site in that state for the chosen parameter. Used only when no site numbers are supplied. A statewide pull can return hundreds of sites.

## `parameterCd` (type: `string`):

USGS parameter code. 00060 = discharge / streamflow (cubic feet per second); 00065 = gage height (feet). Comma-separate to request several, e.g. "00060,00065".

## `service` (type: `string`):

Which USGS Water Services endpoint to use: 'iv' for near real-time instantaneous values, or 'dv' for daily values.

## `period` (type: `string`):

Optional ISO-8601 duration to widen the window so a prior reading is available for the change delta, e.g. "PT2H" (2 hours) or "P1D" (1 day). Leave blank to fetch only the latest reading per site.

## `thresholdValue` (type: `string`):

Optional flood-stage / alert threshold applied to every site (in the parameter's unit, e.g. cfs for 00060 or feet for 00065). Sets above\_threshold=true and amount\_over\_threshold when the latest value meets or exceeds it.

## `siteThresholds` (type: `object`):

Optional per-site thresholds as a JSON object mapping site number to threshold value, e.g. {"01646500": 30000}. Overrides the global threshold for those sites.

## `onlyAlerts` (type: `boolean`):

When true, only sites whose latest reading is at or above their threshold are returned (useful for flood-alert monitoring). Requires a global or per-site threshold.

## Actor input object example

```json
{
  "sites": [
    "01646500"
  ],
  "stateCd": "",
  "parameterCd": "00060",
  "service": "iv",
  "period": "",
  "thresholdValue": "",
  "siteThresholds": {},
  "onlyAlerts": false
}
```

# Actor output Schema

## `results` (type: `string`):

The default dataset.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "sites": [
        "01646500"
    ],
    "parameterCd": "00060"
};

// Run the Actor and wait for it to finish
const run = await client.actor("malonestar/usgs-nwis-streamflow-monitor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "sites": ["01646500"],
    "parameterCd": "00060",
}

# Run the Actor and wait for it to finish
run = client.actor("malonestar/usgs-nwis-streamflow-monitor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "sites": [
    "01646500"
  ],
  "parameterCd": "00060"
}' |
apify call malonestar/usgs-nwis-streamflow-monitor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=malonestar/usgs-nwis-streamflow-monitor",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "USGS NWIS Streamflow & Gage Height Monitor API by Site/State",
        "description": "USGS NWIS streamflow API: pull real-time river discharge (cfs) and gage height (ft) by site number or state. Flattens nested USGS WaterML-JSON into clean rows with change deltas and flood-stage threshold alerts. Keyless USGS Water Services data for irrigation, utilities, flood risk & hydrology.",
        "version": "1.0",
        "x-build-id": "Ogkeu8O34dDX2nA8U"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/malonestar~usgs-nwis-streamflow-monitor/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-malonestar-usgs-nwis-streamflow-monitor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/malonestar~usgs-nwis-streamflow-monitor/runs": {
            "post": {
                "operationId": "runs-sync-malonestar-usgs-nwis-streamflow-monitor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/malonestar~usgs-nwis-streamflow-monitor/run-sync": {
            "post": {
                "operationId": "run-sync-malonestar-usgs-nwis-streamflow-monitor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "properties": {
                    "sites": {
                        "title": "USGS site numbers",
                        "type": "array",
                        "description": "List of USGS NWIS site (station) numbers to pull, e.g. [\"01646500\"] (Potomac River at Little Falls). Provide this OR a State code. Site numbers are the 8-15 digit USGS station IDs.",
                        "default": [],
                        "items": {
                            "type": "string"
                        }
                    },
                    "stateCd": {
                        "title": "State code (alternative to sites)",
                        "type": "string",
                        "description": "USPS two-letter state code (e.g. \"VA\") to pull every gaging site in that state for the chosen parameter. Used only when no site numbers are supplied. A statewide pull can return hundreds of sites.",
                        "default": ""
                    },
                    "parameterCd": {
                        "title": "Parameter code",
                        "type": "string",
                        "description": "USGS parameter code. 00060 = discharge / streamflow (cubic feet per second); 00065 = gage height (feet). Comma-separate to request several, e.g. \"00060,00065\".",
                        "default": "00060"
                    },
                    "service": {
                        "title": "Service (instantaneous or daily)",
                        "enum": [
                            "iv",
                            "dv"
                        ],
                        "type": "string",
                        "description": "Which USGS Water Services endpoint to use: 'iv' for near real-time instantaneous values, or 'dv' for daily values.",
                        "default": "iv"
                    },
                    "period": {
                        "title": "Look-back period (ISO 8601 duration)",
                        "type": "string",
                        "description": "Optional ISO-8601 duration to widen the window so a prior reading is available for the change delta, e.g. \"PT2H\" (2 hours) or \"P1D\" (1 day). Leave blank to fetch only the latest reading per site.",
                        "default": ""
                    },
                    "thresholdValue": {
                        "title": "Global threshold value",
                        "type": "string",
                        "description": "Optional flood-stage / alert threshold applied to every site (in the parameter's unit, e.g. cfs for 00060 or feet for 00065). Sets above_threshold=true and amount_over_threshold when the latest value meets or exceeds it.",
                        "default": ""
                    },
                    "siteThresholds": {
                        "title": "Per-site thresholds",
                        "type": "object",
                        "description": "Optional per-site thresholds as a JSON object mapping site number to threshold value, e.g. {\"01646500\": 30000}. Overrides the global threshold for those sites.",
                        "default": {}
                    },
                    "onlyAlerts": {
                        "title": "Only return sites over threshold",
                        "type": "boolean",
                        "description": "When true, only sites whose latest reading is at or above their threshold are returned (useful for flood-alert monitoring). Requires a global or per-site threshold.",
                        "default": false
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
