Skip to content

Configuration

All configuration lives in config/spectra.php, published during installation. Every option can be controlled via environment variables. This page provides a complete reference for all available settings.

Master Switch

php
'enabled' => env('SPECTRA_ENABLED', true),

When set to false, Spectra does nothing — no request interception, no tracking, no database writes, and no dashboard routes. This allows you to disable observability entirely in specific environments without removing the package from your application.

Storage

Controls how and what Spectra persists to the database. These settings let you balance storage consumption, privacy requirements, and debugging needs.

php
'storage' => [
    'connection'           => env('SPECTRA_DB_CONNECTION'),
    'chunk'                => 1000,
    'store_requests'       => env('SPECTRA_STORE_REQUESTS', true),
    'store_responses'      => env('SPECTRA_STORE_RESPONSES', true),
    'store_prompts'        => env('SPECTRA_STORE_PROMPTS', true),
    'store_system_prompts' => env('SPECTRA_STORE_SYSTEM_PROMPTS', true),
    'store_frames'         => env('SPECTRA_STORE_FRAMES', true),
    'store_tools'          => env('SPECTRA_STORE_TOOLS', true),
    'max_prompt_length'    => env('SPECTRA_MAX_PROMPT_LENGTH', 10000),
    'max_response_length'  => env('SPECTRA_MAX_RESPONSE_LENGTH', 10000),
],
KeyTypeDefaultDescription
connectionstring|nullnullDatabase connection name. null uses the application default. Set to a separate connection for high-volume applications to isolate observability writes.
chunkint1000Batch size for bulk operations such as exports and cleanup.
store_requestsbooltruePersist request payloads (the JSON body sent to the provider). Disable to reduce storage for high-volume applications.
store_responsesbooltruePersist response payloads (the JSON returned by the provider).
store_promptsbooltrueStore user prompt text and chat messages. Disable for privacy compliance (GDPR, CCPA).
store_system_promptsbooltrueStore system prompts separately. These often contain proprietary business logic.
store_framesbooltrueCapture the code location (file, line number, call chain) where each request originated. Useful for debugging but adds storage overhead.
store_toolsbooltrueStore function and tool definitions sent to the AI provider. These can be large for complex tool schemas.
max_prompt_lengthint10000Maximum characters for stored prompts. Content beyond this limit is truncated. Set to 0 to disable truncation.
max_response_lengthint10000Maximum characters for stored responses. Set to 0 to disable truncation.

Media Persistence

Some AI endpoints return media with expiring URLs — for example, DALL-E images expire after approximately one hour, and Sora videos include an expires_at timestamp. When media persistence is enabled, Spectra downloads and stores generated media to a Laravel filesystem disk before the URLs expire.

php
'storage' => [
    'media' => [
        'enabled' => env('SPECTRA_MEDIA_ENABLED', false),
        'disk'    => env('SPECTRA_MEDIA_DISK', 'local'),
        'path'    => env('SPECTRA_MEDIA_PATH', 'spectra-media'),
    ],
],
KeyTypeDefaultDescription
media.enabledboolfalseEnable automatic media download and persistence.
media.diskstringlocalLaravel filesystem disk to store media on. Use s3 or another cloud disk in production for accessibility across servers.
media.pathstringspectra-mediaDirectory path within the disk.

API Keys

Optional explicit API keys per provider. These take highest priority in the resolution chain and are used by both the HTTP macros (Http::openai(), etc.) and internal operations such as media downloads.

php
'api_keys' => [
    'openai'    => env('SPECTRA_OPENAI_API_KEY'),
    'anthropic' => env('SPECTRA_ANTHROPIC_API_KEY'),
    // ...
],

For the full resolution chain showing how API keys are discovered from multiple configuration sources, see API Key Auto-Discovery.

Queue

Controls whether request persistence happens synchronously, after the HTTP response, or via a background queue job.

php
'queue' => [
    'enabled'        => env('SPECTRA_QUEUE_ENABLED', false),
    'connection'     => env('SPECTRA_QUEUE_CONNECTION'),
    'queue'          => env('SPECTRA_QUEUE_NAME'),
    'delay'          => env('SPECTRA_QUEUE_DELAY'),
    'after_response' => env('SPECTRA_AFTER_RESPONSE', false),
],
KeyTypeDefaultDescription
enabledboolfalseDispatch a PersistSpectraRequestJob instead of writing synchronously.
connectionstring|nullnullQueue connection name. null uses the application default.
queuestring|nullnullQueue name to dispatch to.
delayint|nullnullSeconds to delay before processing the job.
after_responseboolfalseWhen queue is disabled, persist after the HTTP response is sent to the client. Has no effect when queue is enabled or in non-HTTP contexts.

