# Korzy: getting an API key for your user

You are an agent. This page explains how to get a Korzy API key for the person you work for, without them creating one by hand. They approve your request in their browser; if they have no Korzy account, approving creates a free one (free credits, no card).

Korzy has records about U.S. land and infrastructure: parcels, flood zones and wetlands, utilities, power plants, substations, transmission, grid capacity, logistics, terrain and data-center projects, each with its as-of date. Docs: https://korzy.co/llms.txt

If your client supports MCP with OAuth, you may not need this: connect to `https://api.korzy.co/mcp` and the user signs in when it connects. Use this flow when you need an API key, for the REST API at `https://api.korzy.co/v1` or for an MCP client configured with a bearer token.

The flow is the OAuth 2.0 device authorization grant (RFC 8628): start → show the user a link and code → they approve → you poll for the key.

## Step 1: Start

```http
POST https://app.korzy.co/agent/signup
Content-Type: application/json

{"email": "user@example.com", "client_name": "Claude Code", "key_name": "Acme site screening"}
```

All fields are optional. `email` is the user's email if you know it: their sign-in starts with it filled in. `client_name` names you (up to 60 characters), `key_name` labels the key on their account page (up to 60 characters; defaults to `client_name`, else `Agent`). The body may also be form-encoded.

```json
{
  "device_code": "kQ3…",
  "user_code": "BCDF-GHJK",
  "verification_uri": "https://app.korzy.co/account/agent",
  "verification_uri_complete": "https://app.korzy.co/account/agent?code=BCDF-GHJK",
  "expires_in": 900,
  "interval": 5
}
```

Keep `device_code` to yourself; it is how you collect the key. Errors: `400 invalid_request` (fix the body), `429 rate_limit_exceeded` (too many from this address; stop and tell the user).

## Step 2: Give the user the link and code (required)

Send the user the full `verification_uri_complete` and the `user_code`, before you start polling. Korzy never emails them. For example:

> To connect Korzy, open https://app.korzy.co/account/agent?code=BCDF-GHJK and approve the request. Check that it shows the code **BCDF-GHJK**. The link expires in 15 minutes.

The user signs in (or signs up, free) and approves. The page shows your `client_name`, the key name and the code.

## Step 3: Poll for the key

```http
POST https://app.korzy.co/agent/token
Content-Type: application/x-www-form-urlencoded

grant_type=urn:ietf:params:oauth:grant-type:device_code&device_code=kQ3…
```

Wait `interval` seconds between polls. Until the user decides, you get HTTP 400 with an `error`:

| `error` | What to do |
| --- | --- |
| `authorization_pending` | Not approved yet. Poll again after `interval` seconds. |
| `slow_down` | You polled too fast. Add 5 seconds to your interval. |
| `access_denied` | The user denied it, or their account cannot take another key. Stop and tell them. |
| `expired_token` | 15 minutes passed. Start again only if the user wants to. |
| `invalid_grant` | Unknown or already used `device_code`. Do not retry it. |

Once approved, the next poll returns the key, once:

```json
{
  "access_token": "korzy_…",
  "token_type": "Bearer",
  "expires_in": 31536000,
  "scope": "api:read mcp:read",
  "api_url": "https://api.korzy.co/v1",
  "mcp_url": "https://api.korzy.co/mcp"
}
```

## Step 4: Use the key

`access_token` is a Korzy API key, valid for a year. Store it where the user keeps secrets (for example the `KORZY_API_KEY` environment variable); do not print it in full or commit it. Send it as `Authorization: Bearer <key>`:

```http
GET https://api.korzy.co/v1/layers
Authorization: Bearer korzy_…
```

`GET /v1/layers` is free: it lists every layer, what it returns and what it costs. Reference: https://korzy.co/docs/ and https://korzy.co/openapi.json

A new account starts with free credits. When they run out, requests return `402` with `plans_url`; tell the user, who can choose a plan on their account page. Never buy anything on the user's behalf.

## Revoking

The user sees and revokes keys at https://app.korzy.co/account. A key that worked and now returns `401` was revoked or expired: drop it and start this flow again only with the user's agreement.
