Skip to content

Feature Flags

Feature flags and gradual rollouts: define flags, evaluate per user/context, toggle and roll out by percentage — LaunchDarkly-style.

1. Overview

Base path: https://api.infrai.cc/v1/flags
Auth header: Authorization: Bearer $INFRAI_API_KEY
bash
# Call any /v1/flags capability over raw HTTP — no SDK to install.
# curl:
curl https://api.infrai.cc/v1/flags/... \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json"

2. Methods (9)

2.1flags.is_enabled

GET /v1/flags/is_enabled/{key}

Evaluate a feature flag for the current context.

Parameters

NameTypeRequiredDescription
keystring
Required
Feature flag key.

Returns

{ enabled: boolean }
NameTypeDescription
valueanyEvaluated flag value for the supplied user/context (type matches flag.type).
variantobject | nullWinning variant when a multi-variant rollout was applied; null otherwise.
variant.valueanyVariant value; type must match flag.type.
variant.weightinteger0..100; sum of weights must be <= rollout.percentage.
0–100
keystringFlag key that was evaluated (flags.is_enabled only).
enabledbooleanBoolean-coerced evaluation result, same value as `value` (flags.is_enabled only).

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/flags/is_enabled/KEY \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.2flags.set

POST /v1/flags/set

创建或更新功能开关定义

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键
pattern: ^[a-z0-9_.-]{1,128}$
descriptionstringOptional功能开关描述
5–500 chars
type"bool" | "string" | "number" | "json" | nullOptional取值类型:bool/string/number/json
default_valueunknownOptional默认取值
rulesFlagRule[]Optional定向规则列表
rolloutRolloutConfigOptional灰度发布配置
tagsRecord<string, string>Optional键值标签
enabledbooleanOptional是否启用
default: true
versionnumberOptional版本号,用于乐观并发控制
≥ 1

Returns

Flag
NameTypeDescription
keystringUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
descriptionstringFree-text description of this resource
5–500 chars
type"bool" | "string" | "number" | "json"Type discriminator for this resource
default_valueanyDefault value when no rules match
enabledbooleanWhether this feature or configuration is enabled
default: true
rulesobject[]Targeting rules for the flag
rolloutobject | nullRollout configuration for gradual delivery
tagsobject | nullTags for categorization and filtering
versionintegerOptimistic-lock counter.
≥ 1
created_atstringISO 8601 timestamp when this resource was created
format: date-time
created_bystringUser who created this flag
updated_atstringISO 8601 timestamp when this resource was last updated
format: date-time
updated_bystringUser who last updated this flag
archived_atstring | nullISO 8601 timestamp when this flag was archived
format: date-time

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/flags/set \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "sample"}'

2.3flags.list

GET /v1/flags/list

分页列出功能开关

Parameters

NameTypeRequiredDescription
cursorstringOptional分页游标
limitnumberOptional每页返回数量
include_archivedbooleanOptional是否包含已归档开关

Returns

FlagList
NameTypeDescription
itemsobject[]Array of result items in this page
items[].keystringUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
items[].descriptionstringFree-text description of this resource
5–500 chars
items[].type"bool" | "string" | "number" | "json"Type discriminator for this resource
items[].default_valueanyDefault value when no rules match
items[].enabledbooleanWhether this feature or configuration is enabled
default: true
items[].rulesobject[]Targeting rules for the flag
items[].rolloutobject | nullRollout configuration for gradual delivery
items[].tagsobject | nullTags for categorization and filtering
items[].versionintegerOptimistic-lock counter.
≥ 1
items[].created_atstringISO 8601 timestamp when this resource was created
format: date-time
items[].created_bystringUser who created this flag
items[].updated_atstringISO 8601 timestamp when this resource was last updated
format: date-time
items[].updated_bystringUser who last updated this flag
items[].archived_atstring | nullISO 8601 timestamp when this flag was archived
format: date-time
next_cursorstring | nullOpaque cursor to fetch the next page; null/absent if this is the last page
totalintegerTotal number of items across all pages
≥ 0
flagsobjectMap of flag key to evaluated boolean value for the caller's context (flags.get_all only)

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/flags/list \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.4flags.get

