Skip to main content
The PHP SDK is published on Packagist and the source lives on GitHub. Install it with Composer in Laravel or any other PHP app.

Installation

If you are using Laravel, this is the standard installation path. Composer pulls the package from Packagist automatically.

Initialize the client

The SDK uses a Bearer token for authentication. Obtain an access token by exchanging your SDK credentials and pass it when creating the client:

Configuration options


Get recommendations

Each recommendation includes id, object, item_id, rank, score, and an embedded item object with the metadata you stored. The response also includes a request_id for event attribution. Use search when the user supplies a free-text query and you want ranked catalog items back through the Core API data plane:
The SDK posts to https://api.neuronsearchlab.com/v1/search, not the console Platform API. Search responses use the same item shape as recommendations and include query, request_id, data, and recommendations.

Auto-generated sections

Use getAutoRecommendations for paginated, auto-titled recommendation sections:

Track events

Events provide the feedback loop that powers personalization. The PHP SDK buffers events in memory for the lifetime of the current process.

How batching works in PHP

1

Buffer events

Events are buffered with a timestamp that maps to occurred_at in the API.
2

Flush at max batch size

The buffer flushes when it reaches maxBatchSize.
3

Force delivery when needed

You can force delivery with flushEvents() or by calling ->wait() on the returned PendingResult.
4

Flush during shutdown

Remaining buffered events are flushed during PHP shutdown.
5

Retry failed sends

Failed sends are retried with exponential backoff.

Request ID propagation

When propagateRecommendationRequestId is enabled, the SDK captures the request_id from getRecommendations() or search() and automatically attaches it to subsequent trackEvent() calls unless you explicitly provide requestId or request_id.

Manage catalog items

Create an item

Update an item

Or use the convenience helper:

Delete items


Error handling

The SDK exposes SDKHttpError and SDKTimeoutError:
Transient errors such as 429s, 5xxs, and timeouts are retried automatically.

Logging

Configure structured logging for debugging and observability:
Available log levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL.

Session management

The SDK auto-generates a session UUID on initialization when autoSessionId is enabled. You can override or read it: