Skip to content

REST API v1 Overview & Authentication

Authentication headers, base URL, rate limits, pagination, and response formats for Shaf REST API v1.

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:

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:

Authorization: Bearer shaf_live_3f8a92b1c4e7d0...

Generate and revoke API keys in the dashboard at Settings > 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:

{
  "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:

{
  "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.


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/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/1.1 429 Too Many Requests
Retry-After: 12
X-RateLimit-Limit: 600
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1774180060

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

{
  "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 -X GET "https://shaf.app/api/v1/links?limit=10" \
  -H "Authorization: Bearer $SHAF_API_TOKEN" \
  -H "Accept: application/json"
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);
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())

Type to search…

↑↓ navigate↵ selectEsc close