Use with AI agents
Everything an agent needs to find this API, read the docs and call /v1/fetch on its own.
The API was built with agents as first-class callers. Responses are plain JSON, every value carries the URL it came from, and a missing value is an explicit null with a reason, so a model never has to guess whether a gap is real.
Docs an agent can read
| What | URL |
|---|---|
| Index of every page, for LLMs | /llms.txt |
| All docs in one Markdown file | /llms-full.txt |
| Any page as Markdown | Add .md to the URL, for example /quickstart.md. The home page is /index.md. |
| Markdown by content negotiation | Send Accept: text/markdown to any page URL. |
| Live field catalog, JSON, no key | GET https://api.invariant-ai.com/v1/meta/fields |
Pointing a coding agent at the API? Paste https://docs.invariant-ai.com/llms-full.txt into its context. That file holds the whole reference.
Rules for agents
- Get a key with
POST /v1/keysand the user's real email address. Ask the user for it; never invent one. The key is shown once, so store it (an environment variable such asINVARIANT_API_KEYis the convention). - Call
GET /v1/meta/fieldsto learn which field names exist. It needs no key. - Call
POST /v1/fetchwithlat,lng(WGS84 decimal degrees, US only) and afieldsarray. Send the key inX-API-Key. Use a client timeout of 30 seconds or more. - Read
statuson each field.okmeans usevalue.absentmeans the source has no data at that point, which is a real answer.failedmeans the source did not answer: retry later ifpartial_failures[].retryableistrue, and do not report it as "no data". - When you tell a person a value, give the
source, thesource_urland thedataset_vintagewith it. That lets them check the number against the agency. - One coordinate per request. For many points, send one request per point.
Tool definition for Claude
Pass this in tools on the Anthropic Messages API:
{
"name": "invariant_fetch",
"description": "Get cited public data for one US coordinate from the Invariant Earth API. Returns any of 220 fields (parcels, power and grid, hazards, terrain, climate, land cover, built environment; list them with GET /v1/meta/fields), each with its source URL, dataset vintage and confidence. US only: lat 18 to 72, lng -180 to -65.",
"input_schema": {
"type": "object",
"properties": {
"lat": {
"type": "number",
"minimum": 18,
"maximum": 72,
"description": "Latitude, WGS84 decimal degrees"
},
"lng": {
"type": "number",
"minimum": -180,
"maximum": -65,
"description": "Longitude, WGS84 decimal degrees"
},
"fields": {
"type": "array",
"items": {
"type": "string"
},
"minItems": 1,
"maxItems": 50,
"description": "Field names from GET /v1/meta/fields, for example [\"elevation\"]"
}
},
"required": [
"lat",
"lng",
"fields"
]
}
}
Tool definition for OpenAI
The same tool for function calling with the OpenAI Chat Completions API:
{
"type": "function",
"function": {
"name": "invariant_fetch",
"description": "Get cited public data for one US coordinate from the Invariant Earth API. Returns any of 220 fields (parcels, power and grid, hazards, terrain, climate, land cover, built environment; list them with GET /v1/meta/fields), each with its source URL, dataset vintage and confidence. US only.",
"parameters": {
"type": "object",
"properties": {
"lat": {
"type": "number",
"description": "Latitude, WGS84 decimal degrees, 18 to 72"
},
"lng": {
"type": "number",
"description": "Longitude, WGS84 decimal degrees, -180 to -65"
},
"fields": {
"type": "array",
"items": {
"type": "string"
},
"description": "Field names, for example [\"elevation\"]"
}
},
"required": [
"lat",
"lng",
"fields"
]
}
}
}
Run the tool
Whatever model asks for the call, your code makes it the same way:
import os, requests
API = "https://api.invariant-ai.com"
def invariant_fetch(lat: float, lng: float, fields: list[str]) -> dict:
r = requests.post(
f"{API}/v1/fetch",
headers={"X-API-Key": os.environ["INVARIANT_API_KEY"]},
json={"lat": lat, "lng": lng, "fields": fields},
timeout=30,
)
if r.status_code != 200:
# 400 and 401 carry a stable code in detail.error; hand it back to the model
return {"error": r.json().get("detail", r.text)}
return r.json()
Return the whole JSON to the model. It needs status, source_url and partial_failures to answer honestly.
A system prompt line that works
When you need ground elevation for a US location, call invariant_fetch with
fields ["elevation"]. Report the value in meters with its source_url and
dataset_vintage. If status is "failed", say the source did not answer and
retry later; if "absent", say USGS has no elevation at that point.