Skip to main content

GET /api/feature-flags

Fetches feature flags and experiments for a user. This endpoint is called by the SDK to get the current state of feature flags.

Request

Headers

X-Api-Key
string
required
Your API key

Query Parameters

userId
string
The user’s ID (if user is identified)
anonymousId
string
The anonymous ID
userProperties
string
JSON-encoded user properties for targeting (optional)

Example Request

curl -X GET "https://api.solute.dev/api/feature-flags?userId=user_123&anonymousId=anon_456" \
  -H "X-Api-Key: your_api_key"

Response

Success Response

flags
object
required
Object mapping flag keys to flag objects
experiments
object
Object mapping experiment keys to experiment objects
timestamp
string
required
ISO 8601 timestamp

Flag Object

key
string
required
Flag key
enabled
boolean
required
Whether the flag is enabled
variant
string
Assigned variant (for experiments)
value
boolean | string | number | object
Flag value
rolloutPercentage
number
Rollout percentage (0-100)

Experiment Object

key
string
required
Experiment key
name
string
required
Experiment name
variants
Array<{ key: string; value: any }>
required
Available variants
assignedVariant
string
Assigned variant for this user
status
'draft' | 'running' | 'paused' | 'completed'
required
Experiment status

Example Response

{
  "flags": {
    "new-checkout-flow": {
      "key": "new-checkout-flow",
      "enabled": true,
      "variant": "variant-b",
      "value": true,
      "rolloutPercentage": 50
    },
    "show-ai-assistant": {
      "key": "show-ai-assistant",
      "enabled": false,
      "value": false
    }
  },
  "experiments": {
    "pricing-test": {
      "key": "pricing-test",
      "name": "Pricing Page A/B Test",
      "variants": [
        { "key": "control", "value": "original" },
        { "key": "variant-a", "value": "new-design" }
      ],
      "assignedVariant": "variant-a",
      "status": "running"
    }
  },
  "timestamp": "2025-01-15T10:30:00Z"
}

Feature Flag Evaluation

Consistent Hashing

For percentage-based rollouts, use consistent hashing to ensure the same user always gets the same variant:
function assignVariant(userId: string, flagKey: string, rolloutPercentage: number): boolean {
  const hash = djb2Hash(`${userId}:${flagKey}`);
  const userPercentage = (hash % 100) + 1; // 1-100
  return userPercentage <= rolloutPercentage;
}

function djb2Hash(str: string): number {
  let hash = 5381;
  for (let i = 0; i < str.length; i++) {
    hash = (hash * 33) ^ str.charCodeAt(i);
  }
  return hash >>> 0;
}

Targeting Rules

Support targeting based on user properties:
  • equals: Property equals value
  • not_equals: Property does not equal value
  • contains: Property contains value (for arrays/strings)
  • not_contains: Property does not contain value
  • greater_than: Property is greater than value
  • less_than: Property is less than value
  • is_set: Property exists
  • is_not_set: Property does not exist

Best Practices

Cache feature flags to reduce database load. Refresh cache when flags are updated.
Use consistent hashing to ensure users always get the same variant.
Evaluate targeting rules based on user properties to determine flag values.