---
title: "Create a detector"
method: POST
path: "/api/v1/public/detectors"
tags: ["Detectors"]
---

# Create a detector

`POST /api/v1/public/detectors`

## Request

- Base URL: `https://app.traceroot.ai`
- URL: `https://app.traceroot.ai/api/v1/public/detectors`
- Auth: HTTP bearer

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.

## Request body

- CreateDetectorRequest: Body for creating a detector in a project.
  - `detection_model` string, nullable
  - `detection_provider` string, nullable
  - `detection_source` string, nullable
  - `enable_rca` boolean, nullable
  - `enabled` boolean, nullable
  - `name` string, required
  - `output_schema` unknown[], nullable
    - unknown
  - `project_id` string, required
  - `prompt` string, nullable: Detector instructions. Omit to adopt the canonical instructions of a standard template; required for any other template.
  - `sample_rate` integer, nullable
  - `template` string, required
  - `trigger_conditions` unknown[], nullable: 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.
    - unknown

## Response `200`

Successful Response

- CreateDetectorResponse: The created (or idempotently matched) detector.
  - `created` boolean, required
  - `enabled` boolean, required
  - `id` string, required
  - `name` string, required
  - `project_id` string, required
  - `sample_rate` integer, required

## Other responses

- `400`: Invalid request
- `401`: Authentication failed or session revoked
- `403`: Insufficient role or wrong credential kind
- `404`: Not found
- `422`: Validation Error
- `503`: Write service unavailable

---

[API](https://skmtc.dev/traceroot/apis/traceroot-public-api.md) - [All operations](https://skmtc.dev/traceroot/apis/traceroot-public-api/llms.txt) - [OpenAPI document](https://skmtc.dev/traceroot/apis/traceroot-public-api/revisions/ce6aef96c0d6?raw)