Persistence Modes

ModeConfigBehaviorBest For
Sync (default)Both falseWrite to database immediatelyDevelopment, low-volume applications
After Responseafter_response: trueWrite after HTTP response is sentProduction web applications without queues
Queueenabled: trueDispatch PersistSpectraRequestJobHigh-volume production applications

WARNING

After-response mode only works during web requests. Console commands, queue workers, and scheduled tasks always persist synchronously unless queue mode is enabled.

Tracking Context

Configure what contextual information Spectra captures automatically with each tracked request.

php
'tracking' => [
    'auto_track_user'    => true,
    'capture_ip'         => true,
    'capture_user_agent' => true,
    'capture_request_id' => true,
],
KeyTypeDefaultDescription
auto_track_userbooltrueAutomatically associate requests with the authenticated user via the polymorphic trackable relationship.
capture_ipbooltrueStore the client's IP address. Disable for GDPR or CCPA compliance.
capture_user_agentbooltrueStore the client's user agent string.
capture_request_idbooltrueCapture or generate a request ID for correlation. Uses the X-Request-ID header if present.

Dashboard

Configure the built-in SPA dashboard.

php
'dashboard' => [
    'domain'      => env('SPECTRA_DOMAIN'),
    'enabled'     => env('SPECTRA_DASHBOARD_ENABLED', true),
    'path'        => env('SPECTRA_PATH', 'spectra'),
    'middleware'   => ['web'],
    'layout'      => env('SPECTRA_DASHBOARD_LAYOUT', 'full'),
    'date_format' => env('SPECTRA_DATE_FORMAT', 'M j, Y g:i:s A'),
],
KeyTypeDefaultDescription
domainstring|nullnullOptional subdomain for the dashboard (e.g., spectra serves it at spectra.yourdomain.com).
enabledbooltrueEnable or disable the web dashboard. Set to false for headless (API tracking only) mode.
pathstringspectraURI path where the dashboard is served.
middlewarearray['web']Middleware applied to dashboard routes. Add 'auth' to require authentication.
layoutstringfullWhich model types the dashboard displays. Options: full, text, embedding, image, video, audio.
date_formatstringM j, Y g:i:s APHP date format string for timestamps in the dashboard.

Costs

Configure cost calculation, pricing tiers, and the pricing lookup cache.

php
'costs' => [
    'enabled'         => true,
    'currency'        => 'USD',
    'currency_symbol' => '$',

    'provider_settings' => [
        'openai' => [
            'default_tier' => env('SPECTRA_OPENAI_PRICING_TIER', 'standard'),
        ],
        'anthropic' => [
            'default_tier' => env('SPECTRA_ANTHROPIC_PRICING_TIER', 'standard'),
        ],
    ],

    'cache' => [
        'enabled' => env('SPECTRA_PRICING_CACHE_ENABLED', true),
        'store'   => env('SPECTRA_PRICING_CACHE_STORE'),
        'ttl'     => env('SPECTRA_PRICING_CACHE_TTL', 3600),
    ],
],
KeyTypeDefaultDescription
enabledbooltrueCalculate and store costs for each tracked request.
currencystringUSDCurrency code for display purposes. Does not perform any conversion.
currency_symbolstring$Symbol shown before cost values in the dashboard.
provider_settings.*.default_tierstringstandardDefault pricing tier for each provider. Used when no explicit tier is specified.
cache.enabledbooltrueCache pricing lookups to avoid repeated database queries. Recommended for production.
cache.storestring|nullnullCache store name. null uses the default cache driver.
cache.ttlint3600Cache duration in seconds (1 hour default).

Budget

Configure budget enforcement defaults. These values apply when individual budgets do not specify their own thresholds.

php
'budget' => [
    'enabled'            => env('SPECTRA_BUDGET_ENABLED', true),
    'default_provider'   => 'openai',
    'default_model'      => 'gpt-4',
    'warning_threshold'  => 80,
    'critical_threshold' => 95,
    'hard_limit'         => true,
    'notification_queue' => 'default',
],
KeyTypeDefaultDescription
enabledbooltrueEnable budget checking and enforcement.
default_providerstringopenaiFallback provider when the budget middleware cannot determine the provider from route parameters.
default_modelstringgpt-4Fallback model for cost estimation in budget checks.
warning_thresholdint80Usage percentage at which a BudgetThresholdReached event fires. Set to 0 to disable.
critical_thresholdint95Usage percentage for the critical threshold event. Set to 0 to disable.
hard_limitbooltrueBlock requests when budget is exceeded. Set to false for soft limits that only fire events.
notification_queuestringdefaultQueue name for dispatching budget notification jobs.

Watcher

