> ## Documentation Index
> Fetch the complete documentation index at: https://docs.yield.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> Authenticate Yield.xyz API requests with the x-api-key header: key format, scope across Earn, Trade and Borrow, and 401 behavior.

Every request needs the `x-api-key` header except the health routes.

```bash theme={null}
curl --request GET \
  --url 'https://api.yield.xyz/v1/yields?limit=1' \
  --header "x-api-key: $YIELD_API_KEY"
```

## Key contract

| Property | Value |
| - | - |
| Header | `x-api-key` |
| Format | UUID v4. Anything else is rejected before lookup. |
| Scope | Keys belong to a project, and a project can have as many keys as you need. Each key authenticates against Earn (`https://api.yield.xyz`), Trade (`https://perps.yield.xyz`) and Borrow (`https://borrow.yield.xyz`). |
| Project scoping | The key resolves to a project. Earn returns only the yields enabled for that project. |
| No key needed | `GET /health` on each host, and `GET /v1/health/providers` on the Perps API. |
| Where keys come from | The dashboard. See [Projects and API keys](https://docs.yield.xyz/documentation/get-started/onboarding.md). |

Keep the key on your server. Do not ship it in browser or mobile bundles; proxy requests through your backend.

## 401 responses

A request fails with `401 Unauthorized` when the key is missing, malformed, unknown, expired, or its project is inactive. The `message` differs per API.

| Condition | Earn and Trade `message` | Borrow `message` |
| - | - | - |
| Header missing | `API key is required` | `API key is missing or invalid` |
| Not a UUID v4 | `Invalid API key format` | `API key is missing or invalid` |
| Key not found | `Invalid API key` | `API key is missing or invalid` |
| Key past its validity window | `API key has expired. Please create a new key or renew this one in the dashboard.` | same expiry message |
| Project missing or inactive | `Project not found or inactive` | `API key is missing or invalid` |

Do not retry a 401 with the same key. See [Errors and retries](https://docs.yield.xyz/api-reference/errors-retries.md) for the response envelope.

> [!NOTE]
>
> `403` is not an auth error. It is returned by the geolocation guard on action routes when the caller's region is blocked. See [Errors and retries](https://docs.yield.xyz/api-reference/errors-retries.md#endpoint-specific-earn-errors).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.