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'),
    '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_tools'          => env('SPECTRA_STORE_TOOLS', true),
    'store_embeddings'     => env('SPECTRA_STORE_EMBEDDINGS', false),
],
KeyTypeDefaultDescription
connectionstring|nullnullDatabase connection name. null uses the application default. Set to a separate connection for high-volume applications to isolate observability writes.
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_toolsbooltrueStore function and tool definitions sent to the AI provider. These can be large for complex tool schemas.
store_embeddingsboolfalseStore embedding vector values in the response column. Embedding requests are always tracked (tokens, costs, latency), but the float-vector arrays can be very large. When disabled, vectors are replaced with [stripped].

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'),
        'path'    => env('SPECTRA_MEDIA_PATH', 'spectra'),
    ],
],
KeyTypeDefaultDescription
media.enabledboolfalseEnable automatic media download and persistence.
media.diskstring|nullnullLaravel filesystem disk to store media on. null uses the default filesystem disk. Use s3 or another cloud disk in production for accessibility across servers.
media.pathstringspectraDirectory path within the disk.

NOTE

Binary data is always stripped from stored responses. Regardless of whether media persistence is enabled, Spectra replaces inline base64-encoded data with [stripped] placeholders before saving responses to the database. This prevents multi-megabyte base64 strings from bloating the response column. The following formats are stripped automatically:

  • OpenAI DALL-E: data[].b64_json
  • OpenAI Responses API: output[].result (image generation calls)
  • Google Gemini: candidates[].content.parts[].inlineData.data (images and audio)
  • Google Imagen: generatedImages[].image.imageBytes

To preserve the actual media files, enable media persistence above. Spectra will decode and store the files on disk, and the dashboard will serve them from the media_storage_path column.

Media files are stored as flat file paths in the media_storage_path JSON column (e.g. ["spectra-media/abc123/0.png", "spectra-media/abc123/1.png"]). The dashboard serves images and audio directly from these paths via internal API routes.

API Keys

Optional explicit API keys per provider. These take highest priority in the resolution chain and are used by internal operations such as media downloads and Google embedding token counting (via the countTokens API).

Spectra resolves API keys using a lookup chain that checks multiple config locations per provider. For example, for Google it checks: spectra.api_keys.googleservices.google.api_keyservices.google.keyprism.providers.gemini.api_keyai.providers.google.key. If any key is found in the chain, it is used.

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

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 and pricing tiers.

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'),
        ],
    ],

    'pricing' => [
        'openai'     => \Spectra\Pricing\OpenAIPricing::class,
        'anthropic'  => \Spectra\Pricing\AnthropicPricing::class,
        'google'     => \Spectra\Pricing\GooglePricing::class,
        'xai'        => \Spectra\Pricing\XAiPricing::class,
        'mistral'    => \Spectra\Pricing\MistralPricing::class,
        'openrouter' => \Spectra\Pricing\OpenRouterPricing::class,
        'replicate'  => \Spectra\Pricing\ReplicatePricing::class,
        'cohere'     => \Spectra\Pricing\CoherePricing::class,
        'groq'       => \Spectra\Pricing\GroqPricing::class,
    ],
],
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.
pricingarraySee aboveMap provider slugs to their ProviderPricing class. See Pricing for customization.

Budget

Configure budget enforcement defaults.

php
'budget' => [
    'enabled'          => env('SPECTRA_BUDGET_ENABLED', true),
    'default_provider' => 'openai',
    'default_model'    => 'gpt-4',
],
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.

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.

For the full list of built-in providers, see Models.

php
'providers' => [
    // Built-in providers are registered by default.
    // Add or override entries as needed.
    'acme' => ['class' => App\Spectra\AcmeProvider::class, 'name' => 'Acme AI'],
],

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

Endpoint URLs

Override the base URL for any provider. This is useful when routing requests through a proxy or using a self-hosted model server:

php
'endpoint_urls' => [
    'openai' => env('OPENAI_BASE_URL', 'https://api.openai.com'),
    'anthropic' => env('ANTHROPIC_BASE_URL', 'https://api.anthropic.com'),
],

When the laravel-ai package is installed, Spectra will also check its config (ai.providers.{provider}.url) as a fallback.

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_TOOLS=true
SPECTRA_STORE_EMBEDDINGS=false

# Media
SPECTRA_MEDIA_ENABLED=false
SPECTRA_MEDIA_DISK=
SPECTRA_MEDIA_PATH=spectra

# 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

# 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.