Skip to content

Artisan Commands ​

Spectra provides Artisan commands for installation, data retention, statistics maintenance, pricing updates, pausing recording, alerts, error grouping and evaluations. The dashboard's Maintenance screen runs the same prune and rebuild; prices are checked and written only with spectra:pricing-scrape.

spectra:install ​

An interactive installer that publishes the configuration file and database migrations, and can run the migrations for you. Use it to set up Spectra after installing the Composer package, and to add new migrations after upgrading.

shell
php artisan spectra:install

The installer runs these steps in order:

  1. Publishes configuration. Copies config/spectra.php to your application's config directory (an existing file is kept).
  2. Publishes missing migrations. Copies only the Spectra migrations your database/migrations/ folder doesn't have yet, so it's safe to run again after an upgrade.
  3. Runs migrations (optional). If it published something, it asks whether to run the migrations. Run without a terminal, with --no-interaction or from a Composer script, it never runs them and prints the php artisan migrate to run instead.

Publish New Migrations on composer update ​

To pick up the migrations of a new Spectra version without remembering the installer, add it to the post-update-cmd scripts in your application's composer.json:

json
"scripts": {
    "post-update-cmd": [
        "@php artisan vendor:publish --tag=laravel-assets --ansi --force",
        "@php artisan spectra:install --no-interaction"
    ]
}

Composer runs post-update-cmd after composer update, which you usually run on your own machine to upgrade, and not after the composer install of a deploy. The new migrations land in database/migrations/; commit them, and the php artisan migrate your deploy already runs applies them. The installer doesn't run them itself here, so a Composer script never changes a database.

A package can't add this for you: Composer only runs the scripts in your application's own composer.json.

On a fresh install you can also publish the files yourself. Don't use vendor:publish for migrations when upgrading, though: it copies the older migrations again under a new date.

shell
php artisan vendor:publish --tag=spectra-config
php artisan vendor:publish --tag=spectra-migrations
php artisan migrate

spectra:prune ​

Deletes old request records, with their spans, scores, review queue items and media files, so storage doesn't keep growing. Pruning can't be undone. Make sure your retention period meets your audit and compliance requirements before you schedule this command.

shell
php artisan spectra:prune [--hours=24] [--stats-days=] [--chunk=1000]

Options ​

OptionDefaultDescription
--hours=24Keep requests from the last N hours. Older requests are deleted.
--stats-days=(not set)Also delete daily stats older than N days. Without this option, daily stats are kept.
--chunk=1000How many rows to delete per query
--payload-hours=(not set)Also delete request and response bodies older than N hours, keeping the calls themselves. See Keep Bodies for Less Time.
--pause=0Milliseconds to wait between chunks, to leave more room for live writes on a busy database

The command deletes rows from spectra_requests whose created_at is older than the cutoff, rows from spectra_spans that started before it, and rows from spectra_scores created before it. It works in chunks, so a large table is not locked by one huge query. Their tags in spectra_requests_tags are removed by cascade delete. Media files stored for these requests (see Media Persistence) are deleted from the media disk too.

Daily stats (spectra_daily_stats) are the long-term history behind the dashboard charts, so they are kept by default. Pass --stats-days to prune them too.

Examples ​

shell
# Delete requests older than 24 hours (default)
php artisan spectra:prune

# Keep 7 days of requests
php artisan spectra:prune --hours=168

# Keep 30 days of requests and one year of daily stats
php artisan spectra:prune --hours=720 --stats-days=365

Scheduling ​

Add pruning to your application's scheduler to apply your retention period automatically:

php
use Illuminate\Support\Facades\Schedule;

Schedule::command('spectra:prune --hours=168 --stats-days=365')->daily();

spectra:rebuild-stats ​

Rebuilds the spectra_daily_stats table from the raw spectra_requests records. Run it after data migrations, manual database edits, or bulk imports, or whenever the dashboard stats look out of sync with the requests. An upgrade from 1.x needs one rebuild; see Rebuild the Daily Stats.

The command rebuilds one day at a time: the database adds up the day's requests, and those rows replace the day's stats in one transaction, so a screen never shows a day half rebuilt. Stats are grouped by date, provider, model, model type, and trackable entity. A call saved on a day while that day is being rebuilt can be missed, so rebuild finished days, or rebuild today again afterwards.

Pruned requests

