# POST /v1/fetch

> Per-field data fetch for one US coordinate, with full provenance.

Source: https://docs.invariant-ai.com/api/fetch

`POST https://api.invariant-ai.com/v1/fetch`

Fetch returns the public fields you ask for at one US coordinate. Each value comes with its source.

```bash
curl -s https://api.invariant-ai.com/v1/fetch \
  -H "X-API-Key: $INVARIANT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"lat": 39.0438, "lng": -77.4874, "fields": ["elevation"]}'
```

```json
{
  "lat": 39.0438,
  "lng": -77.4874,
  "fetched_at": "2026-11-22T03:26:14.083456Z",
  "fields": {
    "elevation": {
      "value": 89.63117218,
      "unit": "meters",
      "status": "ok",
      "source": "USGS_3DEP_COG",
      "source_url": "https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/13/TIFF/current/n40w078/USGS_13_n40w078.tif",
      "confidence": "medium",
      "fetched_at": "2026-11-22T03:26:14.082945Z",
      "dataset_vintage": "USGS 3DEP 1/3 arc-second seamless DEM, current edition; tile n40w078; nominal resolution 10 m",
      "ttl_seconds": 86400,
      "cached": false,
      "notes": "metres; vertical datum NAVD88"
    }
  },
  "partial_failures": [],
  "resolved_location": {
    "lat": 39.0438,
    "lng": -77.4874,
    "source": "coordinate"
  }
}
```

Every value carries:

- **`source` and `source_url`**: the agency and a URL that fetches the same value again.
- **`fetched_at` and `dataset_vintage`**: when we read it, and which release of the dataset it came from.
- **`confidence`**: `high`, `medium`, `low` or `unknown`.
- **An explicit null**: a field the source cannot answer comes back as `null` with a reason, and the request still succeeds.

```bash
curl --request POST \
  --url https://api.invariant-ai.com/v1/fetch \
  --header 'Content-Type: application/json' \
  --header 'X-API-Key: <api-key>' \
  --data '{
  "lat": 39.0438,
  "lng": -77.4874,
  "fields": ["elevation"]
}'
```

```python
import requests

url = "https://api.invariant-ai.com/v1/fetch"

payload = {"lat": 39.0438, "lng": -77.4874, "fields": ["elevation"]}
headers = {"X-API-Key": "<api-key>", "Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers, timeout=30)

print(response.json())
```

```javascript
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<api-key>', 'Content-Type': 'application/json'},
  body: JSON.stringify({lat: 39.0438, lng: -77.4874, fields: ['elevation']})
};

fetch('https://api.invariant-ai.com/v1/fetch', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

Response 200:

```json
{
  "lat": 39.0438,
  "lng": -77.4874,
  "fetched_at": "2026-11-22T03:26:14.083456Z",
  "fields": {
    "elevation": {
      "value": 89.63117218,
      "unit": "meters",
      "status": "ok",
      "source": "USGS_3DEP_COG",
      "source_url": "https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/13/TIFF/current/n40w078/USGS_13_n40w078.tif",
      "confidence": "medium",
      "fetched_at": "2026-11-22T03:26:14.082945Z",
      "dataset_vintage": "USGS 3DEP 1/3 arc-second seamless DEM, current edition; tile n40w078; nominal resolution 10 m",
      "ttl_seconds": 86400,
      "cached": false,
      "notes": "metres; vertical datum NAVD88"
    }
  },
  "partial_failures": [],
  "resolved_location": {
    "lat": 39.0438,
    "lng": -77.4874,
    "source": "coordinate"
  }
}
```

Response 400:

```json
{
  "detail": {
    "error": "fields_unknown",
    "message": "Unknown fields: slope. See GET /v1/meta/fields.",
    "unknown": [
      "slope"
    ]
  }
}
```

Response 401:

```json
{
  "detail": {
    "error": "auth_missing",
    "message": "Send your API key in the X-API-Key header."
  }
}
```

## Authorizations

- `X-API-Key` (string, header, required): Your API key, sent in the header. `Authorization: Bearer <key>` also works. [Get one free](https://docs.invariant-ai.com/get-api-key).

## Headers

- `X-Request-ID` (string): Optional. Echoed back on the response; otherwise we generate one.

## Body

- `lat` (number, required): Latitude, WGS84 decimal degrees.

  Required range: `18 <= x <= 72`
- `lng` (number, required): Longitude, WGS84 decimal degrees.

  Required range: `-180 <= x <= -65`
- `fields` (string[], required): Field names from [`GET /v1/meta/fields`](https://docs.invariant-ai.com/api/meta-fields). Duplicates are ignored. Unknown keys in the body are rejected with `400 invalid_request`.

  Required array length: `1 - 50` elements

## Response

- `fields` (object): One object per requested field, in request order: `value`, `unit`, `status`, `source`, `source_url`, `confidence`, `fetched_at`, `dataset_vintage`, `cached`. Explained in [Responses](https://docs.invariant-ai.com/responses).
- `partial_failures` (object[]): Fields whose source could not answer, each with `field`, `source`, `error` and `retryable`. A failed source still returns `200`.
- `resolved_location` (object): The coordinate the answer is for, with its `source`.
- `lat` (number): Latitude as requested.
- `lng` (number): Longitude as requested.
- `fetched_at` (string): When this response was assembled, ISO 8601 UTC.

## A failed source

```json
{
  "fields": {
    "elevation": {
      "value": null,
      "status": "failed",
      "source": "USGS_EPQS",
      "confidence": "unknown",
      "notes": "USGS_3DEP_COG: 3DEP tile read failed: TimeoutError; USGS_EPQS: EPQS timed out after 20 s"
    }
  },
  "partial_failures": [
    {
      "field": "elevation",
      "source": "USGS_EPQS",
      "error": "USGS_3DEP_COG: 3DEP tile read failed: TimeoutError; USGS_EPQS: EPQS timed out after 20 s",
      "retryable": true
    }
  ]
}
```

## Errors

| HTTP | `error` | When |
| --- | --- | --- |
| 400 | `invalid_request` | Malformed body |
| 400 | `coord_out_of_bounds` | Outside the US envelope |
| 400 | `fields_unknown` | Unknown field name |
| 401 | `auth_missing` / `auth_invalid` | No key, or key not recognised |

Full list on [Errors](https://docs.invariant-ai.com/errors).
