---
title: "Train model (Anomaly)"
method: POST
path: "/api/{projectId}/jobs/train/anomaly/{learnId}"
tags: ["Jobs"]
---

# Train model (Anomaly)

`POST /api/{projectId}/jobs/train/anomaly/{learnId}`

## Request

- Base URL: `https://studio.edgeimpulse.com/v1`
- URL: `https://studio.edgeimpulse.com/v1/api/{projectId}/jobs/train/anomaly/{learnId}`
- Auth: one of:
  - API key in header `x-api-key`
  - API key in cookie `jwt`
  - API key in header `x-jwt-token`
  - OAuth 2
    - Authorization code: `/v1/oauth/authorize`
    - Client credentials
    - Implicit: `/v1/oauth/authorize`
    - Password
    - Token URL: `/v1/oauth/token`
- TypeScript: <https://skmtc.dev/edgeimpulse/apis/edge-impulse-api/docs/api/:projectId/jobs/train/anomaly/:learnId/post.ts> (a function with typed inputs; its response is checked against the schema)

Take the output from a DSP block and train an anomaly detection model using K-means or GMM. Updates are streamed over the websocket API.

## Path parameters

- `projectId` integer, required
- `learnId` integer, required

## Request body

- StartTrainingRequestAnomaly
  - `axes` integer[], required: Which axes (indexes from DSP script) to include in the training set
  - `clusterCount` integer: Number of clusters for K-means, or number of components for GMM
  - `minimumConfidenceRating` number, required: DEPRECATED, use "thresholds" instead. Minimum confidence rating required before tagging as anomaly
  - `skipEmbeddingsAndMemory` boolean: If set, skips creating embeddings and measuring memory (used in tests)
  - `thresholds` BlockThreshold[]: List of configurable thresholds for this block.
    - `key` string, required: Identifier to reference the threshold. You'll need to refer to the threshold by this key when you set the threshold).
    - `description` string, required: User-friendly description of the threshold.
    - `helpText` string, required: Additional help text (shown in the UI under a "?" icon)
    - `suggestedValue` number: If the threshold has a suggested value, e.g. a max. absolute error for regression projects; or the min. anomaly score for visual anomaly detection, then this is the numeric value of that threshold.
    - `suggestedValueText` string: If the threshold has a suggested value, e.g. a max. absolute error for regression projects; or the min. anomaly score for visual anomaly detection, then this is the stringified value of that threshold.
    - `value` union, required: Current value of the threshold
      - number
      - string
    - `dropdownOptions` object[]: Optional list of options, will be shown in a dropdown.
      - `description` string, required: Full description of the value
      - `value` string, required: Value, maps back to "BlockThreshold#value"

## Response `200`

OK

- StartJobResponse
  - `success` boolean, required: Whether the operation succeeded
  - `error` string: Optional error description (set if 'success' was false)
  - `id` integer, required: Job identifier. Status updates will include this identifier.

---

[API](https://skmtc.dev/edgeimpulse/apis/edge-impulse-api.md) - [All operations](https://skmtc.dev/edgeimpulse/apis/edge-impulse-api/llms.txt) - [OpenAPI document](https://skmtc.dev/edgeimpulse/apis/edge-impulse-api/revisions/e2a976d38427?raw)
