Skip to main content

Batch evaluate

POST /v1/variables resolves many variables for the same user context in one HTTP round-trip. Use this when your app needs more than two or three flags for a single render — it cuts down round-trips and gives every flag the same evaluation snapshot.

Request

POST /v1/variables HTTP/1.1
Host: api.redpennon.dev
X-API-Key: 00000000-0000-0000-0000-000000000000
Content-Type: application/json

{
"keys": ["show-banner", "discount-pct", "ai-search"],
"user": {
"id": "user-123",
"email": "alice@example.com"
}
}

Body

FieldTypeRequiredDescription
keysstring[]yesVariable keys to evaluate. Order is preserved in the response map.
userobjectnoSame shape as the single-evaluate endpoint. See Evaluate a variable.

keys may be empty — the response is {"results": {}}. Unknown keys are not an error: each surfaces inline as reason: "variable_not_found" so a typo in one key never disqualifies the rest of the batch.

Response

{
"results": {
"show-banner": {
"key": "show-banner",
"value": true,
"variation": "on",
"reason": "targeting_rule_matched",
"feature": "marketing-banner"
},
"discount-pct": {
"key": "discount-pct",
"value": 25,
"variation": "experiment-a",
"reason": "targeting_rule_matched",
"feature": "promo-discount"
},
"ai-search": {
"key": "ai-search",
"value": null,
"variation": null,
"reason": "variable_not_found",
"feature": null
}
}
}

Each entry in results has the same shape as the single-evaluate response, keyed by the request key.

Errors

StatusBodyWhen
400{"error":"Invalid JSON."}Body did not parse as JSON.
400{"error":"\"keys\" field is required."}keys was omitted.
400{"error":"\"keys\" must be a list."}keys was sent as something other than an array.
400{"error":"\"user\" must be an object."}user was sent as a non-object.
401{"error":"Invalid or missing API key."}X-API-Key missing, malformed, or doesn't resolve.
405{"error":"Method not allowed."}Anything other than POST.

Example: cURL

curl -X POST "https://api.redpennon.dev/v1/variables" \
-H "X-API-Key: $REDPENNON_API_KEY" \
-H "Content-Type: application/json" \
-d '{"keys": ["show-banner", "discount-pct"], "user": {"id": "user-123"}}'

Example: SDK

import { RedPennonClient } from "@redpennon/node-sdk";

const client = new RedPennonClient({ apiKey: process.env.REDPENNON_API_KEY });
const results = await client.variables(
["show-banner", "discount-pct"],
{ user: { id: "user-123" } },
);
const banner = results["show-banner"].value ?? false;
const discount = results["discount-pct"].value ?? 0;