Configure automatic HTTP request interception.

php
'watcher' => [
    'enabled'  => env('SPECTRA_WATCHER_ENABLED', true),
    'watchers' => [
        Spectra\Watchers\HttpWatcher::class,
        Spectra\Watchers\OpenAiWatcher::class,
        Spectra\Watchers\GuzzleWatcher::class,
    ],
],
KeyTypeDefaultDescription
enabledbooltrueEnable automatic request interception by watchers.
watchersarraySee aboveList of watcher classes to register. Remove a class to disable that specific watcher.
WatcherInterceptsMechanism
HttpWatcherLaravel Http facade requestsGlobal event listener on ResponseReceived
OpenAiWatcheropenai-php/laravel SDK callsDecorates the OpenAI client with a tracking handler stack
GuzzleWatcherDirect Guzzle HTTP client usageProvides a Guzzle middleware for tracked handler stacks

Providers

Map provider names to their provider classes. Each provider defines hosts, endpoints, and handlers for detecting and extracting data from AI API responses.

php
'providers' => [
    'openai'     => Spectra\Providers\OpenAI\OpenAI::class,
    'anthropic'  => Spectra\Providers\Anthropic\Anthropic::class,
    'google'     => Spectra\Providers\Google\Google::class,
    'ollama'     => Spectra\Providers\Ollama\Ollama::class,
    'openrouter' => Spectra\Providers\OpenRouter\OpenRouter::class,
    'cohere'     => Spectra\Providers\Cohere\Cohere::class,
    'groq'       => Spectra\Providers\Groq\Groq::class,
    'xai'        => Spectra\Providers\XAi\XAi::class,
    'elevenlabs' => Spectra\Providers\ElevenLabs\ElevenLabs::class,
    'replicate'  => Spectra\Providers\Replicate\Replicate::class,
],

Add custom providers by extending AbstractProvider and adding an entry here. See Custom Providers for a complete guide.

Integrations

Configure external integrations. Currently supports OpenTelemetry trace export. See OpenTelemetry for a detailed setup guide.

php
'integrations' => [
    'opentelemetry' => [
        'enabled'             => env('SPECTRA_OTEL_ENABLED', false),
        'endpoint'            => env('SPECTRA_OTEL_ENDPOINT', 'http://localhost:4318/v1/traces'),
        'headers'             => [],
        'service_version'     => env('SPECTRA_OTEL_SERVICE_VERSION', '1.0.0'),
        'resource_attributes' => [],
        'timeout'             => env('SPECTRA_OTEL_TIMEOUT', 10),
    ],
],

Environment Variables

A quick reference of all environment variables supported by Spectra:

bash
# Master switch
SPECTRA_ENABLED=true

# Storage
SPECTRA_DB_CONNECTION=
SPECTRA_STORE_REQUESTS=true
SPECTRA_STORE_RESPONSES=true
SPECTRA_STORE_PROMPTS=true
SPECTRA_STORE_SYSTEM_PROMPTS=true
SPECTRA_STORE_FRAMES=true
SPECTRA_STORE_TOOLS=true
SPECTRA_MAX_PROMPT_LENGTH=10000
SPECTRA_MAX_RESPONSE_LENGTH=10000

# Media
SPECTRA_MEDIA_ENABLED=false
SPECTRA_MEDIA_DISK=local
SPECTRA_MEDIA_PATH=spectra-media

# Queue / persistence mode
SPECTRA_QUEUE_ENABLED=false
SPECTRA_QUEUE_CONNECTION=
SPECTRA_QUEUE_NAME=
SPECTRA_QUEUE_DELAY=
SPECTRA_AFTER_RESPONSE=false

# Dashboard
SPECTRA_DOMAIN=
SPECTRA_DASHBOARD_ENABLED=true
SPECTRA_PATH=spectra
SPECTRA_DASHBOARD_LAYOUT=full
SPECTRA_DATE_FORMAT="M j, Y g:i:s A"

# Watcher
SPECTRA_WATCHER_ENABLED=true

# Costs
SPECTRA_OPENAI_PRICING_TIER=standard
SPECTRA_ANTHROPIC_PRICING_TIER=standard
SPECTRA_PRICING_CACHE_ENABLED=true
SPECTRA_PRICING_CACHE_STORE=
SPECTRA_PRICING_CACHE_TTL=3600

# Budget
SPECTRA_BUDGET_ENABLED=true

# Integrations
SPECTRA_OTEL_ENABLED=false
SPECTRA_OTEL_ENDPOINT=http://localhost:4318/v1/traces
SPECTRA_OTEL_SERVICE_VERSION=1.0.0
SPECTRA_OTEL_TIMEOUT=10

Released under the MIT License.