CslClient
PRODUCTION-READYCslClient is the wrapper-facing entry point for Node/server and browser integrations. 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 or null on fail-silent transport or contract failure.
| Parameter | Type | Required | Description |
|---|---|---|---|
request | JobRequest | yes | Create-job payload with consent, prompt, slot count, and optional routing or callback settings. |
Returns
Resolves to accepted JobResponse metadata with job_id and slot_ids, 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.
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". |
model_id | string | yes | none | Model identifier. |
locale | string | yes | none | Locale code, for example "en-US". |
consent | ConsentFlags | yes | none | User consent configuration. |
prompt | { text: string } | yes | none | Prompt context for targeting. |
slots_requested | number | yes | none | Number of sponsoring slots. |
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
const client = new CslClient({
baseUrl: process.env.CSL_BASE_URL ?? "http://127.0.0.1:3000",
getApiKey: () => process.env.CSL_WRAPPER_API_KEY ?? "",
options: {
onError: (error) => {
console.error(error.code, error.message, error.cause);
},
},
});
const job = await client.createJob(request);
if (!job) {
// Fail-silent path: inspect telemetry or your onError hook.
}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
App 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
Ask about integration
Start with Node direct for the recommended production-ready integration path.