Skip to content

Feature Flags

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

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"

Methods

flags.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 }

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"

flags.set

POST /v1/flags/set

创建或更新功能开关定义

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键
descriptionstringOptional功能开关描述
type'bool' | 'string' | 'number' | 'json'Optional取值类型:bool/string/number/json
default_valueunknownOptional默认取值
rulesFlagRule[]Optional定向规则列表
rolloutRolloutConfigOptional灰度发布配置
tagsRecord<string, string>Optional键值标签
enabledbooleanOptional是否启用
versionnumberOptional版本号,用于乐观并发控制

Returns

Flag

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": "new_checkout", "type": "bool", "default_value": false, "description": "new checkout UX"}'

flags.list

GET /v1/flags/list

分页列出功能开关

Parameters

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

Returns

FlagList

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"

flags.get

GET /v1/flags/get/{key}

获取功能开关定义

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键

Returns

Flag

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"

flags.get_value

GET /v1/flags/get_value/{key}

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

Parameters

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

Returns

FlagValue

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"

flags.get_all

GET /v1/flags/get_all

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

Parameters

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

Returns

FlagEvaluationMap

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"

flags.toggle

POST /v1/flags/toggle/{key}

启用或禁用功能开关

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键
enabledboolean
Required
目标启用状态
versionnumber
Required
版本号,用于乐观并发控制

Returns

Flag

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": "...", "enabled": true, "version": 0}'

flags.rollout

POST /v1/flags/rollout/{key}

配置功能开关的灰度发布

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键
percentagenumber
Required
灰度百分比(0-100)
saltstring
Required
哈希分桶用的盐值
sticky_unit'user_id' | 'session_id' | 'device_id'
Required
黏滞维度:user_id/session_id/device_id
versionnumber
Required
版本号,用于乐观并发控制
variantsVariant[]Optional多变体配置列表

Returns

Flag

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": "new_checkout", "rollout": {"percentage": 25, "salt": "v1", "sticky_unit": "user_id"}}'

flags.delete

DELETE /v1/flags/delete/{key}

删除功能开关

Parameters

NameTypeRequiredDescription
keystring
Required
功能开关键

Returns

DeleteResult

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"

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.

CapabilityEndpointDescription
flags.deleteDELETE /v1/flags/delete/{key}Delete a feature flag permanently.
flags.getGET /v1/flags/get/{key}Retrieve the full definition of a feature flag.
flags.get_allGET /v1/flags/get_allEvaluate all feature flags at once for a given evaluation context.
flags.get_valueGET /v1/flags/get_value/{key}Evaluate a single feature flag's value for a given evaluation context.
flags.is_enabledGET /v1/flags/is_enabled/{key}Check whether a feature flag is enabled for the current evaluation context.
flags.listGET /v1/flags/listList feature flags with pagination, optionally including archived ones.
flags.rolloutPOST /v1/flags/rollout/{key}Configure a percentage-based gradual rollout for a feature flag.
flags.setPOST /v1/flags/setCreate or update a feature-flag definition.
flags.togglePOST /v1/flags/toggle/{key}Enable or disable a feature flag with optimistic version checking.

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"))