---
url: https://record-api-docs.vercel.app/guide/cli.md
---

# CLI Commands

## CLI Commands

### OpenAPI Specification

OpenAPI is generated dynamically from record configuration at request time:

```text
GET /{api_prefix}/docs/openapi
GET /{api_prefix}/docs/openapi.json
GET /{api_prefix}/docs/llms.mdx
GET /{api_prefix}/docs/llms.txt
```

`/{api_prefix}/docs/openapi.json` is the recommended machine endpoint for public docs mode, returned with `application/vnd.oai.openapi+json`.
`/{api_prefix}/docs/llms.mdx` (or `llms.txt`) provides an AI-oriented markdown contract that points to the OpenAPI schema and key endpoint patterns.

Use the bundled Scalar page to browse the API documentation:

```text
GET /api-docs
GET /api-docs/openapi.json
```

Docs access mode is configurable via `config/record.php`:

```php
'api_docs' => [
    'is_private' => env('RECORD_API_DOCS_PRIVATE', false),
    'access_token_key' => 'access_token',
    'login_api' => '/v1/auth/login',
    'email' => env('RECORD_API_DOCS_EMAIL'),
],
```

* When `is_private=false` (or `api_docs` config is missing), `/api-docs` is public.
* When `is_private=true`, `/api-docs` shows a login form and logs in through internal proxy route `/api-docs/auth/login`.
* In private mode, schema is served from `/api-docs/openapi.json` and requires docs session token.
* In private mode, API docs routes under `/{api_prefix}/docs/*` return `404` to prevent anonymous schema leakage.
* `login_api` can be a relative path (`/v1/auth/login`) or absolute URL (`https://api.example.com/v1/auth/login`) based on client project routing.
* `access_token_key` controls how token is extracted from login response payload.
* `email` (optional) enforces a fixed docs login account for additional protection.

The generated OpenAPI 3.0 schema includes:

**Enhanced Schema Generation:**

* **Full Schema**: Complete model schema with all properties
* **Read Schema**: Optimized for GET responses (includes computed fields, relationships)
* **Write Schema**: Optimized for POST/PUT requests (excludes read-only fields)

**Automatic Documentation:**

* Dynamic CRUD endpoints for all configured tables
* RPC function endpoints (global and table-specific)
* Comprehensive parameter documentation (pagination, filtering, sorting)
* Detailed response schemas with examples
* Security schemes (Bearer token authentication)

**Smart Table Detection:**

* Automatically discovers database tables
* Generates appropriate tags and descriptions
* Includes relationship documentation
* Supports custom table configurations

**Compatibility:**

* Compatible with Swagger UI, Postman, and other OpenAPI tools

**Example Generated Features:**

* RESTful endpoints: `GET /{prefix}/{table}`, `POST /{prefix}/{table}`, etc.
* RPC endpoints: `GET|POST|PUT|PATCH|DELETE /{prefix}/rpc/{functionName}`, `GET|POST|PUT|PATCH|DELETE /{prefix}/{table}/rpc/{functionName}`
* Advanced filtering and pagination parameters
* Comprehensive error response documentation

### Setup Package

```bash
php artisan record-api:setup
```

Publishes default configurations for:

* `config/record.php` - Dynamic table and global function loader configuration
* `config/records/tables` - Per-table `RecordTableType` files
* `config/records/globalFunctions` - Global RPC function group files
* `config/audit.php` - Audit logging settings
* `config/record-api.php` - Package settings (auth guard, OpenAPI output)

### Record Table & Cache Management

```bash
# Create a new per-table RecordTableType config (config/records/tables/{name}.php)
php artisan record-api:record customers

# Clear cached query results (kept in the Laravel cache)
php artisan cache:clear

# Sync RecordTableType columns in config/records/tables from DB schema
php artisan record-api:sync-record-columns

# Clean old audit logs based on retention policy
php artisan record-api:clean-audit-logs

# Clean audit logs with options
php artisan record-api:clean-audit-logs --dry-run
php artisan record-api:clean-audit-logs --force --days=30
php artisan record-api:clean-audit-logs --batch-size=500
```

## Audit Log Cleanup

The package includes a powerful CLI command for cleaning old audit logs based on your retention policy.

### Configuration

Set the retention period in your audit configuration:

```php
// config/audit.php
'retention_days' => env('AUDIT_LOG_RETENTION_DAYS', 365),
```

### Command Options

* `--dry-run` - Show what would be deleted without actually deleting
* `--force` - Force deletion without confirmation prompt
* `--days=N` - Override retention days from config
* `--batch-size=N` - Number of records to delete per batch (default: 1000)

### Usage Examples

```bash
# Basic cleanup (uses config retention_days)
php artisan record-api:clean-audit-logs

# Dry run to see what would be deleted
php artisan record-api:clean-audit-logs --dry-run

# Force cleanup without confirmation
php artisan record-api:clean-audit-logs --force

# Override retention period to 30 days
php artisan record-api:clean-audit-logs --days=30

# Use smaller batch size for large datasets
php artisan record-api:clean-audit-logs --batch-size=500

# Combine options
php artisan record-api:clean-audit-logs --dry-run --days=90
```

### Features

* **Safe by default**: Requires confirmation unless `--force` is used
* **Batch processing**: Deletes records in configurable batches to prevent database locks
* **Progress tracking**: Shows real-time progress with progress bar
* **Statistics**: Reports total deleted and remaining records
* **Dry run mode**: Preview what would be deleted without making changes
* **Configurable**: Respects audit configuration or allows override
