# auth.md

This file is for software agents. It describes how to get credentials for ZilloData, a property data API, and how to use them. Work through it from top to bottom.

## Summary

| Item | Value |
|---|---|
| API (resource server) | `https://api.zillodata.com`, REST at `/v1/...`, MCP at `/mcp` |
| Authorization server | `https://api.zillodata.com` |
| Scope | `mcp:access`. It is the only scope and covers every REST endpoint and MCP tool. |
| Token type | Bearer, sent in the `Authorization` header |

You can authenticate in one of two ways:

| Situation | Method | Human involvement |
|---|---|---|
| A person can create a key and give it to you, or you run server-side | **Option 1: API key** | Once, to create the key |
| You are a remote MCP client, or have no key yet | **Option 2: OAuth 2.1 with Dynamic Client Registration** | Once, to approve the connection |

ZilloData treats the agent as anonymous. You don't assert any user identity. A person grants access either by creating a key in the dashboard or by approving the OAuth consent screen. ID-JAG identity assertions (`urn:ietf:params:oauth:token-type:id-jag`), verified-email claim grants, and JWT-bearer grants aren't supported, and requests that use them will fail.

## Discovery documents

These are public and served with `Access-Control-Allow-Origin: *`:

| Document | URL |
|---|---|
| Protected resource metadata (RFC 9728) | `https://api.zillodata.com/.well-known/oauth-protected-resource` |
| Authorization server metadata (RFC 8414) | `https://api.zillodata.com/.well-known/oauth-authorization-server` |
| This file | `https://zillodata.com/auth.md` |
| OpenAPI 3.1 | `https://zillodata.com/openapi.json` |
| MCP server card | `https://zillodata.com/.well-known/mcp/server-card.json` |

A request to `/v1/...` or `/mcp` without usable credentials gets a 401. Its `WWW-Authenticate` header tells you where to start:

```http
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="zillodata", resource_metadata="https://api.zillodata.com/.well-known/oauth-protected-resource", scope="mcp:access"
```

When a token was sent but rejected, the header also includes `error="invalid_token"` and an `error_description`. The authorization server metadata has an `agent_auth` object that summarizes the OAuth option below.

## Option 1: API key

Use this when a person can hand you a key, or for backend integrations.

1. The person creates a free account at `https://zillodata.com/signup`. It includes 100 credits and needs no card.
2. They create a key at `https://zillodata.com/console/keys/`. Keys look like `zdk_` followed by 43 URL-safe characters. The full key is displayed only once, so store it somewhere safe.
3. Send the key with every request:

```http
GET /v1/properties/29384412/zestimate HTTP/1.1
Host: api.zillodata.com
Authorization: Bearer zdk_<your key>
```

Keys don't expire. Revoke a key at `https://zillodata.com/console/keys/` and it stops working right away.

## Option 2: OAuth 2.1 with Dynamic Client Registration

Remote MCP clients use this flow. It combines the authorization code grant (RFC 6749), Dynamic Client Registration (RFC 7591), and PKCE (RFC 7636) with the S256 method. Clients are public, so there's no client secret.

### Step 1. Register your client

```http
POST /oauth/register HTTP/1.1
Host: api.zillodata.com
Content-Type: application/json

{
  "client_name": "Parcel Scout Agent",
  "redirect_uris": ["https://agent.example.net/oauth/callback"]
}
```

You must send at least one redirect URI. Each must use `https`, or `http` on `localhost` or `127.0.0.1`, and can't contain a fragment. A successful response is `201`:

```json
{
  "client_id": "zoc_...",
  "client_id_issued_at": 1764072000,
  "client_name": "Parcel Scout Agent",
  "redirect_uris": ["https://agent.example.net/oauth/callback"],
  "grant_types": ["authorization_code"],
  "response_types": ["code"],
  "token_endpoint_auth_method": "none",
  "scope": "mcp:access"
}
```

Keep the `client_id`. You can reuse it for later authorizations.

### Step 2. Send the person to approve access

Create a random PKCE code verifier and derive its S256 challenge. Then open this URL in the person's browser:

```
https://api.zillodata.com/oauth/authorize
  ?response_type=code
  &client_id=<client_id>
  &redirect_uri=<a redirect URI you registered>
  &code_challenge=<base64url(sha256(code_verifier))>
  &code_challenge_method=S256
  &scope=mcp:access
  &state=<random value you check later>
```

ZilloData forwards the person to a consent page on `https://zillodata.com`. They sign in, or create an account, and choose Allow or Deny. The consent page expires after 10 minutes.

- On Allow, the browser returns to your redirect URI with `?code=<code>&state=<state>`. The code is valid for 60 seconds and works once.
- On Deny, it returns with `?error=access_denied&state=<state>`.

Check that `state` matches what you sent.

### Step 3. Exchange the code for a token

```http
POST /oauth/token HTTP/1.1
Host: api.zillodata.com
Content-Type: application/x-www-form-urlencoded

grant_type=authorization_code&code=<code>&client_id=<client_id>&redirect_uri=<same redirect URI>&code_verifier=<code_verifier>
```

A JSON body with the same fields also works. A successful response is `200`:

```json
{
  "access_token": "<token>",
  "token_type": "Bearer",
  "expires_in": 31536000,
  "scope": "mcp:access"
}
```

The token lasts about a year and there's no refresh token. When it expires or is revoked, go back to step 2 with the same `client_id`. Each new authorization for the same client name replaces the previous token.

### Step 4. Call the API

```http
POST /mcp HTTP/1.1
Host: api.zillodata.com
Authorization: Bearer <token>
Content-Type: application/json

{"jsonrpc":"2.0","id":1,"method":"tools/list"}
```

The same token works for REST calls under `/v1/...`. The connection shows up in the person's dashboard at `https://zillodata.com/console/keys/`, and its calls appear in their request logs.

### Step 5. Revoke the token (RFC 7009)

```http
POST /oauth/revoke HTTP/1.1
Host: api.zillodata.com
Content-Type: application/x-www-form-urlencoded

token=<token>
```

The endpoint always responds `200`. The person can also revoke the connection from the dashboard.

## Errors

| Status | Meaning | What to do |
|---|---|---|
| 401 `missing_api_key` | No bearer token was sent | Get credentials with option 1 or 2 |
| 401 `invalid_api_key` | Token is malformed, unknown, or revoked | Ask for a new key, or repeat the OAuth flow |
| 402 `out_of_credits` | The account has no credits left | Ask the person to buy credits or upgrade at `https://zillodata.com/console/billing` |
| 403 `account_suspended` | The account isn't active | The person should contact support |
| 429 `rate_limited` | Too many requests this minute for this key | Wait and retry with exponential backoff |

API errors use `{ "error": { "code", "message", "request_id" } }`. OAuth endpoint errors use the RFC 6749 shape, `{ "error": "invalid_grant", "error_description": "..." }`.

## More information

- Authentication guide: `https://zillodata.com/authentication/`
- Rate limits: `https://zillodata.com/rate-limits/`
- Agents guide: `https://zillodata.com/ai-agents/`
- Pricing: `https://zillodata.com/pricing/`
- Terms of Service: `https://zillodata.com/legal/terms/`
- Support: `support@zillodata.com`
