Laizy CMS
API Reference

API Overview

Overview of the Laizy CMS API — base URL, authentication, request format, and available endpoints.

API Overview

The Laizy CMS API is built on tRPC and provides type-safe endpoints for managing content models, content data, and developer operations. The API is used internally by the generated TypeScript client and the CLI, but you can also call it directly for advanced use cases.

Base URL

All API requests go through the tRPC endpoint:

https://laizycms.com/api/trpc

For local development:

http://localhost:3000/api/trpc

Authentication

Every API request requires two headers:

Authorization: Bearer laizy_eyJhbGciOiJIUzI1NiIs...
x-laizy-project: <project-id>
HeaderRequiredDescription
AuthorizationYesBearer token with laizy_ prefix
x-laizy-projectYesProject ID to scope requests

Token Types

TypeScopeAccess Level
Admin tokenadminFull CRUD on schema, content, and project settings
Frontend tokencontent:readRead-only access to published content

Generate tokens from the dashboard at /dashboard/developer.

For details on token structure, security, and generation, see Authentication.

Request Format

The API uses tRPC's HTTP batch link with SuperJSON as the serialization transformer. This means:

  • Queries use GET requests with encoded input in query parameters
  • Mutations use POST requests with JSON body
  • Responses are JSON with SuperJSON encoding (supports Date, Map, Set, etc.)

For most use cases, you should use the generated TypeScript client or the ManagementClient instead of making raw HTTP calls. They handle serialization, authentication, and error handling automatically.

Available Endpoints

Content Data

CRUD operations for content entries. These are the endpoints used most often by applications.

EndpointMethodDescription
contentData.listQueryList content entries for a model
contentData.getQueryGet a single entry by ID
contentData.createMutationCreate a new content entry
contentData.updateMutationUpdate an existing entry
contentData.deleteMutationDelete an entry
contentData.countQueryCount entries for a model

Content Data Reference

Content Models

Schema management endpoints for defining and updating content models.

EndpointMethodDescription
contentModel.listQueryList all content models
contentModel.getQueryGet a model by name
contentModel.createMutationCreate a new model
contentModel.updateMutationUpdate a model's schema
contentModel.deleteMutationDelete a model
contentModel.existsQueryCheck if a model exists

Developer

Token management and identity verification.

EndpointMethodDescription
developer.getIdentityQueryVerify token and get user/org info
developer.generateTokenMutationGenerate a new admin API token
developer.generateFrontendTokenMutationGenerate a read-only frontend token

Schema Sync

Schema synchronization endpoints used by the CLI.

EndpointMethodDescription
schemaSync.getSchemaStateQueryGet current remote schema state
schemaSync.getContentImpactQueryAnalyze content impact of changes
schemaSync.executeMigrationMutationExecute a migration plan
schemaSync.validateMigrationQueryValidate a plan without executing

Projects

Project management endpoints.

EndpointMethodDescription
project.listQueryList accessible projects
project.getByIdQueryGet project details
project.createMutationCreate a new project
project.updateMutationUpdate project settings

Error Handling

The API returns standard tRPC error codes:

CodeDescription
BAD_REQUESTInvalid input parameters
UNAUTHORIZEDMissing or invalid authentication
NOT_FOUNDResource does not exist
CONFLICTResource already exists (e.g., duplicate model name)
INTERNAL_SERVER_ERRORServer-side error

Error responses include a message field with a human-readable description:

{
  "error": {
    "code": "NOT_FOUND",
    "message": "Content model 'BlogPost' not found"
  }
}

Using the ManagementClient

Instead of making raw HTTP calls, use the ManagementClient which handles all tRPC details:

import { ManagementClient } from '@/lib/management-client';

const client = new ManagementClient({
  baseUrl: 'https://laizycms.com',
  apiToken: process.env.LAIZY_API_TOKEN!,
  projectId: 'your-project-id',
});

// Content operations
const entries = await client.listContentData({ modelName: 'BlogPost' });
const entry = await client.getContentData('entry-id');
const created = await client.createContentData({
  modelName: 'BlogPost',
  data: { title: 'Hello', content: 'World', slug: 'hello' },
  status: 'published',
});
const count = await client.countContentData({ modelName: 'BlogPost' });

// Model operations
const models = await client.listContentModels();
const model = await client.getContentModel('BlogPost');

// Identity verification
const identity = await client.getIdentity();

The ManagementClient provides convenience methods that map directly to the tRPC endpoints with proper typing and error handling.

Next Steps

On this page