GET /v1/flags/get/{key}

获取功能开关定义

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键

Returns

Flag
NameTypeDescription
keystringUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
descriptionstringFree-text description of this resource
5–500 chars
type"bool" | "string" | "number" | "json"Type discriminator for this resource
default_valueanyDefault value when no rules match
enabledbooleanWhether this feature or configuration is enabled
default: true
rulesobject[]Targeting rules for the flag
rolloutobject | nullRollout configuration for gradual delivery
tagsobject | nullTags for categorization and filtering
versionintegerOptimistic-lock counter.
≥ 1
created_atstringISO 8601 timestamp when this resource was created
format: date-time
created_bystringUser who created this flag
updated_atstringISO 8601 timestamp when this resource was last updated
format: date-time
updated_bystringUser who last updated this flag
archived_atstring | nullISO 8601 timestamp when this flag was archived
format: date-time

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/flags/get/KEY \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.5flags.get_value

GET /v1/flags/get_value/{key}

在上下文下求值单个功能开关

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键
user_idstringOptional求值上下文中的用户 ID
contextRecord<string, unknown>Optional求值上下文属性
defaultunknownOptional求值失败时的兜底默认值

Returns

FlagValue
NameTypeDescription
valueanyEvaluated flag value for the supplied user/context (type matches flag.type).
variantobject | nullWinning variant when a multi-variant rollout was applied; null otherwise.
variant.valueanyVariant value; type must match flag.type.
variant.weightinteger0..100; sum of weights must be <= rollout.percentage.
0–100
keystringFlag key that was evaluated (flags.is_enabled only).
enabledbooleanBoolean-coerced evaluation result, same value as `value` (flags.is_enabled only).

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/flags/get_value/KEY \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.6flags.get_all

GET /v1/flags/get_all

在上下文下批量求值所有开关

Parameters

NameTypeRequiredDescription
user_idstringOptional求值上下文中的用户 ID
contextRecord<string, unknown>Optional求值上下文属性

Returns

FlagEvaluationMap
NameTypeDescription
itemsobject[]Array of result items in this page
items[].keystringUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
items[].descriptionstringFree-text description of this resource
5–500 chars
items[].type"bool" | "string" | "number" | "json"Type discriminator for this resource
items[].default_valueanyDefault value when no rules match
items[].enabledbooleanWhether this feature or configuration is enabled
default: true
items[].rulesobject[]Targeting rules for the flag
items[].rolloutobject | nullRollout configuration for gradual delivery
items[].tagsobject | nullTags for categorization and filtering
items[].versionintegerOptimistic-lock counter.
≥ 1
items[].created_atstringISO 8601 timestamp when this resource was created
format: date-time
items[].created_bystringUser who created this flag
items[].updated_atstringISO 8601 timestamp when this resource was last updated
format: date-time
items[].updated_bystringUser who last updated this flag
items[].archived_atstring | nullISO 8601 timestamp when this flag was archived
format: date-time
next_cursorstring | nullOpaque cursor to fetch the next page; null/absent if this is the last page
totalintegerTotal number of items across all pages
≥ 0
flagsobjectMap of flag key to evaluated boolean value for the caller's context (flags.get_all only)

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X GET https://api.infrai.cc/v1/flags/get_all \
  -H "Authorization: Bearer $INFRAI_API_KEY"

2.7flags.toggle

POST /v1/flags/toggle/{key}

启用或禁用功能开关

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键
pattern: ^[a-z0-9_.-]{1,128}$
enabledboolean
Required
目标启用状态
versionnumber
Required
版本号,用于乐观并发控制
≥ 1

Returns

Flag
NameTypeDescription
keystringUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
descriptionstringFree-text description of this resource
5–500 chars
type"bool" | "string" | "number" | "json"Type discriminator for this resource
default_valueanyDefault value when no rules match
enabledbooleanWhether this feature or configuration is enabled
default: true
rulesobject[]Targeting rules for the flag
rolloutobject | nullRollout configuration for gradual delivery
tagsobject | nullTags for categorization and filtering
versionintegerOptimistic-lock counter.
≥ 1
created_atstringISO 8601 timestamp when this resource was created
format: date-time
created_bystringUser who created this flag
updated_atstringISO 8601 timestamp when this resource was last updated
format: date-time
updated_bystringUser who last updated this flag
archived_atstring | nullISO 8601 timestamp when this flag was archived
format: date-time

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/flags/toggle/KEY \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "sample", "enabled": true, "version": 1}'

