spectra-php/laravel-spectra
Laravel Spectra is the Laravel integration for the Spectra PHP package. It provides config publishing, service-provider registration, and framework-friendly helpers so you can add Spectra to Laravel apps with minimal setup and familiar conventions.
Spectra 2.0 turns AI spend from an estimate into a defensible, per-request ledger, which unlocks a specific class of product decisions rather than generic "observability."
aboveInputTokens thresholds, dated price changes (since), audio/image token rates, megapixel/page/request units, fast/ultrafast tiers — mean formerly invisible cost cliffs are now line items. Prompt caching, long-context surcharges, and reasoning tokens are exactly the levers that decide whether a feature is viable; the 2.0 fixes (Anthropic cache reads/writes, Gemini thinking and tool-use tokens, xAI reasoning) mean earlier cost baselines were systematically understated and should be re-derived before any pricing decision is finalized.traceparent joined as the OpenTelemetry parent, plus conversation_id and conversation_turn, means a PM can price a conversation or a workflow, not just a call. That is the prerequisite for deciding whether agents are sold per-seat, per-run, or per-outcome.error_type/error_message stored from the provider, connection failures recorded and still thrown, request_source, laravel_request_id, ip_address, user_agent, and provider-reported latency replacing client-side timing give support a defensible answer to "why did this user's request fail and what did we still pay for?"spectra:prune --stats-days with chunked deletion plus media cleanup lets a PM set a retention policy that survives a legal review.Strong fit when:
traceparent interop is the differentiator here.Look elsewhere or wait when:
Two adoption risks to raise explicitly:
input_tokens and cache writes never billed at all; Gemini thinking/tool-use tokens and xAI reasoning tokens unbilled; polled async jobs counted once per poll, inflating daily stats and budgets; streams stored as zero-token rows. Any pricing, packaging, or margin decision made on 1.x data should be treated as provisional until re-measured. This is the single most important thing to say out loud, because the direction of error was mostly understatement for the providers people actually use.Spectra is now a scoped service to stop global tags, trackables, tiers and metadata leaking between queued jobs and Octane requests. That is correct, but any code setting global state and expecting it to persist across a job boundary will now find it absent. Budget the migration as an engineering task with a test pass, not a composer bump.For executives — one paragraph: We currently cannot say what a given AI feature, customer, or conversation costs us, and what we do report is known to be wrong in the expensive direction: prompt caching, reasoning tokens, and streamed responses are all under-billed or untracked in the version we run today. Spectra 2.0 gives us a per-request, per-conversation cost ledger across every model we use, with current October 2026 pricing, currency conversion, working budgets, and a dashboard we can put in front of finance. It replaces a recurring engineering maintenance burden — twelve pricing catalogs and provider-specific billing quirks — with a dependency. The cost is a Laravel 11→12/13 upgrade we should be doing anyway on security grounds, plus a scoped migration and a re-baselining exercise. The decision it unlocks is concrete: we can price, cap, and defend AI features instead of guessing at them.
For engineering — the honest summary: This is a substantial correctness release, and much of it is bug fixes rather than features. Streaming no longer breaks the caller's response body while logging a zero-token row; Anthropic cache accounting is fixed at the root; Gemini thinking and tool-use tokens and xAI reasoning tokens are billed; async polling no longer double-counts into daily stats; morph-alias lookups for trackables now resolve; multipart uploads no longer price at $0. Saving a tracked request can no longer throw into the app — failures are reported instead — which matters for request-path safety. The architecture change to note is Spectra becoming a scoped service, which fixes real state leakage across queued jobs and Octane but will surface in any code relying on the old global behaviour. We also gain trace-per-request with queued-job propagation and W3C traceparent joining, OpenTelemetry GenAI semantic conventions, a pruning command that chunks and cleans up stored media, and a request-detail view with an input (uncached / cache-read / cache-write) and output (answer / reasoning) token breakdown. Requirements move to Laravel 12–13 and PHP 8.2–8.5. The upgrade guide is in UPGRADE.md; plan for a migration, a config review (trace_per_request, use_traceparent, exchange_rates), and a before/after cost comparison on a representative workload so we can quantify how wrong the old numbers were.
For finance and finance-adjacent stakeholders: Expect reported AI spend to increase after this upgrade without any change in usage. That is the correction landing, not a regression. Ask for the re-baselined figure before signing off on any pricing or margin model built on prior data.
What to ask for as proof in the first 30 days: a per-feature cost breakdown for one real customer cohort, one budget enforced end-to-end (including through a queued job), and one trace showing every AI call in a single user request with its total cost and token split. If those three land, the tool has earned its place in the stack.
How can I help you explore Laravel packages today?