CslClient
RELEASEDCslClient is the wrapper-facing entry point for the SDK server and browser package paths. It carries the core paths for jobs, decisions, generation events, and beacons.
Public request methods are fail-silent by design. Use options.onError to observe structured CslSdkError values and machine-readable CslSdkErrorCode values.
Methods
Creates a wrapper job and returns accepted job metadata, a typed rate-limit result, or null on fail-silent transport or contract failure.
| Parameter | Type | Required | Description |
|---|---|---|---|
request | JobRequest | yes | Create-job payload. job_type is the only required field; everything else is optional. |
Returns
Resolves to accepted JobResponse metadata with job_id and slot_ids, { error: "rate_limit_exceeded", retry_after_ms }, or null when the SDK falls back silently.
Notes
- Use
callback_urlinsiderequestwhen the job should switch to callback delivery. - Transport or contract failures are observed through
options.onError, not thrown as hard failures.
Returns a normalized DecisionResponse union. Ready decisions preserve constraints and cs_declaration.
| Parameter | Type | Required | Description |
|---|---|---|---|
slotId | string | yes | One slot id from createJob(). The SDK resolves it through polling, WebSocket, auto, or callback-aware delivery rules. |
options | { wait_ms?: number } | no | Optional polling wait budget for direct decision reads when the integration wants to tune the long-poll request. |
Returns
Resolves to DecisionResponse, which can represent pending, no-fill, or fill outcomes.
Notes
- When
decisionDeliveryis"auto", the SDK prefers WebSocket where available and falls back to polling.
Reports started, finished, or failed generation events to the public wrapper API.
| Parameter | Type | Required | Description |
|---|---|---|---|
jobId | string | yes | Accepted wrapper job id returned by createJob(). |
event | GenerationEvent | yes | Lifecycle stage: "started", "finished", or "failed". |
request | GenerationRequest | no | Optional lifecycle payload such as generation_id, model_id, usage_json, or error. |
Returns
Resolves when the lifecycle event has been handed off through the public wrapper API.
Notes
- Use the same
jobIdfor every lifecycle update tied to one wrapper job.
Sends wrapper beacons such as rendered, visible_started, visible_ended, clicked, and related public beacon types.
| Parameter | Type | Required | Description |
|---|---|---|---|
request | BeaconRequest | yes | Public beacon payload with beacon id, asset_token, beacon type, client timestamp, and optional measurements. |
Returns
Resolves to BeaconResponse, which acknowledges whether the beacon was accepted and may include reason_code.
Notes
- Send beacons only after a fill decision because
asset_tokencomes from the filled response. - Revenue requires the full beacon sequence, not just
rendered: banner and native userendered->visible_started->visible_ended, while clip usesrendered->play_started->play_completed.
Important `createJob()` fields
The table below highlights the minimum request fields most integrators need first when wiring `createJob()`.
createJob() request
Released public JobRequest shape
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
job_type | string | yes | none | Type of job, for example "chat". |
slots_requested | number | no | 1 | Number of sponsoring slots. |
model_id | string | no | "unknown" | Optional model identifier. |
locale | string | no | "en" | Optional locale code, for example "en-US". |
context.topic | string | no | none | Optional context hint for matching without sharing prompt text. |
prompt | { text?: string; token_count_estimate?: number } | string | no | none | Optional prompt context when your integration chooses to send it. |
consent | ConsentFlags | no | server defaults | Optional privacy and consent configuration. |
slot_config | { allowed_formats?: ("banner" | "clip" | "native")[]; max_width?: number; max_height?: number; position_hint?: "above" | "below" | "sidebar" | "between"; bidfloor?: number; bidfloorcur?: string } | no | none | Optional slot and bidfloor hints. |
brand_safety | { blocked_categories?: string[]; blocked_domains?: string[] } | no | none | Optional category and advertiser blocking controls. |
Error handling
Public methods stay fail-silent. Observe SDK failures through options.onError, then handle null or incomplete results in your integration code.
CslSdkErroris the structured error object surfaced throughoptions.onError.CslSdkErrorCodeis the machine-readable companion for transport, timeout, parse, WebSocket, HTTP, and internal failure categories.- Treat
nullfromcreateJob()as a failed handoff and keep your app path moving without assuming a sponsored slot exists.
Documented `CslSdkErrorCode` values
sdk_httpsdk_networksdk_timeoutsdk_websocketsdk_parsesdk_internal
error-handling.ts
typescript
The cause field may contain the originating Error when the SDK can preserve that underlying failure context.
Package and client types
DecisionDeliveryMode
The four supported delivery modes: auto, websocket, polling, and callback.
auto prefers WebSocket when a global WebSocket exists, falls back to polling when it does not, and switches to callback when callback_url is supplied.
Jobs and decisions
ConsentFlags
Optional privacy and consent flags used by createJob().
In the current integration flow, these flags align with the Semantic Source and Semantic Persistence dimensions of the Compute Sponsoring standard. Setting semantic_targeting: true with both persistence flags false corresponds to the CS-S (S1/P0) profile described in the Compute Sponsoring glossary.
Lifecycle and contracts
API first, Script Tag second, SDK third
These pages are the advanced package layer for teams that intentionally choose @csl/wrapper-sdk. Primary onboarding still lives in the API docs, and browser-first installs should start with the Script Tag. Use contact only when you want rollout review, enterprise coordination, or help with non-standard integration constraints. Beacon billing rules live in SDK Concepts.