2.8flags.rollout

POST /v1/flags/rollout/{key}

配置功能开关的灰度发布

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键
pattern: ^[a-z0-9_.-]{1,128}$
percentagenumber
Required
灰度百分比(0-100)
0–100
saltstring
Required
哈希分桶用的盐值
sticky_unit"user_id" | "session_id" | "device_id"
Required
黏滞维度:user_id/session_id/device_id
default: "user_id"
versionnumber
Required
版本号,用于乐观并发控制
≥ 1
variantsVariant[]Optional多变体配置列表

Returns

Flag
NameTypeDescription
keystringUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
descriptionstringFree-text description of this resource
5–500 chars
type"bool" | "string" | "number" | "json"Type discriminator for this resource
default_valueanyDefault value when no rules match
enabledbooleanWhether this feature or configuration is enabled
default: true
rulesobject[]Targeting rules for the flag
rolloutobject | nullRollout configuration for gradual delivery
tagsobject | nullTags for categorization and filtering
versionintegerOptimistic-lock counter.
≥ 1
created_atstringISO 8601 timestamp when this resource was created
format: date-time
created_bystringUser who created this flag
updated_atstringISO 8601 timestamp when this resource was last updated
format: date-time
updated_bystringUser who last updated this flag
archived_atstring | nullISO 8601 timestamp when this flag was archived
format: date-time

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X POST https://api.infrai.cc/v1/flags/rollout/KEY \
  -H "Authorization: Bearer $INFRAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"key": "sample", "percentage": 1, "salt": "sample", "sticky_unit": "user_id", "version": 1}'

2.9flags.delete

DELETE /v1/flags/delete/{key}

删除功能开关

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键
pattern: ^[a-z0-9_.-]{1,128}$

Returns

DeleteResult
NameTypeDescription
idstringThe flag key that was targeted for deletion
deletedbooleanWhether the flag existed and was deleted; false is an idempotent no-op when the flag was already absent

Example

一次性前置(每个范例都假定已完成):

bash
# No SDK to install — every call is a plain HTTPS request.
# Get a project key by signing in at https://infrai.cc/login (Google/GitHub gives
# you $2 free credit; email sign-in starts at $0). On 402 INSUFFICIENT_CREDIT, add
# funds at https://infrai.cc/billing (or POST /v1/account/topup and open the
# returned checkout_url).
export INFRAI_API_KEY="ifr_..."
bash
curl -X DELETE https://api.infrai.cc/v1/flags/delete/KEY \
  -H "Authorization: Bearer $INFRAI_API_KEY"

3. All capabilities

Every routed capability in this module — the complete public REST contract. The methods above are the guided walkthrough; this index is the full reference.

flags.deleteDELETE /v1/flags/delete/{key}

Delete a feature flag permanently.

Parameters (1)
NameTypeRequiredDescription
keystringRequiredUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
flags.getGET /v1/flags/get/{key}

Retrieve the full definition of a feature flag.

Parameters (1)
NameTypeRequiredDescription
keystringRequiredPath parameter.
flags.get_allGET /v1/flags/get_all

Evaluate all feature flags at once for a given evaluation context.

No request parameters.

flags.get_valueGET /v1/flags/get_value/{key}

Evaluate a single feature flag's value for a given evaluation context.

Parameters (1)
NameTypeRequiredDescription
keystringRequiredPath parameter.
flags.is_enabledGET /v1/flags/is_enabled/{key}

Check whether a feature flag is enabled for the current evaluation context.

Parameters (1)
NameTypeRequiredDescription
keystringRequiredPath parameter.
flags.listGET /v1/flags/list

List feature flags with pagination, optionally including archived ones.

No request parameters.

