---
title: "REST API v1 Overview & Authentication"
description: "Authentication headers, base URL, rate limits, pagination, and response formats for Shaf REST API v1."
---

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

# REST API v1 Overview & Authentication

# REST API v1 Overview & Authentication

The Shaf REST API provides programmatic control over links, custom domains, workspace members, analytics telemetry, and edge utility tools. All endpoints use standard HTTP verbs, strict TLS encryption, and predictable JSON payloads.

---

## Base URL

Direct all API requests to the versioned v1 edge gateway:

```text
https://shaf.app/api/v1
```

Non-HTTPS requests are rejected immediately at the Cloudflare edge.

---

## Authentication

Every API request requires an API key passed in the `Authorization` HTTP header with the `Bearer` authentication scheme:

```http
Authorization: Bearer shaf_live_3f8a92b1c4e7d0...
```

Generate and revoke API keys in the dashboard at [Settings > API Keys](https://shaf.app/docs/docs/how-to/integrations-and-developer/api-keys). Keys are scoped to specific workspaces and inherit granular permissions:
- `links:read` — Query links and inspect traffic analytics.
- `links:write` — Create, update, tag, and delete short links.
- `domains:manage` — Register and configure custom domains and reverse proxy subpaths.
- `org:admin` — Manage team members, invitations, and billing settings.

Requests missing valid credentials or permissions fail with `401 Unauthorized` or `403 Forbidden`.

---

## Standard Response Format

Shaf REST endpoints return standardized JSON envelopes.

### Success Envelope (HTTP 200 / 201)

Successful operations return `code: 0` and encapsulate the result payload within `data`:

```json
{
  "code": 0,
  "data": {
    "id": "lnk_98fbc12a",
    "slug": "launch-event",
    "url": "https://example.com/products/launch",
    "domain": "shaf.is",
    "createdAt": 1774180000,
    "updatedAt": 1774180000
  }
}
```

### Error Envelope (HTTP 4xx / 5xx)

Client and server errors return non-zero machine codes alongside descriptive diagnostic messages:

```json
{
  "code": 40001,
  "message": "The destination URL is malformed or lacks a valid protocol (http:// or https://).",
  "data": null,
  "requestId": "req_a1b2c3d4e5f6"
}
```

Provide the `requestId` when reporting issues to support. For a comprehensive catalog of error codes, see [Standard Error Codes](https://shaf.app/docs/docs/reference/error-codes).

---

## Rate Limits

API rate limits enforce fair usage and edge resource stability. Rate limits are tracked per workspace across sliding 60-second windows.

| Plan Tier | Sustained Limit | Burst Cap | Reset Window |
| :--- | :---: | :---: | :---: |
| **Starter** | 120 req / min | 30 req / 5 sec | 60 seconds |
| **Pro** | 600 req / min | 100 req / 5 sec | 60 seconds |
| **Enterprise** | Custom (up to 10,000 req / min) | Custom | 60 seconds |

### Rate Limit Headers

Every API response carries diagnostic rate limit headers:

```http
HTTP/1.1 200 OK
X-RateLimit-Limit: 600
X-RateLimit-Remaining: 588
X-RateLimit-Reset: 1774180060
```

When rate limits are exceeded, the API returns `HTTP 429 Too Many Requests`:

```http
HTTP/1.1 429 Too Many Requests
Retry-After: 12
X-RateLimit-Limit: 600
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1774180060
```

> **Caution**
>
> Always inspect the `Retry-After` header when receiving HTTP 429 and execute exponential backoff with random jitter before retrying failed requests.

---

## Pagination

List endpoints (`/links`, `/organizations/members`, `/tools/export`) support cursor-based and offset-based pagination. Cursor pagination is strongly recommended for high-volume datasets.

### Query Parameters

| Parameter | Type | Default | Description |
| :--- | :--- | :---: | :--- |
| `limit` | `integer` | `50` | Number of items to retrieve per page (min: `1`, max: `100`). |
| `offset` | `integer` | `0` | Number of records to skip in offset-based queries. |
| `cursor` | `string` | — | Opaque pagination cursor string returned by previous response. |

### Paginated Response Structure

```json
{
  "code": 0,
  "data": {
    "items": [
      { "id": "lnk_01", "slug": "alpha" },
      { "id": "lnk_02", "slug": "beta" }
    ],
    "total": 1420,
    "limit": 50,
    "hasMore": true,
    "nextCursor": "eyJzbHVnIjoiYmV0YSIsInRzIjoxNzc0MTgwMDAwfQ=="
  }
}
```

---

## Versioning & Deprecation Policy

The Shaf API uses URL path versioning (`/api/v1`). Breaking changes introduce a new major version path (`/api/v2`). 

- **Non-breaking additions:** New endpoints, optional request parameters, and additional response fields may be added to `/api/v1` without version increments.
- **Deprecation schedule:** Deprecated fields or routes remain operational for a minimum of 6 months following formal notice via changelog and email.

---

## Quickstart Code Samples

### cURL

```bash
curl -X GET "https://shaf.app/api/v1/links?limit=10" \
  -H "Authorization: Bearer $SHAF_API_TOKEN" \
  -H "Accept: application/json"
```

### TypeScript

```typescript
const token = process.env.SHAF_API_TOKEN;

const response = await fetch("https://shaf.app/api/v1/links?limit=10", {
  headers: {
    Authorization: `Bearer ${token}`,
    Accept: "application/json",
  },
});

const data = await response.json();
console.log(data);
```

### Python

```python
import os
import requests

token = os.environ.get("SHAF_API_TOKEN")

response = requests.get(
    "https://shaf.app/api/v1/links",
    params={"limit": 10},
    headers={
        "Authorization": f"Bearer {token}",
        "Accept": "application/json",
    },
)

print(response.json())
```

Source: https://shaf.app/docs/reference/rest-api/overview/index.mdx
