---
title: "POST /projects/{project_id}/flags"
method: POST
path: "/projects/{project_id}/flags"
tags: ["Feature Flags"]
---

# POST /projects/{project_id}/flags

`POST /projects/{project_id}/flags`

## Request

- Base URL: `/api` (relative, and the document was published on a file host, not at the API’s origin)
- URL: `/api/projects/{project_id}/flags`
- Auth: HTTP bearer

## Path parameters

- `project_id` integer, required

## Request body

- CreateFlagRequest
  - `client_visible` boolean: Whether the flag may be exposed on the unauthenticated same-origin evaluation endpoint. Defaults to `false`: flags are server-only unless explicitly opted in, because targeting rules can encode business logic.
  - `default_value` unknown, required
  - `description` string, nullable
  - `exposure_sample_rate` number, double: Share of subjects (`0..=1`) whose browser records a `flag_exposure` event when it reads the flag. Defaults to 0: exposure is opt-in.
  - `key` string, required: Stable key used in application code. Immutable after create.
  - `value_type` 'bool' | 'string' | 'number' | 'json', required: Fixed at create: retyping would invalidate every stored value and every call site.
  - `variants` FlagVariant[]: Named values targeting rules may serve. Each must match `value_type`.
    - `description` string, nullable
    - `key` string, required: `[a-z0-9][a-z0-9._-]*`, unique within the flag.
    - `value` unknown, required

## Response `201`

Flag created

- FlagResponse
  - `archived_at` string, nullable
  - `client_visible` boolean, required
  - `created_at` string, required
  - `default_value` unknown, required
  - `description` string, nullable
  - `environments` FlagEnvironmentResponse[], required: Per-environment overrides. Empty means the flag inherits its default everywhere.
    - `enabled` boolean, required
    - `environment_id` integer, required
    - `rules` FlagRule[], required: Ordered targeting rules; first match wins.
      - `conditions` RuleCondition[]: All must hold. Empty means every subject.
        - `attribute` string, required: Context attribute name, e.g. `plan`, `country`, `email`.
        - `operator` 'eq' | 'neq' | 'in' | 'not_in' | 'contains' | 'not_contains' | 'matches' | 'gt' | 'gte' | 'lt' | 'lte' | 'exists' | 'not_exists', required: Comparison applied by one rule condition.
        - `value` union: The right-hand side of a condition: one value, or a list for `in`/`not_in`.
          - AttributeValue[]
            - union: A targeting attribute: what the caller (or the server, implicitly) knows about the subject.
              - …
          - union: A targeting attribute: what the caller (or the server, implicitly) knows about the subject.
            - boolean
            - number, double
            - string
      - `description` string, nullable: Free text shown in the console, e.g. "Beta customers".
      - `rollout_percentage` number, double, nullable: Share of matching subjects the rule applies to, `0..=100`. `None` means all of them. Ramping it up never removes anyone already included.
      - `serve` union, required: What a matching rule serves.
        - object: A literal value of the flag's type.
          - `kind` 'value', required
          - `value` unknown, required
        - object: One declared variant.
          - `kind` 'variant', required
          - `variant` string, required
        - object: Subjects split across declared variants by weight, stably per subject.
          - `kind` 'split', required
          - `split` VariantWeight[], required
            - `variant` string, required: A variant key declared on the flag.
            - `weight` integer, required: Share of the rule's subjects, in whole percent. A split's weights sum to 100.
    - `rules_valid` boolean, required: `false` when the stored rules could not be decoded. The flag then serves its default with reason `ERROR` until they are replaced.
    - `updated_at` string, required: Send back as `expected_updated_at` when replacing the rules.
    - `value` unknown
  - `exposure_sample_rate` number, double, required: Share of subjects whose browser records exposure events. 0 = off.
  - `id` integer, required
  - `key` string, required
  - `last_evaluated_at` string, nullable: When an app last actually evaluated this flag. `None` means never seen, which is a real answer rather than missing data.
  - `updated_at` string, required: Send back as `expected_updated_at` to make an update conditional.
  - `value_type` string, required
  - `variants` FlagVariant[], required: Named values targeting rules may serve.
    - `description` string, nullable
    - `key` string, required: `[a-z0-9][a-z0-9._-]*`, unique within the flag.
    - `value` unknown, required

## Other responses

- `400`: Validation error
- `401`: Unauthorized
- `403`: Insufficient permissions
- `409`: Flag key already exists
- `500`: Internal server error

## Changes

- **2026-11-20** `68c970dc603c`: 7 info
  - added the new optional request property `exposure_sample_rate`
  - added the new optional request property `variants`
  - added the required property `environments/items/rules` to the response with the `201` status
  - added the required property `environments/items/rules_valid` to the response with the `201` status
  - …3 more
- **2026-08-04** `c647b6ab1d2c`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/gotempsh/apis/temps/changes/projects/:project_id/flags/post.md)

---

[API](https://skmtc.dev/gotempsh/apis/temps.md) - [All operations](https://skmtc.dev/gotempsh/apis/temps/llms.txt) - [OpenAPI document](https://skmtc.dev/gotempsh/apis/temps/revisions/3b040526eb43?raw)