flags.rolloutPOST /v1/flags/rollout/{key}

Configure a percentage-based gradual rollout for a feature flag.

Parameters (6)
NameTypeRequiredDescription
keystringRequiredUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
percentageintegerRequiredRollout percentage (0-100)
0–100
saltstringRequiredConsistent-hash salt; rotate to reshuffle bucket assignments.
sticky_unit"user_id" | "session_id" | "device_id"RequiredSticky unit for consistent rollout assignment
default: "user_id"
variantsobject[] | nullOptionalVariant definitions for the flag
versionintegerRequiredCurrent version; mismatch triggers FLAG_VERSION_CONFLICT.
≥ 1
flags.setPOST /v1/flags/set

Create or update a feature-flag definition.

Parameters (9)
NameTypeRequiredDescription
keystringRequiredUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
descriptionstring | nullOptionalRequired on create (FLAG_DESCRIPTION_TOO_SHORT if <5 chars).
5–500 chars
type"bool" | "string" | "number" | "json" | nullOptionalFlag value type (enums/flag_type.yaml). Defaults to bool on create.
default_valueanyOptionalValue returned when no rule matches; type must match `type` (FLAG_TYPE_MISMATCH).
rulesobject[] | nullOptionalTargeting rules for the flag
rolloutobject | nullOptionalRollout configuration for gradual delivery
tagsobject | nullOptionalTags for categorization and filtering
enabledboolean | nullOptionalWhether this feature or configuration is enabled
default: true
versioninteger | nullOptionalRequired for update (optimistic lock). Omit for create.
≥ 1
flags.togglePOST /v1/flags/toggle/{key}

Enable or disable a feature flag with optimistic version checking.

Parameters (3)
NameTypeRequiredDescription
keystringRequiredUnique identifier key for this resource
pattern: ^[a-z0-9_.-]{1,128}$
enabledbooleanRequiredWhether this feature or configuration is enabled
versionintegerRequiredCurrent version; mismatch triggers FLAG_VERSION_CONFLICT.
≥ 1

4. End-to-end example

A production-style walkthrough of this module: configure once, then run the flow. It exercises most of the module's APIs.

A copy-paste-runnable single-file Python program (stdlib only, no SDK): set your INFRAI_API_KEY, run it, and walk this module's core flow with REAL billed calls — later steps reuse real fields returned by earlier ones. The 12-line helper is the entire integration.

python
#!/usr/bin/env python3
"""Infrai · flags — runnable real-app example (single file, zero deps).

Copy this file, set your key, run it: every step is a REAL call to
api.infrai.cc, billed at the real (tiny) per-call price, printing the
live JSON response. Get a key at https://infrai.cc/login (Google/
GitHub sign-in grants $2 free credit); add funds at
https://infrai.cc/billing. No SDK — the 12-line helper below is the
entire integration."""
import json
import os
from urllib import error, request

KEY = os.environ.get("INFRAI_API_KEY") or "ifr_..."  # <- your key
BASE = "https://api.infrai.cc"


# Same raw HTTPS POST/GET as every per-method example on this page —
# wrapped once for reuse. There is nothing else to it: no SDK.
def infrai(method, path, body=None):
    req = request.Request(
        BASE + path, method=method,
        data=json.dumps(body).encode() if body is not None else None,
        headers={"Authorization": f"Bearer {KEY}",
                 "Content-Type": "application/json"})
    try:
        with request.urlopen(req, timeout=60) as r:
            return json.loads(r.read())
    except error.HTTPError as e:
        return json.loads(e.read())


def show(label, resp):
    print(f"\n== {label} ==")
    print(json.dumps(resp, indent=2, ensure_ascii=False))
    return resp


# 1) flags.set — POST /v1/flags/set · Create or update a feature-flag definition.
r1 = show("flags.set", infrai("POST", "/v1/flags/set", {"key":"new_checkout","type":"bool","default_value":False,"description":"new checkout UX"}))

# 2) flags.list — GET /v1/flags/list · List feature flags with pagination, optionally including archived ones.
r2 = show("flags.list", infrai("GET", "/v1/flags/list"))