# Aurum Data API

Base URL: `http://47.82.95.145/api`

Account and API keys: https://huicointelligent.com/me?tab=api

OpenAPI: http://47.82.95.145/api/openapi.json

## Authentication and quota

Send `Authorization: Bearer <YOUR_API_KEY>` on data requests. Store the key in the `AURUM_API_KEY` environment variable.

New accounts receive 1,000 calls in total. Up to three active keys share that account allowance. Creating, rotating, or revoking keys does not replenish the allowance. Existing daily-quota accounts retain their previous policy and reset at midnight Asia/Shanghai.

Each authenticated data request consumes one call, including requests whose query or data lookup subsequently returns an error. Account access, key management, health checks, and documentation downloads are free.

Response headers:

- `X-RateLimit-Limit`: account allowance.
- `X-RateLimit-Remaining`: remaining calls after this request.
- `X-Quota-Period`: `lifetime` or `daily`.
- `X-RateLimit-Reset`: Unix timestamp; present only for daily quotas.

## Data catalog

`GET /v1/series`

Optional filters: `source_id`, `country`, `metric`; values follow the catalog metadata. `format=json` is the default; `format=markdown` returns readable text.

```bash
curl --get 'http://47.82.95.145/api/v1/series' \
  --header "Authorization: Bearer $AURUM_API_KEY" \
  --data-urlencode 'source_id=fred'
```

The JSON response contains `count`, `data_note`, and `series`. Use each entry's `series_id` to query observations.

## Observations

`GET /v1/observations`

| Parameter | Required | Meaning |
| --- | --- | --- |
| `series_id` | Yes | Catalog ID, 2–32 characters |
| `as_of` | Yes | Research timestamp with timezone, such as `2020-01-01T00:00:00Z` |
| `start`, `end` | No | Inclusive observation dates |
| `limit` | No | 1–10,000; default 1,000 |
| `offset` | No | Pagination offset; default 0 |
| `format` | No | `json` or `markdown` |

```python
import os
import requests

r = requests.get(
    'http://47.82.95.145/api/v1/observations',
    headers={'Authorization': f"Bearer {os.environ['AURUM_API_KEY']}"},
    params={
        'series_id': 'CPIAUCSL',
        'as_of': '2020-01-01T00:00:00Z',
        'start': '2019-01-01',
        'end': '2019-12-31',
        'limit': 1000,
    },
    timeout=30,
)
r.raise_for_status()
print(r.json()['observations'])
print(r.headers.get('X-RateLimit-Remaining'))
```

Results include `source`, `temporal_quality`, `backtest_note`, and `observations`. Observation values are strings to preserve precision.

FRED/ALFRED selects versions visible by `as_of`; ALFRED date-only vintages become available at 00:00 UTC on the following day. IMF data is a current snapshot, available only from its capture time, and cannot reconstruct earlier historical knowledge. Read the returned metadata and quality flags.

## Agent and script instructions

1. Discover actual series with `GET /v1/series` before requesting observations.
2. Specify `series_id`, a timezone-aware `as_of`, and the intended observation-date window.
3. Use `format=markdown` when readable text is useful to the calling tool.
4. Preserve the source, observation date, research timestamp, and time-quality information when presenting results.
5. Do not treat current snapshots as historical vintages. Stop retrying on `429` and check the account balance.

## Health and errors

`GET /healthz` is public, uncharged, and returns `{"status":"ok","database":"ok"}` when healthy.

| HTTP status | Meaning |
| --- | --- |
| 401 | Missing API key |
| 403 | Invalid or revoked API key |
| 404 | Unknown series |
| 422 | Invalid parameters |
| 429 | Account allowance exhausted |
| 5xx | Temporary service or data-source error |

Errors normally use a JSON `detail` field. Remaining-call response headers reflect the server's balance.
