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

# Create a detector

> Create a detector in a project the authenticated user can write to.

Requires MEMBER role or higher in the project's workspace (the write
service decides). Idempotent on the detector name within the project.

Args:
    request (Request): Incoming request (rate-limit plumbing).
    response (Response): Outgoing response (rate-limit plumbing).
    auth (AccountStampedAuth): Account-scope user auth (session token or
        CLI access JWT); its resolved ``user_id`` becomes the actor.
    payload (CreateDetectorRequest): The detector to create.
    _live (None): Write-path liveness gate (blocks a revoked JWT session).

Returns:
    CreateDetectorResponse: The created (or matched) detector.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/public/detectors
openapi: 3.1.0
info:
  title: TraceRoot Public API
  version: 0.1.0
servers:
  - description: TraceRoot Cloud
    url: https://app.traceroot.ai
  - description: Self-hosted
    url: '{baseUrl}'
    variables:
      baseUrl:
        default: http://localhost:8000
        description: Your TraceRoot backend URL
security: []
paths:
  /api/v1/public/detectors:
    post:
      tags:
        - Detectors
      summary: Create a detector
      description: |-
        Create a detector in a project the authenticated user can write to.

        Requires MEMBER role or higher in the project's workspace (the write
        service decides). Idempotent on the detector name within the project.

        Args:
            request (Request): Incoming request (rate-limit plumbing).
            response (Response): Outgoing response (rate-limit plumbing).
            auth (AccountStampedAuth): Account-scope user auth (session token or
                CLI access JWT); its resolved ``user_id`` becomes the actor.
            payload (CreateDetectorRequest): The detector to create.
            _live (None): Write-path liveness gate (blocks a revoked JWT session).

        Returns:
            CreateDetectorResponse: The created (or matched) detector.
      operationId: create_detector
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateDetectorRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateDetectorResponse'
          description: Successful Response
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Invalid request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Authentication failed or session revoked
        '403':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Insufficient role or wrong credential kind
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Not found
        '422':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
          description: Validation Error
        '503':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
          description: Write service unavailable
      security:
        - BearerAuth: []
components:
  schemas:
    CreateDetectorRequest:
      description: Body for creating a detector in a project.
      properties:
        detection_model:
          anyOf:
            - type: string
            - type: 'null'
          title: Detection Model
        detection_provider:
          anyOf:
            - type: string
            - type: 'null'
          title: Detection Provider
        detection_source:
          anyOf:
            - type: string
            - type: 'null'
          title: Detection Source
        enable_rca:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Enable Rca
        enabled:
          anyOf:
            - type: boolean
            - type: 'null'
          title: Enabled
        name:
          title: Name
          type: string
        output_schema:
          anyOf:
            - items: {}
              type: array
            - type: 'null'
          title: Output Schema
        project_id:
          title: Project Id
          type: string
        prompt:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Detector instructions. Omit to adopt the canonical instructions of a
            standard template; required for any other template.
          title: Prompt
        sample_rate:
          anyOf:
            - type: integer
            - type: 'null'
          title: Sample Rate
        template:
          title: Template
          type: string
        trigger_conditions:
          anyOf:
            - items: {}
              type: array
            - type: 'null'
          description: >-
            Conditions gating WHICH completed traces the detector evaluates;
            omit or pass [] to evaluate every completed trace. Each condition is
            {field, op, value} (metadata also takes key): model_name/environment
            take =, !=; cost/total_tokens/duration_ms/errors take >, >=, <, <=,
            =; metadata takes =, contains. A condition is a deterministic
            pre-filter, not the flag decision - the prompt still judges every
            trace that passes.
          title: Trigger Conditions
      required:
        - project_id
        - name
        - template
      title: CreateDetectorRequest
      type: object
    CreateDetectorResponse:
      description: The created (or idempotently matched) detector.
      properties:
        created:
          title: Created
          type: boolean
        enabled:
          title: Enabled
          type: boolean
        id:
          title: Id
          type: string
        name:
          title: Name
          type: string
        project_id:
          title: Project Id
          type: string
        sample_rate:
          title: Sample Rate
          type: integer
      required:
        - id
        - name
        - project_id
        - enabled
        - sample_rate
        - created
      title: CreateDetectorResponse
      type: object
    ErrorResponse:
      description: >-
        The canonical public error envelope (matches the gateway's normalized
        shape).
      properties:
        detail:
          title: Detail
          type: string
      required:
        - detail
      title: ErrorResponse
      type: object
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          title: Detail
          type: array
      title: HTTPValidationError
      type: object
    ValidationError:
      properties:
        ctx:
          title: Context
          type: object
        input:
          title: Input
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          title: Location
          type: array
        msg:
          title: Message
          type: string
        type:
          title: Error Type
          type: string
      required:
        - loc
        - msg
        - type
      title: ValidationError
      type: object
  securitySchemes:
    BearerAuth:
      scheme: bearer
      type: http

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.