-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathopenapi.yaml
More file actions
322 lines (297 loc) · 9.55 KB
/
Copy pathopenapi.yaml
File metadata and controls
322 lines (297 loc) · 9.55 KB
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
openapi: 3.1.0
info:
title: Ribbit Network API
version: "1.0.0"
summary: Public CO2 measurements from the Ribbit Network sensor fleet.
description: |
The Ribbit Network API exposes CO2, temperature, humidity, and location
readings from the global network of citizen-operated CO2 sensors at
[ribbitnetwork.org](https://ribbitnetwork.org).
## Authentication
The data endpoints are **open** — you can call them without an API key on
the free tier. A key is optional and simply unlocks much higher rate limits.
When you have a key, send it in **either** header:
```
Authorization: Bearer <your-key>
X-API-Key: <your-key>
```
Sending a key that is invalid or revoked returns `401 Unauthorized` (a wrong
key is treated as a mistake, not a downgrade to the free tier). Omitting the
header entirely is fine — you are simply served on the free tier.
To request a key, open an issue on
[GitHub](https://github.com/Ribbit-Network/api/issues).
## Rate limits
There are two tiers:
| Tier | Limited by | Sustained rate | Burst |
| --------------- | ----------- | ------------------ | ----- |
| Free (no key) | client IP | 1 request / minute | 5 |
| Keyed | API key | 1 request / second | 60 |
The free tier is sized for polling a single sensor about once a minute. For
anything heavier — more sensors, faster polling — request a key.
Exceeding the limit returns `429 Too Many Requests` with a `Retry-After`
header indicating how many seconds to wait before retrying.
## Errors
Errors are returned as `text/plain` with a short human-readable message and
a meaningful HTTP status code.
license:
name: MIT
url: https://github.com/Ribbit-Network/api/blob/main/LICENSE
contact:
name: Ribbit Network
url: https://github.com/Ribbit-Network/api
servers:
- url: https://api.ribbitnetwork.org
description: Production
tags:
- name: Data
description: CO2 and environmental measurements
- name: Sensors
description: Sensor fleet metadata
- name: Health
description: Service liveness
# An empty requirement ({}) means a key is optional — anonymous callers are
# served on the free tier; a key raises the rate limit.
security:
- {}
- bearerAuth: []
- apiKeyAuth: []
paths:
/:
get:
tags: [Health]
summary: Service banner
description: Returns a frog emoji. Useful as a no-auth liveness check.
security: []
responses:
"200":
description: OK
content:
text/plain:
schema:
type: string
example: "🐸\n"
/healthz:
get:
tags: [Health]
summary: Health check
description: Returns `ok` when the service is up. No authentication required.
security: []
responses:
"200":
description: OK
content:
text/plain:
schema:
type: string
example: "ok\n"
/data:
get:
tags: [Data]
summary: Query sensor measurements
description: |
Returns CO2, temperature, humidity, and location measurements for the
requested time range. Results may be filtered by sensor and aggregated
into time windows.
parameters:
- name: start
in: query
required: true
description: Start of the time range, RFC 3339 timestamp.
schema:
type: string
format: date-time
example: "2024-01-01T00:00:00Z"
- name: stop
in: query
required: false
description: End of the time range, RFC 3339 timestamp. Omit to query through the present.
schema:
type: string
format: date-time
example: "2024-01-02T00:00:00Z"
- name: hosts
in: query
required: false
description: Comma-separated list of sensor IDs to filter by. See `/sensors` for the available IDs.
schema:
type: string
example: "a3f2...,b91c..."
- name: fields
in: query
required: false
description: |
Comma-separated list of fields to return. Omit to return all
available fields. Valid values: `co2`, `lat`, `lon`, `humidity`,
`baro_pressure`, `baro_temperature`, `alt`.
schema:
type: string
example: "co2,lat,lon"
- name: interval
in: query
required: false
description: |
Aggregate readings into windows of this duration using mean
aggregation. Accepts Go duration syntax (e.g. `30s`, `5m`, `1h`).
Omit for raw data.
schema:
type: string
example: "1h"
responses:
"200":
description: Measurements for the requested range.
content:
application/json:
schema:
$ref: "#/components/schemas/DataResponse"
example:
data:
- time: "2024-01-01T00:00:00Z"
host: "a3f2..."
co2: 412.5
lat: 37.77
lon: -122.41
- time: "2024-01-01T01:00:00Z"
host: "a3f2..."
co2: 415.1
lat: 37.77
lon: -122.41
"400":
$ref: "#/components/responses/BadRequest"
"401":
$ref: "#/components/responses/Unauthorized"
"429":
$ref: "#/components/responses/RateLimited"
"500":
$ref: "#/components/responses/ServerError"
/sensors:
get:
tags: [Sensors]
summary: List sensor IDs
description: |
Returns the set of sensor IDs that have reported data recently
(approximately the last 30 days, per InfluxDB's default tag-value
lookback).
responses:
"200":
description: Sensor IDs.
content:
application/json:
schema:
$ref: "#/components/schemas/SensorsResponse"
example:
sensors: ["a3f2...", "b91c...", "c7d4..."]
"401":
$ref: "#/components/responses/Unauthorized"
"429":
$ref: "#/components/responses/RateLimited"
"500":
$ref: "#/components/responses/ServerError"
components:
securitySchemes:
bearerAuth:
type: http
scheme: bearer
description: "Send your API key as `Authorization: Bearer <key>`."
apiKeyAuth:
type: apiKey
in: header
name: X-API-Key
description: "Send your API key in the `X-API-Key` header."
schemas:
DataPoint:
type: object
description: A single measurement from one sensor at one timestamp. Fields omitted from `fields` are not returned.
required: [time, host]
properties:
time:
type: string
format: date-time
description: Measurement timestamp (UTC).
host:
type: string
description: Sensor ID.
co2:
type: number
format: double
description: CO2 concentration (ppm).
lat:
type: number
format: double
description: Sensor latitude (degrees).
lon:
type: number
format: double
description: Sensor longitude (degrees).
alt:
type: number
format: double
description: Sensor altitude (meters).
humidity:
type: number
format: double
description: Relative humidity (%).
baro_pressure:
type: number
format: double
description: Barometric pressure (hPa).
baro_temperature:
type: number
format: double
description: Temperature from the barometric sensor (°C).
DataResponse:
type: object
required: [data]
properties:
data:
type: array
items:
$ref: "#/components/schemas/DataPoint"
SensorsResponse:
type: object
required: [sensors]
properties:
sensors:
type: array
items:
type: string
description: Sensor IDs.
responses:
BadRequest:
description: Invalid query parameters (e.g. missing `start`, malformed RFC 3339 time, unparseable `interval`).
content:
text/plain:
schema:
type: string
example: 'missing required parameter: "start"'
Unauthorized:
description: |
The supplied API key is invalid or revoked. Omitting the key is **not**
an error — those requests are served on the free tier instead.
content:
text/plain:
schema:
type: string
example: "invalid api key"
RateLimited:
description: |
Rate limit exceeded for this tier — the free tier (by IP, 1 req/min,
burst 5) or the keyed tier (by key, 1 req/s, burst 60). The response
includes a `Retry-After` header with the seconds to wait.
headers:
Retry-After:
description: Seconds to wait before retrying.
schema:
type: integer
example: 30
content:
text/plain:
schema:
type: string
example: "rate limit exceeded"
ServerError:
description: Internal error while querying the time-series store.
content:
text/plain:
schema:
type: string
example: "query failed"