All API endpoints, including this one, require an
x-api-key
header for authentication.
Refer to the Authentication section for more details.Endpoint
POST /experiment/:slug/assign
Path Parameters
Name | Type | Description |
---|---|---|
slug | string | Required. The unique slug of the experiment. |
Request Body
The request body must be a JSON object containing the user’s identifier and any relevant context for the assignment.userId
(string, required): A unique identifier for the user for whom the variant is being assigned. This helps in ensuring consistent variant assignment for the same user if needed.context
(object, optional): An optional JSON object that can contain any contextual information relevant to this assignment. This data is logged alongside the assignment and can be useful for later analysis (e.g., session information, user properties).
Response Body
On successful assignment, the server responds with a JSON object containing the assigned variant key and its payload. Success (200 OK):variant
(string): The key of the variant that was assigned (e.g., “A”, “B”).payload
(object): The JSON payload associated with the assigned variant. This could be a prompt, a configuration object, or any other data defined for the variant.
400 Bad Request
: If the request body is malformed oruserId
is missing.401 Unauthorized
: If thex-api-key
is missing or invalid.404 Not Found
: If no experiment with the givenslug
is found or if the experiment is not active.500 Internal Server Error
: If there was an unexpected error during the assignment process.