Hyper Local Aqi Actor avatar
Hyper Local Aqi Actor

Pricing

Pay per usage

Go to Apify Store
Hyper Local Aqi Actor

Hyper Local Aqi Actor

Aggregates hyper-local air quality data from OpenAQ for AI agents. Provides AQI calculations with confidence scoring and outlier removal.

Pricing

Pay per usage

Rating

0.0

(0)

Developer

Pranav Bagal

Pranav Bagal

Maintained by Community

Actor stats

2

Bookmarked

1

Total users

0

Monthly active users

10 days ago

Last modified

Categories

Share

๐ŸŒ Global Hyper-Local AQI Actor

Real-time, hyper-accurate air quality intelligence for AI agents and applications

Apify Actor Node.js Version LICENSE

Get scientifically-validated Air Quality Index data from anywhere on Earth. This actor aggregates readings from multiple ground-level PM2.5 sensors, applies advanced statistical cleaning (IQR outlier removal), and delivers reliable AQI calculations with confidence scoringโ€”purpose-built for AI agents, health apps, and intelligent automation systems.

๐ŸŽฏ Built for the Apify $1M Challenge โ€” solving real-world air quality monitoring challenges at scale.


๐Ÿ”ฅ Why This Actor Exists

The Problem

Air quality affects 91% of the world's population living in areas exceeding WHO guidelines. However:

  • โŒ Single-sensor readings are unreliable (sensor malfunctions, local interference)
  • โŒ City-wide averages miss hyperlocal variations (pollution can vary 10x within kilometers)
  • โŒ No standardized confidence metrics for AI decision-making
  • โŒ Existing APIs lack real-time aggregation and statistical validation

The Solution

This actor provides statistically-validated, hyperlocal AQI by:

โœ… Aggregating multiple sensors within your specified radius
โœ… Cleaning outliers using IQR (Interquartile Range) statistical method
โœ… Calculating confidence scores (0-100%) based on data quality
โœ… Delivering actionable insights optimized for AI agent consumption

Perfect for: AI chatbots answering health queries, smart home automation, fitness apps, location-based services, environmental monitoring, and public health systems.


โœจ Key Features

๐ŸŽฏ Hyper-Local Precision

Unlike city-wide averages, get AQI for specific neighborhoods, parks, or addresses by aggregating sensors within 1-25km radius.

๐Ÿ“Š Statistical Rigor

  • Removes sensor malfunctions and outliers using proven IQR method
  • Calculates mean, median, and standard deviation
  • Filters stale data (only readings <48 hours old)

๐Ÿค– AI-Agent Ready

Structured JSON output designed for LLM function calling and programmatic decision-making with built-in confidence scores.

๐ŸŒ Global Coverage

Works anywhere with OpenAQ sensor network coverage (200+ countries, 10,000+ locations).

โšก Fast & Reliable

  • Concurrent sensor querying (10 parallel requests)
  • Automatic retries on failures
  • Typical execution: 5-30 seconds

๐Ÿ“‹ What You Get

{
"result": {
"aqi": 42, // EPA-standard Air Quality Index (0-500)
"category": "Good", // Good, Moderate, Unhealthy, etc.
"pm25_concentration": 10.5, // PM2.5 in ยตg/mยณ
"confidence_score": 87 // 0-100% reliability metric
},
"health_context": {
"advice": "Air quality is satisfactory.",
"is_safe_for_jogging": true // Boolean for quick AI decisions
},
"metadata": {
"sensors_found": 45, // Total sensors discovered
"sensors_used": 38, // Valid readings after cleaning
"outliers_removed": 7 // Statistical outliers filtered
}
}

Full output schema available in .actor/output_schema.json


๐Ÿš€ Quick Start

1๏ธโƒฃ Get Your Free OpenAQ API Key

Visit OpenAQ Registration and create a free account to get your API key.

2๏ธโƒฃ Run the Actor

Example: Check air quality in London

{
"locationName": "London",
"radiusKm": 10,
"maxSensors": 50,
"openaqApiKey": "your_api_key_here"
}

Example: Use precise coordinates (Tokyo)

{
"latitude": 35.6762,
"longitude": 139.6503,
"radiusKm": 15,
"maxSensors": 50,
"openaqApiKey": "your_api_key_here"
}

3๏ธโƒฃ Get Results in Seconds

AQI calculation with confidence score, health advice, and metadataโ€”ready for your application or AI agent.


๐Ÿ’ก Real-World Use Cases

๐Ÿค– AI Chatbots & Virtual Assistants

User: "Is it safe to run outside in Delhi right now?"
Agent: [Queries actor]
โ†’ "Delhi AQI is 156 (Unhealthy). Running outdoors
not recommended. Confidence: 92%"

๐Ÿƒ Fitness & Health Apps

  • Real-time workout safety recommendations
  • Location-based exercise route planning
  • Personalized outdoor activity alerts
  • Asthma/allergy trigger warnings