The stats are rebuilt only from the requests that still exist. If you pruned requests but kept their daily stats, rebuilding that date range deletes those stats. Use --from to rebuild only the days whose requests you still have.

shell
php artisan spectra:rebuild-stats [--from=] [--to=] [--yesterday]

Options ​

OptionDescription
--from=Start date in Y-m-d format (for example, 2026-01-01)
--to=End date in Y-m-d format (for example, 2026-01-31)
--yesterdayRebuild only yesterday's statistics

Examples ​

shell
# Rebuild all stats (prompts for confirmation)
php artisan spectra:rebuild-stats

# Rebuild a specific date range
php artisan spectra:rebuild-stats --from=2026-01-01 --to=2026-01-31

# Rebuild yesterday only (suitable for scheduled runs)
php artisan spectra:rebuild-stats --yesterday

Scheduling ​

To keep the stats fresh, schedule a nightly rebuild:

php
Schedule::command('spectra:rebuild-stats --yesterday')->dailyAt('01:00');

spectra:pricing-sync ​

Reads LiteLLM's cost map, a public price feed, and saves the prices that differ from the bundled catalog, and the models it doesn't have, to your pricing file. It needs no key. Set SPECTRA_PRICING_PATH to bill with the saved prices.

shell
php artisan spectra:pricing-sync [provider*] [--path=] [--dry-run]

Options ​

OptionDescription
provider*The providers to sync. Default: every provider the feed covers, which is every provider in the catalog except Scaleway.
--path=Write this file instead of spectra.costs.pricing_path (default: resources/spectra/pricing.json).
--dry-runPrint the changes without writing the file.

Examples ​

shell
# Sync every provider the feed covers and save the changes
php artisan spectra:pricing-sync

# Check OpenAI only, without writing anything
php artisan spectra:pricing-sync openai --dry-run

See Syncing Prices from Feeds for where the prices come from and how they are checked.

spectra:pricing-scrape ​

An alias of spectra:pricing-sync, so scripts that call it keep working. It takes the same arguments and options. --all and --url are accepted and do nothing.

spectra:pause and spectra:resume ​

Pause recording without a deploy, for example during a load test or an incident:

shell
php artisan spectra:pause
php artisan spectra:resume

While paused, AI calls keep working, but Spectra stores no request, span, score or media file. Their cost is not recorded, so it doesn't count toward budgets. The flag is kept in your default cache store, so every server and queue worker sees it when they share that store; cache:clear resumes recording. Each request or job reads the flag once when it first records something, and a long-running process reads it again every 5 seconds, so a pause reaches work already running within a few seconds. The dashboard's Maintenance screen has the same switch.

spectra:check-alerts ​

Checks the alert rules in spectra.alerts.rules against the stored calls, prints each rule's value now, and notifies when a rule starts firing, keeps firing past its cooldown, or recovers. Schedule it every few minutes:

php
Schedule::command('spectra:check-alerts')->everyFiveMinutes();

spectra:group-errors ​

Groups the failed calls saved before the error fingerprint migration ran, so the dashboard's Errors screen shows them too. New failures are grouped as they are saved, so run it once after upgrading:

shell
php artisan spectra:group-errors

spectra:eval ​

Runs an evaluation over its dataset and prints each scorer's result. Pass the class, or its name in App\Evals:

shell
php artisan spectra:eval SupportAnswerEval [--limit=10]

The run, with every example's output and scores, shows on the dashboard's Evals screen.

Command Summary ​

CommandPurposeTypical Usage
spectra:installInteractive setup; publishes missing migrationsAfter composer require and after upgrading
spectra:prune --hours=168Delete old request data, review queue items and mediaScheduled daily for retention management
spectra:rebuild-stats --yesterdayRebuild aggregated statisticsScheduled daily, after data corrections, or once after upgrading
spectra:pricing-syncSave new provider prices to your pricing file, from a public price feedBefore a release picks them up; review and commit the file
spectra:pause / spectra:resumeStop and restart storing requestsDuring load tests or incidents
spectra:check-alertsCheck the alert rules and notifyScheduled every few minutes
spectra:eval SupportAnswerEvalRun an evaluation over its datasetAfter changing a prompt or model, or in CI
spectra:group-errorsGroup failed calls saved before the error fingerprint migrationOnce after upgrading

Released under the MIT License.