> ## Documentation Index
> Fetch the complete documentation index at: https://docs.greenflash.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Segment

> Create a custom user segment based on filter rules. Available on all plans, limited by your plan's `maxCustomSegments` quota.

After creation, segment membership is computed asynchronously. The segment will be available immediately but member counts may take a few moments to populate.



## OpenAPI

````yaml https://www.greenflash.ai/api/openapi post /segments
openapi: 3.1.0
info:
  title: Greenflash API Reference
  version: 1.0.0
  description: >-
    Greenflash endpoints for capturing interactions, managing prompts, and
    identifying users.
servers:
  - url: https://www.greenflash.ai/api/v1
    description: Greenflash API v1
security: []
tags:
  - name: Interactions
    description: Capture interactions between users and AI
  - name: Business Events
    description: Capture business events
  - name: Analytics
    description: Understand chat and agentic interactions analyses
  - name: Inbox
    description: Review flagged conversations
  - name: Segments
    description: Manage user segments
  - name: Prompts
    description: Manage prompts
  - name: Chat
    description: Stream chat and agentic conversations
  - name: Models
    description: Manage AI models
  - name: Products
    description: Manage products
  - name: Users
    description: Manage users
  - name: Organizations
    description: Manage organizations
paths:
  /segments:
    post:
      tags:
        - Segments
      summary: Create Segment
      description: >-
        Create a custom user segment based on filter rules. Available on all
        plans, limited by your plan's `maxCustomSegments` quota.


        After creation, segment membership is computed asynchronously. The
        segment will be available immediately but member counts may take a few
        moments to populate.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSegmentRequest'
            example:
              name: High-Intent Enterprise Users
              description: Users with high commercial intent from the enterprise plan
              icon: Users
              filters:
                rules:
                  - type: analysis
                    field: commercialIntent
                    operator: gte
                    value: 0.6
                  - type: property
                    key: plan
                    operator: eq
                    value: enterprise
      responses:
        '201':
          description: Segment created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateSegmentResponse'
              example:
                id: 423e4567-e89b-12d3-a456-426614174003
                name: High-Intent Enterprise Users
                type: custom
                description: Users with high commercial intent from the enterprise plan
                icon: Users
                filters:
                  rules:
                    - type: analysis
                      field: commercialIntent
                      operator: gte
                      value: 0.6
                    - type: property
                      key: plan
                      operator: eq
                      value: enterprise
                createdAt: '2026-03-25T14:30:00.000Z'
                updatedAt: '2026-03-25T14:30:00.000Z'
        '400':
          description: Bad request - validation error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: Whether the API call was successful (false for errors).
                  error:
                    type: string
                    description: Error message describing what went wrong.
                description: Error response for create segment operations.
              example:
                success: false
                error: >-
                  Validation error: filters.rules must contain at least 1
                  element(s)
        '403':
          description: Segment limit reached
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: Whether the API call was successful (false for errors).
                  error:
                    type: string
                    description: Error message describing what went wrong.
                description: Error response for create segment operations.
              example:
                success: false
                error: >-
                  Your plan allows up to 5 custom segments (currently using 5).
                  Please upgrade to create more, or contact
                  support@greenflash.ai.
        '500':
          description: Server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    description: Whether the API call was successful (false for errors).
                  error:
                    type: string
                    description: Error message describing what went wrong.
                description: Error response for create segment operations.
      security:
        - bearerAuth: []
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Greenflash from 'greenflash';

            const client = new Greenflash({
              apiKey: process.env['GREENFLASH_API_KEY'], // This is the default and can be omitted
            });

            const createSegmentResponse = await client.segments.create({
              filters: {
                rules: [
                  {
                    type: 'analysis',
                    field: 'commercialIntent',
                    operator: 'gte',
                    value: 0.6,
                  },
                  {
                    type: 'property',
                    key: 'plan',
                    operator: 'eq',
                    value: 'enterprise',
                  },
                ],
              },
              description: 'Users with high commercial intent from the enterprise plan',
              icon: 'Users',
              name: 'High-Intent Enterprise Users',
            });

            console.log(createSegmentResponse.id);
        - lang: Python
          source: |-
            import os
            from greenflash import Greenflash

            client = Greenflash(
                api_key=os.environ.get("GREENFLASH_API_KEY"),  # This is the default and can be omitted
            )
            create_segment_response = client.segments.create(
                filters={
                    "rules": [{
                        "type": "analysis",
                        "field": "commercialIntent",
                        "operator": "gte",
                        "value": 0.6,
                    }, {
                        "type": "property",
                        "key": "plan",
                        "operator": "eq",
                        "value": "enterprise",
                    }]
                },
                description="Users with high commercial intent from the enterprise plan",
                icon="Users",
                name="High-Intent Enterprise Users",
            )
            print(create_segment_response.id)
