Skip to main content

GET /api/v1/experiments

Fetch experiments and their weighted variants. The SDK calls this endpoint on initialization to retrieve active experiment configurations.

Request

GET https://xaiku.com/api/v1/experiments

Headers

HeaderRequiredDescription
X-public-keyYesYour public key (pk_*)
X-experiment-idsNoComma-separated list of experiment IDs to filter by
X-xaiku-testNoSet to 'true' to bypass the live gate (test mode)

X-experiment-ids is built from the array of experiment IDs passed to the SDK at initialization. When omitted, all experiments associated with the key are returned.

Test mode is activated automatically when localStorage.getItem('xaiku_test') equals 'true' in the browser.

Response

Returns a JSON object with a experiments array. Each experiment contains weighted variants, and each variant includes a parts map, weight, id, and control flag.

{
"experiments": [
{
"id": "exp_abc123",
"variants": [
{
"id": "var_001",
"weight": 50,
"control": true,
"parts": {
"headline": "Welcome to our site",
"cta": "Get started"
}
},
{
"id": "var_002",
"weight": 50,
"control": false,
"parts": {
"headline": "Try something new",
"cta": "Sign up now"
}
}
]
}
]
}

Variant Fields

FieldTypeDescription
idstringUnique variant identifier
weightnumberTraffic allocation weight (variants within a experiment sum to 100)
controlbooleanWhether this variant is the control group
partsobjectMap of field names to text content

Examples

curl

curl -X GET "https://xaiku.com/api/v1/experiments" \
-H "Accept: application/json" \
-H "X-public-key: pk_dGhpcyBpcyBhIHRlc3Q" \
-H "X-experiment-ids: exp_abc123,exp_def456"

JavaScript fetch

const response = await fetch('https://xaiku.com/api/v1/experiments', {
method: 'GET',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-public-key': 'pk_dGhpcyBpcyBhIHRlc3Q',
'X-experiment-ids': 'exp_abc123,exp_def456',
},
});

const { experiments } = await response.json();