๐Ÿ  Smart Home Automation

  • Auto-control air purifiers based on outdoor AQI
  • Intelligent window opening/closing systems
  • HVAC optimization based on external air quality
  • Home ventilation scheduling

๐Ÿ“ฑ Location Services & Travel

  • Map overlays showing neighborhood-level AQI
  • Destination air quality assessments for travelers
  • Real estate insights (property + air quality data)
  • Event planning (outdoor venues, timing)

๐Ÿ”ฌ Research & Analytics

  • Urban planning and environmental studies
  • Public health research and policy-making
  • Climate change impact tracking
  • Hyperlocal pollution pattern analysis

๐Ÿ“ฅ Input Configuration

ParameterTypeRequiredDefaultDescription
locationNameStringNo*โ€”City or place name (e.g., "Paris", "Mumbai")
latitudeNumberNo*โ€”Latitude coordinate (e.g., 40.7128)
longitudeNumberNo*โ€”Longitude coordinate (e.g., -74.0060)
radiusKmIntegerNo10Search radius in kilometers (1-25)
maxSensorsIntegerNo50Max sensors to process (1-500)
openaqApiKeyStringYesโ€”Your OpenAQ API key (get one free)

*Either locationName OR both latitude+longitude must be provided.


๐Ÿ“ค Output Explained

AQI Categories (EPA Standard)

AQICategoryHealth ImpactUse Case
0-50๐ŸŸข GoodAir quality satisfactorySafe for all outdoor activities
51-100๐ŸŸก ModerateAcceptable for most peopleUnusually sensitive people should limit prolonged outdoor exertion
101-150๐ŸŸ  Unhealthy for Sensitive GroupsSensitive groups may experience health effectsChildren, elderly, people with respiratory conditions should reduce outdoor activities
151-200๐Ÿ”ด UnhealthyEveryone may experience health effectsEveryone should reduce prolonged outdoor exertion
201-300๐ŸŸฃ Very UnhealthyHealth alert: serious effects for everyoneEveryone should avoid outdoor activities
301-500๐ŸŸค HazardousEmergency health conditionsEveryone should remain indoors

Confidence Score Breakdown

The actor calculates confidence based on three factors:

Quantity (40%) โ€” Number of sensors with valid readings

  • More sensors = higher confidence
  • Minimum 4 sensors recommended

Consensus (40%) โ€” Agreement between sensors (low standard deviation)

  • Tight clustering = higher confidence
  • High variation suggests localized pollution sources

Quality (20%) โ€” Data retention after outlier removal

  • Higher retention rate = better quality
  • Low retention suggests sensor issues or extreme variability

๐Ÿ”ฌ How It Works

Architecture

Input Location โ†’ Geocoding โ†’ Sensor Discovery โ†’ Data Collection โ†’ Statistical Cleaning โ†’ AQI Calculation โ†’ Output

Step-by-Step Process

1. Location Resolution

  • City name โ†’ OpenStreetMap Nominatim geocoding
  • Or use provided latitude/longitude directly

2. Sensor Discovery

  • Query OpenAQ API for all PM2.5 sensors within radius
  • Filter for sensors with readings <48 hours old
  • Limit to maxSensors for performance optimization

3. Concurrent Data Collection

  • Fetch latest readings from each sensor (10 parallel requests)
  • Built-in retry logic for reliability
  • 5-second timeout per sensor

4. Statistical Data Cleaning

Raw values โ†’ Filter invalid โ†’ Calculate IQR โ†’ Remove outliers โ†’ Statistics
  • Remove null, negative, or >2000 ยตg/mยณ values
  • Apply Interquartile Range (IQR) method for outlier detection
  • Calculate mean, median, standard deviation

5. AQI Calculation

  • Apply EPA AQI breakpoints to cleaned PM2.5 mean
  • Map to category (Good โ†’ Hazardous)
  • Generate health advice

6. Confidence Scoring

confidence = quantity_score(40%) + consensus_score(40%) + quality_score(20%)

๐ŸŽ“ Technical Details

Built With

  • Apify SDK 3.2+ โ€” Serverless actor framework
  • Crawlee 3.15+ โ€” Concurrent web scraping with retries
  • TypeScript โ€” Type-safe development
  • OpenAQ API v3 โ€” Global air quality data network
  • OpenStreetMap Nominatim โ€” Geocoding service

Data Sources

  • PM2.5 Sensors: Ground-level particulate matter monitors
  • OpenAQ Network: 10,000+ locations across 200+ countries
  • Community-powered: Government agencies, research institutions, citizen scientists

Performance Metrics

  • Concurrency: 10 simultaneous requests
  • Retry Logic: 2 automatic retries on failures

๐Ÿ’ฐ Pricing & Costs

