R4

API

The API provides programmatic access to R4 platform features using API key authentication. It's designed for automation, integrations, and server-to-server communication.

Overview

The API enables you to:

  • Automate infrastructure management - Integrate R4 with your CI/CD pipelines
  • Build custom tooling - Create scripts and tools that interact with R4
  • Enable third-party integrations - Connect R4 with other systems in your stack
  • Monitor and audit - Programmatically access domain and DNS information

Base URL

All API endpoints are available at:

https://r4.dev/api/v1/machine

Authentication

All API requests require authentication using an API key. See the Authentication guide for details on generating and using API keys.

Quick Start

Include your API key in the X-API-Key header:

curl -X GET "https://r4.dev/api/v1/machine/domain-manager/dns-records?domain=example.com" \
  -H "X-API-Key: rk_abc123def456.ghijklmnopqrstuvwxyz"

Rate Limiting

API requests are rate limited to ensure fair usage:

Limit TypeValue
Per minute100 requests
Per day10,000 requests

When you exceed the rate limit, you'll receive a 429 Too Many Requests response:

{
  "error": {
    "code": "rate_limit_exceeded",
    "message": "Rate limit exceeded. Please wait before making additional requests."
  }
}

Error Handling

All API errors follow a consistent format:

{
  "error": {
    "code": "error_code",
    "message": "Human-readable error message"
  }
}

Common Error Codes

CodeHTTP StatusDescription
unauthorized401Invalid or missing API key
forbidden403API key doesn't have access to this resource
not_found404The requested resource was not found
rate_limit_exceeded429Too many requests
internal_error500An unexpected error occurred

Available Endpoints

Domain Manager

Manage DNS records for domains in your organization.

EndpointMethodDescription
/domain-manager/dns-recordsGETGet DNS records for a domain

Project Manager

Create and manage projects — organizational units that contain vaults, licenses, and license groups.

EndpointMethodDescription
/projectGETList all projects
/projectPOSTCreate a new project
/project/:idGETGet project details with associated resources

Vault Manager

Manage encrypted vaults and vault items for secret storage and retrieval.

EndpointMethodDescription
/vaultPOSTCreate a new vault
/vaultGETList all vaults (optionally filter by project)
/vault/env/:projectIdGETGet environment variables for a project
/vault/encryption-keyGETGet the encryption key for an encrypted vault
/vault/:vaultIdGETGet vault details
/vault/:vaultIdDELETEArchive a vault
/vault/:vaultId/itemsPOSTCreate a vault item
/vault/:vaultId/itemsGETList vault items
/vault/:vaultId/items/:itemIdGETGet vault item details with secrets
/vault/:vaultId/items/:itemIdDELETEArchive a vault item

See the API Reference for full request/response documentation.

SDKs and Libraries

Node.js SDK

We provide an official Node.js SDK for interacting with the API. See the @r4security/sdk package for installation and usage.

Example: Python

import requests
 
API_KEY = "rk_abc123def456.ghijklmnopqrstuvwxyz"
BASE_URL = "https://r4.dev/api/v1/machine"
 
def list_projects() -> dict:
    response = requests.get(
        f"{BASE_URL}/project",
        headers={"X-API-Key": API_KEY}
    )
    response.raise_for_status()
    return response.json()
 
def list_vault_items(vault_id: str) -> dict:
    response = requests.get(
        f"{BASE_URL}/vault/{vault_id}/items",
        headers={"X-API-Key": API_KEY}
    )
    response.raise_for_status()
    return response.json()
 
# Usage
projects = list_projects()
print(projects)

Example: JavaScript/TypeScript

const API_KEY = 'rk_abc123def456.ghijklmnopqrstuvwxyz'
const BASE_URL = 'https://r4.dev/api/v1/machine'
 
async function listProjects() {
  const response = await fetch(`${BASE_URL}/project`, {
    headers: { 'X-API-Key': API_KEY },
  })
  if (!response.ok) throw new Error(`API error: ${response.status}`)
  return response.json()
}
 
async function getVaultItemDetail(vaultId: string, itemId: string) {
  const response = await fetch(`${BASE_URL}/vault/${vaultId}/items/${itemId}`, {
    headers: { 'X-API-Key': API_KEY },
  })
  if (!response.ok) throw new Error(`API error: ${response.status}`)
  return response.json()
}
 
// Usage
const projects = await listProjects()
console.log(projects)

Support

If you need help with the API:

  • Check the API Reference for detailed endpoint documentation
  • Contact our support team
  • Visit our status page for system updates