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

# Create an environment

> Creates an environment in the scoped project. Rejected for projects managed by environments.yaml.



## OpenAPI

````yaml /api-reference/openapi.generated.json post /api/environments
openapi: 3.1.0
info:
  title: Empirical API
  version: 1.0.0
  description: Programmatic access to Empirical test runs, snoozes, and more.
  contact:
    name: Empirical
    url: https://empirical.run
servers:
  - url: https://api.empirical.run
security:
  - Bearer: []
tags:
  - name: Analytics
    description: Aggregated test-run, test-count and test-case analytics for a project.
  - name: Analytics (Deprecated)
    description: >-
      Legacy analytics endpoints retained for backwards compatibility; prefer
      the v2 equivalents.
  - name: Environments
    description: >-
      Named deployment targets (slug + Playwright project filters) a project's
      tests run against.
  - name: Snoozes
    description: Temporarily suppress known test failures for specific Playwright tests.
  - name: Telemetry
    description: Product telemetry derived from analytics events, scoped to a project.
  - name: Test Cases
    description: >-
      Browse the Playwright test cases synced from a project's repository and
      manage their tags.
paths:
  /api/environments:
    post:
      tags:
        - Environments
      summary: Create an environment
      description: >-
        Creates an environment in the scoped project. Rejected for projects
        managed by environments.yaml.
      operationId: createEnvironment
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateEnvironmentRequest'
      responses:
        '200':
          description: The created environment.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EnvironmentResponse'
        '400':
          description: Invalid request, or the slug already exists.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '403':
          description: Project is managed by environments.yaml.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Project not found or not accessible.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    CreateEnvironmentRequest:
      type: object
      properties:
        name:
          type: string
          minLength: 1
          description: Display name.
        slug:
          type: string
          minLength: 1
          description: URL-friendly identifier; unique within the project.
        playwright_projects_match:
          type: array
          items:
            type: string
          description: Playwright project names to include. Items must not start with '!'.
        playwright_projects_ignore:
          type: array
          items:
            type: string
          description: Playwright project names to exclude.
        scheduled_trigger:
          type: string
          nullable: true
          description: Cron expression for scheduled triggers, or null.
      required:
        - name
        - slug
    EnvironmentResponse:
      type: object
      properties:
        data:
          type: object
          properties:
            environment:
              $ref: '#/components/schemas/Environment'
          required:
            - environment
          description: Response payload.
      required:
        - data
    ErrorResponse:
      type: object
      properties:
        data:
          nullable: true
          description: Always null for error responses.
        error:
          type: object
          properties:
            message:
              type: string
              description: Human-readable error message.
          required:
            - message
          description: Error details.
      required:
        - data
        - error
    Environment:
      type: object
      properties:
        id:
          type: number
          description: Unique identifier.
        project_id:
          type: number
          description: Project identifier.
        slug:
          type: string
          description: URL-friendly identifier.
        name:
          type: string
          description: Display name.
        playwright_projects_match:
          type: array
          items:
            type: string
          description: Playwright project names to match.
        playwright_projects_ignore:
          type: array
          items:
            type: string
          description: Playwright project names to ignore.
        is_disabled:
          type: boolean
          nullable: true
          description: Whether the environment is disabled.
        env_files:
          type: array
          items:
            type: string
          description: Environment file paths.
        scheduled_trigger:
          type: string
          nullable: true
          description: Cron expression for scheduled triggers.
        created_at:
          type: string
          nullable: true
          description: ISO 8601 timestamp.
        updated_at:
          type: string
          nullable: true
          description: ISO 8601 timestamp.
      required:
        - id
        - project_id
        - slug
        - name
        - playwright_projects_match
        - playwright_projects_ignore
        - is_disabled
        - env_files
        - scheduled_trigger
        - created_at
        - updated_at
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````