File size: 20,315 Bytes
a9814b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# Weatherstack-Compatible API Specification

> **Complete Drop-In Replacement for Weatherstack API**  
> This specification enables developers to build a fully Weatherstack-compatible weather service.

---

## Table of Contents

1. [Overview](#overview)
2. [Authentication](#authentication)
3. [Endpoints](#endpoints)
   - [Current Weather](#endpoint-current-weather)
   - [Historical Weather](#endpoint-historical-weather)
   - [Weather Forecast](#endpoint-weather-forecast)
   - [Location Autocomplete](#endpoint-location-autocomplete)
4. [Response Objects](#response-objects)
5. [Weather Codes](#weather-codes)
6. [Error Handling](#error-handling)
7. [Implementation Guide](#implementation-guide)

---

## Overview

### Base URL
```
https://api.yourweatherservice.com
```

### Protocol
- HTTP and HTTPS supported
- HTTPS recommended for production

### Response Format
All responses are JSON with `Content-Type: application/json`

---

## Authentication

Every request requires an `access_key` parameter containing the user's API key.

```
GET /current?access_key=YOUR_API_KEY&query=New York
```

### Security Best Practices
- Validate API keys on every request
- Implement rate limiting per key
- Log all API access for monitoring

---

## Endpoints

---

### Endpoint: Current Weather

Returns real-time weather conditions for one or more locations.

**URL:** `GET /current`

#### Request Parameters

| Parameter | Required | Type | Default | Description |
|-----------|----------|------|---------|-------------|
| `access_key` | Yes | string | - | API authentication key |
| `query` | Yes | string | - | Location identifier (see Location Formats) |
| `units` | No | string | `m` | Unit system: `m` (metric), `f` (fahrenheit), `s` (scientific) |
| `language` | No | string | `en` | Response language code |
| `callback` | No | string | - | JSONP callback function name |

#### Location Formats Supported

| Format | Example | Description |
|--------|---------|-------------|
| City Name | `New York` | City name, optionally with country |
| Coordinates | `40.7128,-74.0060` | Latitude,Longitude |
| US Zip Code | `10001` | 5-digit US zip code |
| UK Postcode | `SW1A 1AA` | UK postal code |
| IP Address | `153.65.8.20` | IPv4 or IPv6 address |
| Auto IP | `fetch:ip` | Auto-detect from request IP |
| Bulk Query | `New York;London;Tokyo` | Multiple locations (semicolon-separated) |

#### Example Request
```
GET /current?access_key=abc123&query=40.7128,-74.0060&units=f
```

#### Example Response

```json
{
  "request": {
    "type": "LatLon",
    "query": "Lat 40.71 and Lon -74.01",
    "language": "en",
    "unit": "f"
  },
  "location": {
    "name": "New York",
    "country": "United States of America",
    "region": "New York",
    "lat": "40.714",
    "lon": "-74.006",
    "timezone_id": "America/New_York",
    "localtime": "2026-01-30 12:45",
    "localtime_epoch": 1738255500,
    "utc_offset": "-5.0"
  },
  "current": {
    "observation_time": "05:45 PM",
    "temperature": 42,
    "weather_code": 116,
    "weather_icons": [
      "https://api.yourweatherservice.com/images/wsymbol_0002_sunny_intervals.png"
    ],
    "weather_descriptions": ["Partly Cloudy"],
    "wind_speed": 12,
    "wind_degree": 225,
    "wind_dir": "SW",
    "pressure": 1018,
    "precip": 0,
    "humidity": 55,
    "cloudcover": 25,
    "feelslike": 38,
    "uv_index": 3,
    "visibility": 10,
    "is_day": "yes",
    "astro": {
      "sunrise": "07:08 AM",
      "sunset": "05:15 PM",
      "moonrise": "10:32 AM",
      "moonset": "11:45 PM",
      "moon_phase": "Waxing Crescent",
      "moon_illumination": 25
    },
    "air_quality": {
      "co": "234.5",
      "no2": "15.2",
      "o3": "48.0",
      "so2": "5.1",
      "pm2_5": "8.5",
      "pm10": "12.3",
      "us-epa-index": "1",
      "gb-defra-index": "1"
    }
  }
}
```

---

### Endpoint: Historical Weather

Returns historical weather data for a specific date or date range.

**URL:** `GET /historical`

#### Request Parameters

| Parameter | Required | Type | Default | Description |
|-----------|----------|------|---------|-------------|
| `access_key` | Yes | string | - | API authentication key |
| `query` | Yes | string | - | Location identifier |
| `historical_date` | Yes* | string | - | Date in `YYYY-MM-DD` format |
| `historical_date_start` | Yes* | string | - | Start date for time-series |
| `historical_date_end` | Yes* | string | - | End date for time-series |
| `hourly` | No | string | `0` | Include hourly data: `1` or `0` |
| `interval` | No | integer | `3` | Hourly interval: `1`, `3`, `6`, `12`, `24` |
| `units` | No | string | `m` | Unit system |
| `language` | No | string | `en` | Response language |

*Either `historical_date` OR both `historical_date_start` and `historical_date_end` required.

#### Example Request
```
GET /historical?access_key=abc123&query=40.7128,-74.0060&historical_date=2026-01-30&units=f
```

#### Example Response

```json
{
  "request": {
    "type": "LatLon",
    "query": "Lat 40.71 and Lon -74.01",
    "language": "en",
    "unit": "f"
  },
  "location": {
    "name": "New York",
    "country": "United States of America",
    "region": "New York",
    "lat": "40.714",
    "lon": "-74.006",
    "timezone_id": "America/New_York",
    "localtime": "2026-01-30 12:45",
    "localtime_epoch": 1738255500,
    "utc_offset": "-5.0"
  },
  "current": {
    "observation_time": "05:45 PM",
    "temperature": 42,
    "weather_code": 116,
    "weather_icons": ["https://api.yourweatherservice.com/images/partly_cloudy.png"],
    "weather_descriptions": ["Partly Cloudy"],
    "wind_speed": 12,
    "wind_degree": 225,
    "wind_dir": "SW",
    "pressure": 1018,
    "precip": 0,
    "humidity": 55,
    "cloudcover": 25,
    "feelslike": 38,
    "uv_index": 3,
    "visibility": 10
  },
  "historical": {
    "2026-01-30": {
      "date": "2026-01-30",
      "date_epoch": 1738209600,
      "astro": {
        "sunrise": "07:08 AM",
        "sunset": "05:15 PM",
        "moonrise": "10:32 AM",
        "moonset": "11:45 PM",
        "moon_phase": "Waxing Crescent",
        "moon_illumination": 25
      },
      "mintemp": 28,
      "maxtemp": 42,
      "avgtemp": 35,
      "totalsnow": 0,
      "sunhour": 9.5,
      "uv_index": 3,
      "hourly": [
        {
          "time": "0",
          "temperature": 30,
          "wind_speed": 8,
          "wind_degree": 180,
          "wind_dir": "S",
          "weather_code": 113,
          "weather_icons": ["https://api.yourweatherservice.com/images/night_clear.png"],
          "weather_descriptions": ["Clear"],
          "precip": 0,
          "humidity": 65,
          "visibility": 10,
          "pressure": 1020,
          "cloudcover": 0,
          "heatindex": 30,
          "dewpoint": 18,
          "windchill": 25,
          "windgust": 12,
          "feelslike": 25,
          "chanceofrain": 0,
          "chanceofremdry": 95,
          "chanceofwindy": 10,
          "chanceofovercast": 5,
          "chanceofsunshine": 90,
          "chanceoffrost": 20,
          "chanceofhightemp": 0,
          "chanceoffog": 5,
          "chanceofsnow": 0,
          "chanceofthunder": 0,
          "uv_index": 0
        }
      ]
    }
  }
}
```

---

### Endpoint: Weather Forecast

Returns weather forecast for up to 14 days.

**URL:** `GET /forecast`

#### Request Parameters

| Parameter | Required | Type | Default | Description |
|-----------|----------|------|---------|-------------|
| `access_key` | Yes | string | - | API authentication key |
| `query` | Yes | string | - | Location identifier |
| `forecast_days` | Yes | integer | - | Number of forecast days (1-14) |
| `hourly` | No | string | `0` | Include hourly data: `1` or `0` |
| `interval` | No | integer | `3` | Hourly interval: `1`, `3`, `6`, `12`, `24` |
| `units` | No | string | `m` | Unit system |
| `language` | No | string | `en` | Response language |

#### Example Response

The forecast endpoint returns data in the same format as historical, but under the `forecast` key instead of `historical`.

---

### Endpoint: Location Autocomplete

Returns location suggestions for search/autocomplete functionality.

**URL:** `GET /autocomplete`

#### Request Parameters

| Parameter | Required | Type | Description |
|-----------|----------|------|-------------|
| `access_key` | Yes | string | API authentication key |
| `query` | Yes | string | Partial location name to search |

#### Example Response

```json
{
  "request": {
    "query": "New Yo",
    "type": "City"
  },
  "locations": [
    {
      "id": 2459115,
      "name": "New York",
      "country": "United States of America",
      "region": "New York",
      "lat": "40.714",
      "lon": "-74.006",
      "timezone_id": "America/New_York",
      "utc_offset": "-5.0"
    },
    {
      "id": 2459116,
      "name": "New York Mills",
      "country": "United States of America",
      "region": "Minnesota",
      "lat": "46.518",
      "lon": "-95.376",
      "timezone_id": "America/Chicago",
      "utc_offset": "-6.0"
    }
  ]
}
```

---

## Response Objects

### Request Object

| Field | Type | Description |
|-------|------|-------------|
| `type` | string | Query type: `City`, `LatLon`, `IP`, `Zipcode` |
| `query` | string | Processed query string |
| `language` | string | Language code used |
| `unit` | string | Unit system: `m`, `f`, or `s` |

### Location Object

| Field | Type | Description |
|-------|------|-------------|
| `name` | string | Location name |
| `country` | string | Country name |
| `region` | string | State/region/province |
| `lat` | string | Latitude |
| `lon` | string | Longitude |
| `timezone_id` | string | IANA timezone identifier |
| `localtime` | string | Local time: `YYYY-MM-DD HH:MM` |
| `localtime_epoch` | integer | Unix timestamp |
| `utc_offset` | string | UTC offset in hours |

### Current Object

| Field | Type | Unit (f) | Description |
|-------|------|----------|-------------|
| `observation_time` | string | - | Time of observation: `HH:MM AM/PM` |
| `temperature` | integer | °F | Current temperature |
| `weather_code` | integer | - | Weather condition code |
| `weather_icons` | array | - | Weather icon URLs |
| `weather_descriptions` | array | - | Weather descriptions |
| `wind_speed` | integer | mph | Wind speed |
| `wind_degree` | integer | ° | Wind direction in degrees |
| `wind_dir` | string | - | Compass direction: `N`, `NE`, `E`, etc. |
| `pressure` | integer | mb | Atmospheric pressure |
| `precip` | number | in | Precipitation amount |
| `humidity` | integer | % | Humidity percentage |
| `cloudcover` | integer | % | Cloud cover percentage |
| `feelslike` | integer | °F | Feels-like temperature |
| `uv_index` | integer | - | UV index (0-11+) |
| `visibility` | integer | mi | Visibility |
| `is_day` | string | - | Daytime: `yes` or `no` |

### Astro Object

| Field | Type | Description |
|-------|------|-------------|
| `sunrise` | string | Sunrise time: `HH:MM AM` |
| `sunset` | string | Sunset time: `HH:MM PM` |
| `moonrise` | string | Moonrise time: `HH:MM AM/PM` |
| `moonset` | string | Moonset time: `HH:MM AM/PM` |
| `moon_phase` | string | Moon phase name |
| `moon_illumination` | integer | Illumination percentage (0-100) |

**Moon Phases:**
- New Moon
- Waxing Crescent
- First Quarter
- Waxing Gibbous
- Full Moon
- Waning Gibbous
- Last Quarter
- Waning Crescent

### Air Quality Object

| Field | Type | Description |
|-------|------|-------------|
| `co` | string | Carbon Monoxide (μg/m³) |
| `no2` | string | Nitrogen Dioxide (μg/m³) |
| `o3` | string | Ozone (μg/m³) |
| `so2` | string | Sulphur Dioxide (μg/m³) |
| `pm2_5` | string | PM2.5 (μg/m³) |
| `pm10` | string | PM10 (μg/m³) |
| `us-epa-index` | string | US EPA Air Quality Index (1-6) |
| `gb-defra-index` | string | UK DEFRA Air Quality Index |

**US EPA Index Values:**
| Index | Meaning |
|-------|---------|
| 1 | Good |
| 2 | Moderate |
| 3 | Unhealthy for Sensitive Groups |
| 4 | Unhealthy |
| 5 | Very Unhealthy |
| 6 | Hazardous |

### Historical/Forecast Day Object

| Field | Type | Unit (f) | Description |
|-------|------|----------|-------------|
| `date` | string | - | Date: `YYYY-MM-DD` |
| `date_epoch` | integer | - | Unix timestamp |
| `astro` | object | - | Astro data (see above) |
| `mintemp` | integer | °F | Minimum temperature |
| `maxtemp` | integer | °F | Maximum temperature |
| `avgtemp` | integer | °F | Average temperature |
| `totalsnow` | number | in | Total snowfall |
| `sunhour` | number | hrs | Hours of sunshine |
| `uv_index` | integer | - | UV index |
| `hourly` | array | - | Hourly data (if requested) |

### Hourly Object

| Field | Type | Description |
|-------|------|-------------|
| `time` | string | Hour: `0`, `100`, `200`...`2300` |
| `temperature` | integer | Temperature |
| `wind_speed` | integer | Wind speed |
| `wind_degree` | integer | Wind direction degrees |
| `wind_dir` | string | Compass direction |
| `weather_code` | integer | Weather code |
| `weather_icons` | array | Icon URLs |
| `weather_descriptions` | array | Descriptions |
| `precip` | number | Precipitation |
| `humidity` | integer | Humidity % |
| `visibility` | integer | Visibility |
| `pressure` | integer | Pressure |
| `cloudcover` | integer | Cloud cover % |
| `heatindex` | integer | Heat index |
| `dewpoint` | integer | Dew point |
| `windchill` | integer | Wind chill |
| `windgust` | integer | Wind gust speed |
| `feelslike` | integer | Feels-like temp |
| `chanceofrain` | integer | Rain probability % |
| `chanceofremdry` | integer | Remain dry probability % |
| `chanceofwindy` | integer | Windy probability % |
| `chanceofovercast` | integer | Overcast probability % |
| `chanceofsunshine` | integer | Sunshine probability % |
| `chanceoffrost` | integer | Frost probability % |
| `chanceofhightemp` | integer | High temp probability % |
| `chanceoffog` | integer | Fog probability % |
| `chanceofsnow` | integer | Snow probability % |
| `chanceofthunder` | integer | Thunder probability % |
| `uv_index` | integer | UV index |

---

## Weather Codes

| Code | Condition | Icon (Day) |
|------|-----------|------------|
| 113 | Clear/Sunny | ☀️ |
| 116 | Partly Cloudy | ⛅ |
| 119 | Cloudy | ☁️ |
| 122 | Overcast | ☁️ |
| 143 | Mist | 🌫️ |
| 176 | Patchy Rain Nearby | 🌦️ |
| 179 | Patchy Snow Nearby | 🌨️ |
| 182 | Patchy Sleet Nearby | 🌨️ |
| 185 | Patchy Freezing Drizzle | 🌧️ |
| 200 | Thundery Outbreaks | ⛈️ |
| 227 | Blowing Snow | 🌬️ |
| 230 | Blizzard | ❄️ |
| 248 | Fog | 🌫️ |
| 260 | Freezing Fog | 🌫️ |
| 263 | Patchy Light Drizzle | 🌧️ |
| 266 | Light Drizzle | 🌧️ |
| 281 | Freezing Drizzle | 🌧️ |
| 284 | Heavy Freezing Drizzle | 🌧️ |
| 293 | Patchy Light Rain | 🌧️ |
| 296 | Light Rain | 🌧️ |
| 299 | Moderate Rain at Times | 🌧️ |
| 302 | Moderate Rain | 🌧️ |
| 305 | Heavy Rain at Times | 🌧️ |
| 308 | Heavy Rain | 🌧️ |
| 311 | Light Freezing Rain | 🌧️ |
| 314 | Moderate/Heavy Freezing Rain | 🌧️ |
| 317 | Light Sleet | 🌨️ |
| 320 | Moderate/Heavy Sleet | 🌨️ |
| 323 | Patchy Light Snow | 🌨️ |
| 326 | Light Snow | 🌨️ |
| 329 | Patchy Moderate Snow | 🌨️ |
| 332 | Moderate Snow | 🌨️ |
| 335 | Patchy Heavy Snow | 🌨️ |
| 338 | Heavy Snow | 🌨️ |
| 350 | Ice Pellets | 🌨️ |
| 353 | Light Rain Shower | 🌦️ |
| 356 | Moderate/Heavy Rain Shower | 🌦️ |
| 359 | Torrential Rain Shower | 🌧️ |
| 362 | Light Sleet Showers | 🌨️ |
| 365 | Moderate/Heavy Sleet Showers | 🌨️ |
| 368 | Light Snow Showers | 🌨️ |
| 371 | Moderate/Heavy Snow Showers | 🌨️ |
| 374 | Light Ice Pellet Showers | 🌨️ |
| 377 | Moderate/Heavy Ice Pellet Showers | 🌨️ |
| 386 | Patchy Light Rain with Thunder | ⛈️ |
| 389 | Moderate/Heavy Rain with Thunder | ⛈️ |
| 392 | Patchy Light Snow with Thunder | ⛈️ |
| 395 | Moderate/Heavy Snow with Thunder | ⛈️ |

---

## Error Handling

### Error Response Format

```json
{
  "success": false,
  "error": {
    "code": 101,
    "type": "unauthorized",
    "info": "Invalid API access key."
  }
}
```

### Error Codes

| Code | Type | Description |
|------|------|-------------|
| 101 | `unauthorized` | Invalid or missing API key |
| 104 | `usage_limit_reached` | Monthly API limit exceeded |
| 105 | `function_access_restricted` | Feature not available on plan |
| 404 | `404_not_found` | Resource not found |
| 429 | `too_many_requests` | Rate limit exceeded |
| 601 | `missing_query` | No location query provided |
| 602 | `invalid_query` | Invalid location query |
| 603 | `historical_queries_not_supported` | Historical not on plan |
| 604 | `bulk_queries_not_supported` | Bulk queries not on plan |
| 605 | `invalid_language` | Unsupported language code |
| 606 | `invalid_unit` | Invalid unit parameter |
| 607 | `invalid_interval` | Invalid interval parameter |
| 608 | `invalid_forecast_days` | Invalid forecast_days value |
| 609 | `forecast_days_not_supported` | Forecast not on plan |
| 611 | `invalid_historical_date` | Invalid date format |
| 612 | `invalid_historical_time_frame` | Invalid date range |
| 613 | `historical_time_frame_too_long` | Date range > 60 days |
| 614 | `missing_historical_date` | No date provided |
| 615 | `request_failed` | Internal server error |

---

## Implementation Guide

### Required Data Sources

| Data Type | Recommended Sources |
|-----------|---------------------|
| Current Weather | Open-Meteo, OpenWeatherMap, NWS (US) |
| Location Data | GeoNames, OpenStreetMap Nominatim |
| Time Zones | IANA tzdb, Google Time Zone API |
| Sun/Moon Data | SunCalc library, USNO API |
| Air Quality | OpenAQ, WAQI, IQAir |
| Geocoding | Google Geocoding, Mapbox, HERE |

### Unit Conversions

When `units=f` (Fahrenheit):
- Temperature: Fahrenheit
- Wind Speed: mph
- Visibility: miles
- Pressure: millibars (mb)
- Precipitation: inches

When `units=m` (Metric):
- Temperature: Celsius
- Wind Speed: km/h
- Visibility: kilometers
- Pressure: millibars (mb)
- Precipitation: millimeters

When `units=s` (Scientific):
- Temperature: Kelvin
- Wind Speed: m/s
- Visibility: kilometers
- Pressure: millibars (mb)
- Precipitation: millimeters

### Caching Strategy

| Endpoint | Recommended TTL |
|----------|-----------------|
| Current | 10-30 minutes |
| Historical | 24+ hours (immutable) |
| Forecast | 3-6 hours |
| Location | 30+ days |

### Testing Checklist

- [ ] `/current` returns all required fields
- [ ] `/historical` returns properly nested date objects
- [ ] Weather codes match the reference table
- [ ] Times formatted as `HH:MM AM/PM`
- [ ] Coordinates support both positive and negative values
- [ ] Error responses include `success`, `error.code`, `error.type`, `error.info`
- [ ] Unit conversions work correctly
- [ ] Bulk queries parse semicolon-separated locations
- [ ] CORS headers configured for browser access
- [ ] Rate limiting implemented per API key

### Sample cURL Tests

```bash
# Current weather
curl "https://api.yourservice.com/current?access_key=test&query=40.7128,-74.0060&units=f"

# Historical with astro
curl "https://api.yourservice.com/historical?access_key=test&query=40.7128,-74.0060&historical_date=2026-01-30&units=f"

# Test error handling
curl "https://api.yourservice.com/current?access_key=invalid"
```

---

## Appendix: Wind Directions

| Direction | Degrees | Range |
|-----------|---------|-------|
| N | 0° | 348.75° - 11.25° |
| NNE | 22.5° | 11.25° - 33.75° |
| NE | 45° | 33.75° - 56.25° |
| ENE | 67.5° | 56.25° - 78.75° |
| E | 90° | 78.75° - 101.25° |
| ESE | 112.5° | 101.25° - 123.75° |
| SE | 135° | 123.75° - 146.25° |
| SSE | 157.5° | 146.25° - 168.75° |
| S | 180° | 168.75° - 191.25° |
| SSW | 202.5° | 191.25° - 213.75° |
| SW | 225° | 213.75° - 236.25° |
| WSW | 247.5° | 236.25° - 258.75° |
| W | 270° | 258.75° - 281.25° |
| WNW | 292.5° | 281.25° - 303.75° |
| NW | 315° | 303.75° - 326.25° |
| NNW | 337.5° | 326.25° - 348.75° |

---

*This specification enables complete compatibility with the Weatherstack API. A developer implementing this specification can provide a drop-in replacement requiring only a URL change in the consuming application.*