Cost Optimization

  • Pre-Filtering: We check sensor "Last Updated" timestamps before fetching detailed data, saving API calls.
  • Concurrency Control: Requests are batched to prevent memory spikes.
  • Configurable Limits: Use maxSensors to hard-cap execution time.

External API Costs

  • OpenAQ API: Free tier available (check current limits)
  • Nominatim Geocoding: Free (rate-limited to 1 req/sec)

Cost Optimization Tips:

  • Use coordinates instead of city names (saves geocoding call)
  • Reduce maxSensors for faster/cheaper execution
  • Smaller radius when high sensor density exists

๐Ÿ“Š Example Scenarios

Scenario 1: AI Health Assistant

Question: "Can my child with asthma play outside?"

Actor Input:

{
"locationName": "San Francisco",
"radiusKm": 5,
"maxSensors": 30,
"openaqApiKey": "..."
}

Response: AQI 68 (Moderate, 88% confidence) AI Output: "Air quality is acceptable, but sensitive children should limit prolonged outdoor play. Consider indoor activities instead."


Scenario 2: Smart Home Automation

Trigger: Every 30 minutes

Actor Input:

{
"latitude": 51.5074,
"longitude": -0.1278,
"radiusKm": 3,
"maxSensors": 20,
"openaqApiKey": "..."
}

Automation Logic:

if (aqi > 100) {
closeWindows();
turnOnAirPurifier();
sendNotification("Poor air quality detected");
}

Scenario 3: Fitness App Route Planning

Use Case: Recommend safest jogging routes

Actor Input: Check multiple neighborhoods

[
{"locationName": "Central Park", ...},
{"locationName": "Brooklyn Bridge Park", ...},
{"locationName": "Prospect Park", ...}
]

Output: Rank locations by AQI + confidence score


๐Ÿ› ๏ธ Development & Testing

Local Setup

# Clone repository
git clone https://github.com/cryptomafiaPB/hyper-local-aqi-actor.git
cd hyper-local-aqi-actor
# Install dependencies
npm install
# Build TypeScript
npm run build
# Setup input
mkdir -p storage/key_value_stores/default
cp INPUT.json storage/key_value_stores/default/
# Run locally
npm start

Using Apify CLI

# Install Apify CLI globally
npm install -g apify-cli
# Run actor locally
apify run
# Deploy to Apify platform
apify push

Testing Different Locations

Edit INPUT.json with various test cases:

  • Major cities (London, Tokyo, Delhi, New York)
  • Rural areas (to test low sensor availability)
  • High-pollution areas (to test outlier removal)
  • Coastal vs inland (to compare patterns)

โ“ FAQ & Troubleshooting

"No active PM2.5 sensors found in this area"

Causes:

  • Remote/rural location with no nearby sensors
  • All sensors in area are offline or stale (>48 hours)

Solutions:

  • Increase radiusKm to 20-25km
  • Check sensor coverage on OpenAQ Map
  • Try a nearby major city

"Could not resolve location name"

Causes:

  • Misspelled city name
  • Ambiguous location (e.g., "Cambridge" without country)

Solutions:

  • Add country suffix: "Cambridge, UK" or "Cambridge, USA"
  • Use more specific names: "Central London" instead of "London"
  • Switch to latitude/longitude for precision

Low Confidence Score (<50%)

Causes:

  • Few sensors in area (<10)
  • High sensor disagreement (local pollution sources)
  • Many outliers removed (sensor malfunctions)

Solutions:

  • Increase radiusKm to include more sensors
  • Run multiple times and compare trends
  • Check if specific sensors are consistently outliers

API Key Errors

Causes:

  • Invalid or expired OpenAQ API key
  • Rate limit exceeded on free tier
  • Incorrect key format

Solutions:

  • Generate new key at OpenAQ
  • Check API usage dashboard for rate limits
  • Ensure no extra spaces/characters in key

What Makes This Actor Special

Solves Real Problems: Addresses critical need for reliable, hyperlocal air quality data in health, automation, and AI applications

Built for AI Agents: Structured output with confidence scores optimized for LLM function calling and decision-making

Scientifically Sound: Uses proven statistical methods (IQR outlier removal, EPA AQI standards)

Global Scale: Works across 200+ countries with OpenAQ network

Production Ready: Comprehensive error handling, retries, timeouts, and validation

Well Documented: Complete README, input/output schemas, examples, and troubleshooting


๐Ÿ“š Additional Resources


๐Ÿค Support & Feedback

Need Help?

Feature Requests? Submit ideas via GitHub issues or reach out directly!


๐Ÿ“œ License

Apache License 2.0


๐ŸŽฏ Ready to Get Started?

  1. Get your free OpenAQ API key
  2. Run this actor with your location
  3. Integrate the results into your app, AI agent, or automation system

Let's make air quality data accessible to everyone. ๐ŸŒ๐Ÿ’š