components:
  schemas:
    CreateSegmentRequest:
      type: object
      properties:
        name:
          type: string
          maxLength: 255
          description: Segment name. If omitted, an auto-generated name will be assigned.
        description:
          type: string
          description: A description of the segment purpose.
        icon:
          type: string
          maxLength: 50
          description: Icon identifier for the segment (e.g. "Users", "Tag").
        filters:
          type: object
          properties:
            rules:
              type: array
              items:
                oneOf:
                  - type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - analysis
                        description: Rule based on conversation analysis metrics.
                      field:
                        type: string
                        enum:
                          - sentiment
                          - frustration
                          - struggle
                          - commercialIntent
                          - cqi
                          - rating
                        description: The analysis metric to filter on.
                      operator:
                        type: string
                        enum:
                          - gt
                          - lt
                          - eq
                          - gte
                          - lte
                        description: Comparison operator.
                      value:
                        type: number
                        description: >-
                          Threshold value for the metric (0-1 scale for most
                          metrics).
                    required:
                      - type
                      - field
                      - operator
                      - value
                  - type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - analysis_flag
                        description: Rule based on detected flags.
                      field:
                        type: string
                        enum:
                          - jailbreakDetected
                          - hallucinationDetected
                          - userToxicityDetected
                          - modelToxicityDetected
                          - userBiasDetected
                          - modelBiasDetected
                          - missingCapabilityDetected
                        description: The flag to filter on.
                      value:
                        type: boolean
                        description: Whether the flag should be true or false.
                    required:
                      - type
                      - field
                      - value
                  - type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - property
                        description: Rule based on user properties.
                      key:
                        type: string
                        pattern: ^[\w.-]+$
                        description: >-
                          The property key (alphanumeric, dots, hyphens,
                          underscores).
                      operator:
                        type: string
                        enum:
                          - eq
                          - neq
                          - contains
                          - gt
                          - lt
                        description: Comparison operator.
                      value:
                        anyOf:
                          - type: string
                          - type: number
                          - type: boolean
                        description: Value to compare against.
                    required:
                      - type
                      - key
                      - operator
                      - value
                  - type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - conversation_property
                        description: Rule based on conversation-level properties.
                      key:
                        type: string
                        pattern: ^[\w.-]+$
                        description: The conversation property key.
                      operator:
                        type: string
                        enum:
                          - eq
                          - neq
                          - contains
                          - gt
                          - lt
                        description: Comparison operator.
                      value:
                        anyOf:
                          - type: string
                          - type: number
                          - type: boolean
                        description: Value to compare against.
                    required:
                      - type
                      - key
                      - operator
                      - value
                  - type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - conversation_count
                        description: Rule based on number of conversations.
                      operator:
                        type: string
                        enum:
                          - gte
                          - lte
                        description: Comparison operator.
                      value:
                        type: integer
                        minimum: 0
                        description: Conversation count threshold.
                    required:
                      - type
                      - operator
                      - value
                  - type: object
                    properties:
                      type:
                        type: string
                        enum:
                          - last_seen
                        description: Rule based on when the user was last active.
                      operator:
                        type: string
                        enum:
                          - within
                          - before
                        description: Time comparison operator.
                      value:
                        type: string
                        pattern: ^\d+(d|h|m)$
                        description: Time duration (e.g. "7d", "24h", "30m").
                    required:
                      - type
                      - operator
                      - value
                description: A filter rule defining segment membership criteria.
              minItems: 1
              description: Array of filter rules. At least one rule is required.
            productIds:
              type: array
              items:
                type: string
                format: uuid
              description: Scope the segment to specific product IDs.
            dateRange:
              type: object
              properties:
                preset:
                  type: string
                  enum:
                    - 7d
                    - 30d
                    - 90d
                    - all
                  description: Preset date range.
                from:
                  type: string
                  description: Start date (ISO 8601).
                to:
                  type: string
                  description: End date (ISO 8601).
              description: Optional date range filter.
          required:
            - rules
          description: Filter configuration defining segment membership.
      required:
        - filters
    CreateSegmentResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: The created segment ID.
        name:
          type: string
          description: The segment name.
        type:
          type: string
          enum:
            - custom
          description: Always "custom" for API-created segments.
        description:
          type:
            - string
            - 'null'
          description: Segment description.
        icon:
          type:
            - string
            - 'null'
          description: Icon identifier.
        filters:
          type: object
          additionalProperties: {}
          description: The filter configuration.
        createdAt:
          type: string
          format: date-time
          description: When the segment was created.
        updatedAt:
          type: string
          format: date-time
          description: When the segment was last updated.
      required:
        - id
        - name
        - type
        - description
        - icon
        - filters
        - createdAt
        - updatedAt
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````