Assigns a variant to a user for a specific experiment based on the configured traffic distribution. This endpoint helps in dynamically routing users to different agent variants.
All API endpoints, including this one, require an x-api-key
header for authentication.
Refer to the Authentication section for more details.
POST /experiment/:slug/assign
Name | Type | Description |
---|---|---|
slug | string | Required. The unique slug of the experiment. |
The request body must be a JSON object containing the user’s identifier and any relevant context for the assignment.
Fields:
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).On successful assignment, the server responds with a JSON object containing the assigned variant key and its payload.
Success (200 OK):
Fields:
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.Error Responses:
400 Bad Request
: If the request body is malformed or userId
is missing.401 Unauthorized
: If the x-api-key
is missing or invalid.404 Not Found
: If no experiment with the given slug
is found or if the experiment is not active.500 Internal Server Error
: If there was an unexpected error during the assignment process.