Troubleshooting
Common problems with Spectra, and how to fix them.
No Requests Are Being Tracked
Symptoms: The dashboard shows no data and the spectra_requests table is empty.
Checklist:
Spectra is enabled. Check that the master switch is on:
iniSPECTRA_ENABLED=trueThe watcher is enabled. Automatic tracking needs the watcher:
iniSPECTRA_WATCHER_ENABLED=trueThe provider is registered. The request hostname must match a provider in
spectra.providers. Requests toapi.openai.com, for example, are recognized automatically. Requests to a custom or self-hosted endpoint need a registered custom provider.The endpoint is trackable. The request path must match a trackable endpoint in the provider's handlers. For example, OpenAI tracks
/v1/chat/completions,/v1/embeddings, and/v1/images/generations, but not/v1/modelsor other non-AI endpoints.Migrations have run. Make sure the
spectra_requeststable exists:shellphp artisan migrateYou use a supported HTTP client. Spectra tracks requests sent through Laravel's
Httpfacade (which also covers Prism and Laravel AI), theopenai-php/laravelSDK, and Guzzle clients with Spectra'sGuzzleMiddleware. Streamed responses through these clients are tracked too. Directcurlcalls and other HTTP clients are not tracked automatically. For those, use the Guzzle middleware,Spectra::stream(), or manual tracking.A stream was not read to the end. A streamed request is recorded when your code reads the body to the end, closes it, or drops the response. If your code keeps the response object alive without reading it, nothing is recorded yet.
Saving failed. Spectra never throws saving errors into your app. They go to your exception handler, so check your error log. A common cause is a missing column after an upgrade (see Migrations).
Requests Tracked but Cost Is Zero
Symptoms: Requests appear in the dashboard but total_cost_in_cents shows 0.000000.
Checklist:
The model is in the catalog. The pricing catalog needs an entry for each model you use. Prices live in the catalog bundled with Spectra and in your own pricing file. See Pricing.
The model name matches. The model id must match a catalog entry: by its exact id, an alias, or the id without a snapshot date or routing suffix. See How Spectra Finds a Model. Compare the
snapshotandmodelvalues in your request records with the ids in the catalog.The pricing tier exists. If you use a non-standard tier (such as
batchorflex), the model needs a row for that tier; without one it bills atstandard.The pricing unit matches the metrics. The model's
pricing_unitin the catalog must match what the response reports. For example, a model priced pertokenscosts zero when the response has no token counts.Cost tracking is enabled. Check the configuration:
php'costs' => [ 'enabled' => true, ],Streamed OpenAI Chat Completions. OpenAI only sends usage in a Chat Completions stream when the request has
'stream_options' => ['include_usage' => true]. Without it, the request is recorded with zero tokens and zero cost. See Streaming.
Dashboard Shows Empty Data
Symptoms: The dashboard loads but displays no requests or statistics.
Checklist:
The dashboard is enabled. Check that the dashboard is not turned off:
iniSPECTRA_DASHBOARD_ENABLED=trueRequest persistence is on. If
store_requestsisfalse, requests are tracked in memory but not saved to the database:iniSPECTRA_STORE_REQUESTS=trueThe database connection is correct. If you use a separate database, make sure the dashboard reads from the connection set in
storage.connection.The authorization gate passes. The
viewSpectragate must returntruefor your user. In local development this is automatic. In production, define the gate:phpGate::define('viewSpectra', function ($user) { return $user->isAdmin(); });The middleware is correct. If you added
authto the dashboard middleware, make sure you are logged in when you open the dashboard.
Queue Persistence Not Working
Symptoms: Requests are tracked but never appear in the database when using queue mode.
Checklist:
A queue worker is running. Make sure a worker is processing the queue:
shellphp artisan queue:workThe queue configuration is correct. Check that the connection and queue name match your worker:
php'queue' => [ 'enabled' => true, 'connection' => null, // or your queue connection 'queue' => null, // or your queue name ],Check failed jobs. The
PersistSpectraRequestJobmay be failing silently:shellphp artisan queue:failedQueue takes priority over after-response. You can only use one of these modes. When
queue.enabledistrue, theafter_responsesetting is ignored.
After-Response Mode Not Working
Symptoms: after_response is enabled but requests appear to persist synchronously.
This is expected in two cases:
- Non-HTTP context. After-response only works during web requests. Console commands, queue jobs, and scheduled tasks always save synchronously, because there is no HTTP response to wait for.
- Queue is enabled. When
queue.enabledistrue, it takes priority andafter_responseis ignored.
Budget Middleware Not Enforcing
Symptoms: Requests proceed even when the user's budget is exceeded.
Checklist:
Budgets are enabled in the configuration:
php'budget' => ['enabled' => true],A budget record exists and is active for the user:
php$user->aiBudget()->where('is_active', true)->first();Middleware is applied correctly to the route:
phpRoute::middleware(['auth', 'spectra.budget:openai,gpt-4o']) ->post('/ai/chat', ChatController::class);The hard limit is enabled. With
hard_limit = false, requests go through and Spectra only fires events. Sethard_limit = trueon the budget to block requests once it is exceeded.
OpenTelemetry Export Not Appearing
Symptoms: OpenTelemetry export is enabled but no traces appear in your observability backend.
Checklist:
The export is enabled in the configuration:
iniSPECTRA_OTEL_ENABLED=trueThe endpoint is reachable. Test the connection to your OTLP endpoint:
shellcurl -v http://localhost:4318/v1/tracesAuthentication headers are set. Most cloud backends require authentication. Check the headers in your configuration.
Export timing. In after-response mode, traces are exported after the HTTP response. In console or queue contexts, they are exported synchronously. If traces show up from CLI commands but not from web requests, check that your server supports terminable middleware.
The timeout is long enough. If the OTLP endpoint is remote or slow, increase the timeout:
iniSPECTRA_OTEL_TIMEOUT=30
Stats Look Wrong After Data Changes
Symptoms: Dashboard charts or cost totals don't match the raw request data.
This can also happen after upgrading from 1.x: Spectra 1.x counted each poll of an async job (for example, video generation) in the daily stats.
Solution: Rebuild the daily statistics from the raw request records:
php artisan spectra:rebuild-stats
# Or rebuild a specific date range
php artisan spectra:rebuild-stats --from=2026-01-01 --to=2026-01-31The stats are rebuilt only from requests that still exist. If you pruned old requests but kept their daily stats, rebuild only the days you still have requests for (see spectra:rebuild-stats).
Media Files Not Being Saved
Symptoms: Image or video generation requests are tracked but no media files are downloaded to disk.
Checklist:
Media persistence is enabled:
iniSPECTRA_MEDIA_ENABLED=trueThe disk is writable. Make sure the configured filesystem disk and path exist and your application can write to them.
An API key is available. Some providers need an API key to download media files. Set the keys in
spectra.api_keys.The URLs haven't expired. Provider media URLs don't last long. If saving is delayed (for example, by a queue with a long delay), the URLs may expire before the download finishes.
Macro Not Available
Symptoms: Http::withAITracking() or Http::withoutAITracking() throws a "Method not found" error.
Checklist:
The service provider is registered. Spectra's service provider should be auto-discovered. If it isn't, register it yourself:
php// config/app.php 'providers' => [ Spectra\SpectraServiceProvider::class, ],Check for conflicts. Another package may have registered a macro with the same name. Laravel macros are global, and the last registration wins.
The macros are registered whether Spectra is enabled or not: with SPECTRA_ENABLED=false, Http::withAITracking() works and records nothing. They are also available on a pending request, after withHeaders(), withToken() and the like.
High Memory Usage
Symptoms: Application memory spikes when making many AI requests in a single process.
Solutions:
Enable queue persistence to move database writes to background workers:
iniSPECTRA_QUEUE_ENABLED=trueDisable payload storage if you don't need request and response bodies:
iniSPECTRA_STORE_REQUEST_DATA=false SPECTRA_STORE_RESPONSES=falseDon't set
SPECTRA_STORE_REQUESTS=falsefor this. It stops Spectra from saving request records at all.Schedule pruning to prevent unbounded table growth:
shellphp artisan spectra:prune --hours=168
Duplicate Requests Being Tracked
Symptoms: The same AI request appears multiple times in the dashboard.
Spectra tracks each request once. Every route into a provider (the HTTP client, the OpenAI SDK, the Guzzle stacks, and withAITracking()) uses the same middleware, and a request sent with withAITracking() is skipped by the global middleware. When two records have the same provider response id, Spectra updates the first one instead of adding a new one. This is also how polled async jobs (for example, video generation) stay one request. If you wrap a stream that Spectra already tracks in Spectra::stream(), it is recorded once.
Causes:
Retry middleware. If your HTTP client retries failed requests, each attempt is tracked as a separate request. This is intentional: every attempt uses tokens and costs money.
No response id. Records are only merged when the provider sends a response id. If you track the same call twice yourself (for example, with
Spectra::track()and a custom Guzzle middleware), and the response has no id, you get two records.
Solution: Use only one tracking mechanism per request path.
Costs Look Higher or Lower After Upgrading
Symptoms: After upgrading to Spectra 2.0, new requests cost more (or less) than the same requests did before.
This is expected. Spectra 2.0 prices requests more accurately:
- Prompt tokens now include cache reads and writes for every provider (Anthropic used to report only the uncached part), and cache writes are billed at their own rate.
- Reasoning tokens are now billed for every provider (Gemini thinking tokens and xAI reasoning tokens used to be left out).
- The tier the provider reports wins over the tier the request asked for.
- A cost the provider reports (OpenRouter, xAI) is used as is.
- The model the provider actually served is priced first.
Older rows keep their old values. Nothing is rewritten. See the Upgrade Guide for details. To fix daily stats that 1.x counted more than once for polled jobs, run php artisan spectra:rebuild-stats once.
"No Exchange Rate" Warning in the Log
Symptoms: The log shows a warning like Spectra: no exchange rate from EUR to USD.
A pricing catalog uses a different currency from your reporting currency (the built-in Scaleway catalog is in EUR). Without a rate, Spectra counts those prices 1:1, so the costs are wrong. Add the rate to config/spectra.php:
'costs' => [
'currency' => 'USD',
'exchange_rates' => [
'EUR' => 1.17, // 1 EUR is worth 1.17 USD
],
],The warning is logged once per process. See Currency Conversion.
Budgets or Per-User Usage Show Nothing for Old Requests
Symptoms: In an app with a morph map, budgets and per-user usage ignore requests recorded before the upgrade.
Spectra 2.0 stores the trackable type as the morph alias ($model->getMorphClass()). Spectra 1.x stored the class name. Update the old rows once, as shown in the Upgrade Guide.
Budget Alert Fired Only Once
Symptoms: A BudgetThresholdReached event fired once, and not again on later requests.
This is expected. Warning, critical, and exceeded alerts fire once per budget, limit, and period. See Alerts Fire Once per Period.
The Playground Won't Open or Run a Call
- The screen says the Playground is off. Set
SPECTRA_PLAYGROUND_ENABLED=true. If you cache your config, runphp artisan config:cacheagain. - The screen says you can't use it. Define the
manageSpectragate for your user. See Who Can Use It. - A request has no Open in Playground button. The Playground is off, or you don't have the
manageSpectragate. - A call opens but Run is turned off. The screen says why: it isn't a text call to a chat endpoint, its request body wasn't stored, or it went to a custom provider. See What Can Be Opened.
- It says no API key was found. Set
spectra.api_keys.{provider}inconfig/spectra.php. See API Keys and Base URLs. - The provider rejects a run that worked in your app. The stored body may have lost something, or the call may need a header Spectra doesn't store. See When a Run Differs from the Original.