# USGS Gauge Threshold Crossing Feed (`natstandridge/usgs-gauge-threshold-crossing-feed`) Actor

Turn fresh USGS Water Data API v1 gauge readings into bounded, machine-readable site checks and threshold transitions from a prior Actor dataset. Explicit units, local gage datum, provisional status and freshness; no flood or safety verdict.

- **URL**: https://apify.com/natstandridge/usgs-gauge-threshold-crossing-feed.md
- **Developed by:** [Nathaniel Standridge](https://apify.com/natstandridge) (community)
- **Categories:** Business, Developer tools
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 delivered fresh usgs gauge checks

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/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## USGS Gauge Threshold Crossing Feed

Turn a short USGS streamgage watchlist into fresh, machine-readable site checks. Each delivered row includes the current value, exact unit, observation time, data approval status, threshold state, and any **change from a prior row produced by this Actor**. A recreation or water-data team can schedule the Actor, paste the previous dataset JSON into the next run, and send the resulting rows into a dashboard or workflow.

### Quick start

1. Run [the one-site example](examples/input.json). It checks public USGS site `01646500` for instantaneous streamflow parameter `00060` against a threshold of 10,000 `ft^3/s`.
2. Read the default dataset for fresh checks and `OUTPUT` for requested, delivered, stale, missing, and source-error counts. The first run is a baseline: `crossing` is `none`.
3. On the next run, paste the previous default dataset **JSON array** into `previousResultsJson` and keep the same `monitorKey`. A comparable newer reading crossing the threshold produces `entered_above` or `left_above` (or the corresponding `below` states). [The synthetic comparison example](examples/output.json) shows one entered-above row.
4. Use `siteId`, `parameterCode`, and `monitorKey` as an integration key. Use `observationId` to deduplicate delivery within one Actor run.

The Actor accepts at most 50 distinct site/parameter pairs and makes only fixed-host HTTPS requests to the official [USGS Water Data API v1 latest-continuous endpoint](https://api.waterdata.usgs.gov/ogcapi/v1/collections/latest-continuous?f=html). It never fetches a user-supplied URL, follows a source redirect, or forwards a credential. An explicit empty `sites` list makes no source request. `maxRunSeconds` bounds source work and delivery; `maxAgeMinutes` rejects old readings as uncharged diagnostics; `lookbackHours` limits how old a previous check may be for a crossing comparison. The Actor fetches the **latest** current reading, not all observations within the lookback. Intermediate crossings between checks can be missed.

### Input contract

Each site needs an exact numeric USGS site ID, parameter code `00060` for streamflow or `00065` for gage height, `direction` (`above` or `below`), and a numeric `threshold` in the declared `unit`. The API's streamflow unit is `ft^3/s`; input also accepts `ft3/s` and normalizes it. Gage height uses `ft`. Comparisons are strict: exactly equal to the threshold is `at`, neither above nor below. To track both directions, make two separately labeled watchlists or use the row's `thresholdState`.

For `00065`, `datumBasis` is `site_local_gage_datum_no_geodetic_conversion`. Gage height is relative to each site's local gage datum; this Actor does not turn it into a national vertical elevation or compare heights across sites. For streamflow, datum is not applicable. See [USGS on gage height](https://waterdata.usgs.gov/blog/gage_height/) and the [latest-continuous data dictionary](https://api.waterdata.usgs.gov/ogcapi/v1/collections/latest-continuous/schema?f=html).

`previousResultsJson` is optional user-supplied comparison evidence: up to 50 rows and 512 KiB, from this Actor's default dataset. There is no automatic account-wide history. A prior row with a different threshold, direction, unit, source time series, or statistic is marked incomparable. A prior reading outside `lookbackHours` or newer than the current reading cannot trigger a crossing. `changedSinceLastRun` means the selected threshold state entered or left the active side; it does not mean every change in numeric value.

### Output and pricing

One **fresh, validated site check row** is the proposed $0.001 billing unit, including checks with no crossing. The Actor uses the default-dataset native event only once per delivered row. Missing, stale, invalid, ambiguous-series and undelivered checks produce no paid row; `OUTPUT.diagnostics` reports why. A two-site plan with a one-event cap writes no partial paid queue. Frozen `RESULT_PLAN` rows and a pending-delivery checkpoint prevent a restart from replaying an uncertain charged append; an unresolved write stops for reconciliation.

Rows expose `observedAt`, `lastModifiedAt`, `ageMinutes`, `approvalStatus`, and `qualifiers`. USGS says provisional values may be revised, and telemetry can be delayed. A threshold crossing here is a numeric dashboard signal, **not** a flood-stage, emergency, navigation, property-damage, or personal-safety assessment. This service is a machine-readable comparison convenience; free [USGS WaterAlert](https://accounts.waterdata.usgs.gov/wateralert/service/) already supports threshold email/SMS. Paid customer demand and net profit remain unmeasured.

The previous Actor dataset is comparison input. For operational monitoring, retain the prior dataset alongside your schedule and inspect `OUTPUT` on every run. If coverage is incomplete, retain the last trustworthy row and investigate the diagnostic rather than treating an absent row as recovery.

### Source and migration

USGS [announced Water Data API v1](https://waterdata.usgs.gov/blog/api-v1-release/) as the successor to WaterServices. This Actor uses v1 directly. It currently supports two explicit parameter/unit pairs and a single unambiguous latest series per site/parameter. Source schema changes, site series changes, stale or duplicate series, and nonnumeric observations surface as diagnostics. No proxy, paid upstream data, or USGS API key is required for this bounded watchlist.

# Actor input Schema

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

At most 50 site/parameter pairs. Use an exact USGS numeric site ID, parameter 00060 streamflow (ft^3/s) or 00065 gage height (ft), direction above/below, and a threshold in that unit. No URLs are accepted. An explicit empty list makes no request.

## `monitorKey` (type: `string`):

Stable label for this watchlist; use the same value with previousResultsJson. Letters, digits, underscores and hyphens only.

## `previousResultsJson` (type: `string`):

Paste this Actor’s earlier default dataset JSON array to compare fresh observations with the last check. No account-wide history is read automatically. Up to 50 rows and 512 KiB.

## `maxAgeMinutes` (type: `integer`):

Readings older than this are listed as uncharged diagnostics, not crossing rows.

## `lookbackHours` (type: `integer`):

A previous Actor result older than this cannot trigger a crossing. Only the latest current USGS reading is fetched.

## `maxRunSeconds` (type: `integer`):

Bounded source requests and delivery; unfinished sites become uncharged diagnostics.

## Actor input object example

```json
{
  "sites": [
    {
      "id": "01646500",
      "parameterCode": "00060",
      "unit": "ft^3/s",
      "direction": "above",
      "threshold": 10000
    }
  ],
  "monitorKey": "default",
  "maxAgeMinutes": 120,
  "lookbackHours": 24,
  "maxRunSeconds": 180
}
```

# Actor output Schema

## `siteChecks` (type: `string`):

No description

## `summary` (type: `string`):

No description

# 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 = {};

// Run the Actor and wait for it to finish
const run = await client.actor("natstandridge/usgs-gauge-threshold-crossing-feed").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 = {}

# Run the Actor and wait for it to finish
run = client.actor("natstandridge/usgs-gauge-threshold-crossing-feed").call(run_input=run_input)

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

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

```

## CLI example

```bash
echo '{}' |
apify call natstandridge/usgs-gauge-threshold-crossing-feed --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,natstandridge/usgs-gauge-threshold-crossing-feed"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Z1gi2IcjEQjwykK02/builds/pEtj2TWfXtvYGzYIs/openapi.json
