POST
/api/v1/prompts/ab-testsCreate an A/B test, route a request, or check for a winner
Action-discriminated in-memory A/B test manager. action='create' starts a test with 2-20 variants; action='route' selects a variant for a request; action='check-winner' evaluates statistical significance.
Authentication
Send Authorization: Bearer YOUR_API_KEY on every request. Generate API keys at /dashboard/api-keys.
Request body required
Schema
{
"application/json": {
"schema": {
"oneOf": [
{
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": [
"create"
]
},
"name": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"promptId": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"variants": {
"minItems": 2,
"maxItems": 20,
"type": "array",
"items": {}
},
"trafficSplit": {},
"winnerCriteria": {
"type": "object",
"additionalProperties": {}
}
},
"required": [
"action",
"name",
"promptId",
"variants"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": [
"route"
]
},
"testId": {
"type": "string",
"minLength": 1,
"maxLength": 200
},
"requestId": {
"type": "string",
"minLength": 1,
"maxLength": 200
}
},
"required": [
"action",
"testId",
"requestId"
],
"additionalProperties": false
},
{
"type": "object",
"properties": {
"action": {
"type": "string",
"enum": [
"check-winner"
]
},
"testId": {
"type": "string",
"minLength": 1,
"maxLength": 200
}
},
"required": [
"action",
"testId"
],
"additionalProperties": false
}
]
}
}
}Response
200 example
{
"success": true
}All status codes
200Routed variant or winner-check result.
201Test created.
400(no description)
401(no description)
404Test not found (route/check-winner).
429(no description)
Code samples
cURL
curl -X POST \ https://evalguard.ai/api/v1/prompts/ab-tests \ -H "Authorization: Bearer $EVALGUARD_API_KEY" \
TypeScript
import { EvalGuard } from "@evalguard/sdk";
const client = new EvalGuard({ apiKey: process.env.EVALGUARD_API_KEY });
const response = await client.request({
method: "POST",
path: "/api/v1/prompts/ab-tests",
});
console.log(response);Python
from evalguard import EvalGuard import os client = EvalGuard(api_key=os.environ["EVALGUARD_API_KEY"]) response = client.request(method="POST", path="/api/v1/prompts/ab-tests") print(response)
Go
package main
import (
"context"
"fmt"
"net/http"
"os"
)
func main() {
req, _ := http.NewRequestWithContext(context.Background(), "POST", "https://evalguard.ai/api/v1/prompts/ab-tests", nil)
req.Header.Set("Authorization", "Bearer "+os.Getenv("EVALGUARD_API_KEY"))
resp, err := http.DefaultClient.Do(req)
if err != nil { panic(err) }
defer resp.Body.Close()
fmt.Println(resp.Status)
}Errors
400401404429