# Machine Learning

Every registered machine learning instance operation, with source-derived inputs, outputs, access policy, and errors.

Source: https://docs.minds.sh/docs/api/instance/machine-learning



This reference covers **9 HTTP operations** registered by the Akasha daemon. Call these paths on your instance base URL. See [authentication](/docs/api/instance/authentication), [errors](/docs/api/instance/errors), and [coverage](/docs/api/instance/coverage) before integrating.

| Method | Path                      | Operation                                                |
| ------ | ------------------------- | -------------------------------------------------------- |
| `POST` | `/v1/ml/models/load`      | [Ml models load](#post-v1-ml-models-load)                |
| `POST` | `/v1/ml/models/unload`    | [Ml models unload](#post-v1-ml-models-unload)            |
| `GET`  | `/v1/ml/models`           | [Ml models list](#get-v1-ml-models)                      |
| `POST` | `/v1/ml/metrics`          | [Ml metrics](#post-v1-ml-metrics)                        |
| `POST` | `/v1/ml/embed`            | [Ml embed](#post-v1-ml-embed)                            |
| `POST` | `/v1/ml/generate`         | [Ml generate](#post-v1-ml-generate)                      |
| `POST` | `/v1/ml/tokenizers/load`  | [Ml tokenizer load](#post-v1-ml-tokenizers-load)         |
| `POST` | `/v1/ml/train/supervised` | [Ml train supervised http](#post-v1-ml-train-supervised) |
| `POST` | `/v1/ml/train/hrm`        | [Ml train hrm http](#post-v1-ml-train-hrm)               |

<a id="post-v1-ml-models-load" />

## POST `/v1/ml/models/load` [#post-v1mlmodelsload]

Ml models load

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request]

**Json** — `LoadModelRequest`

| Field        | Rust type        | Required on input         | Notes |
| ------------ | ---------------- | ------------------------- | ----- |
| `name`       | `String`         | Yes                       |       |
| `model_type` | `String`         | Yes                       |       |
| `framework`  | `String`         | Yes                       |       |
| `path`       | `Option<String>` | No; optional or defaulted |       |
| `data_b64`   | `Option<String>` | No; optional or defaulted |       |

```rust
struct LoadModelRequest {
    name: String,
    model_type: String,
    framework: String,
    path: Option<String>,
    data_b64: Option<String>,
}
```

### Response [#response]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"id": id})
```

```rust
serde_json::json!({"id": id})
```

### Errors and validation [#errors-and-validation]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_models_load(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Json(req): Json<LoadModelRequest>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        let mt = parse_model_type(&req.model_type)?;
        let fw = parse_framework(&req.framework)?;
        if let Some(path) = req.path {
            let id = db
                .ml_load_model(req.name, mt, fw, std::path::PathBuf::from(path))
                .await
                .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
            Ok(Json(serde_json::json!({"id": id})))
        } else if let Some(b64) = req.data_b64 {
            let data = base64::engine::general_purpose::STANDARD
                .decode(b64.as_bytes())
                .map_err(|e| DaemonError::InvalidRequest(format!("bad base64: {e}")))?;
            let id = db
                .ml_load_model_from_bytes(req.name, mt, fw, &data)
                .await
                .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
            Ok(Json(serde_json::json!({"id": id})))
        } else {
            Err(DaemonError::InvalidRequest(
                "either path or data_b64 required".into(),
            ))
        }
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:2650`. Registration: `akasha-daemon/src/main.rs:4556`.

<a id="post-v1-ml-models-unload" />

## POST `/v1/ml/models/unload` [#post-v1mlmodelsunload]

Ml models unload

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-1]

**Json** — `UnloadModelRequest`

| Field | Rust type | Required on input | Notes |
| ----- | --------- | ----------------- | ----- |
| `id`  | `String`  | Yes               |       |

```rust
struct UnloadModelRequest {
    id: String,
}
```

### Response [#response-1]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"ok": true})
```

### Errors and validation [#errors-and-validation-1]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_models_unload(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Json(req): Json<UnloadModelRequest>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        db.ml_unload_model(&req.id)
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        Ok(Json(serde_json::json!({"ok": true})))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:2685`. Registration: `akasha-daemon/src/main.rs:4557`.

<a id="get-v1-ml-models" />

## GET `/v1/ml/models` [#get-v1mlmodels]

Ml models list

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-2]

No typed JSON, query, or path extractor is declared in the handler signature. Headers or request objects may still be consumed; the signature below is authoritative.

### Response [#response-2]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"models": db.ml_list_loaded_models()}),
```

### Errors and validation [#errors-and-validation-2]

Directly referenced error variants: none in the handler body. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_models_list(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        Ok(Json(
            serde_json::json!({"models": db.ml_list_loaded_models()}),
        ))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:2697`. Registration: `akasha-daemon/src/main.rs:4558`.

<a id="post-v1-ml-metrics" />

## POST `/v1/ml/metrics` [#post-v1mlmetrics]

Ml metrics

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-3]

**Json** — `MlMetricsRequest`

| Field      | Rust type | Required on input | Notes |
| ---------- | --------- | ----------------- | ----- |
| `model_id` | `String`  | Yes               |       |

```rust
struct MlMetricsRequest {
    model_id: String,
}
```

### Response [#response-3]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"metrics": m})
```

### Errors and validation [#errors-and-validation-3]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_metrics(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Json(req): Json<MlMetricsRequest>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        let m = db
            .ml_model_metrics(&req.model_id)
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        Ok(Json(serde_json::json!({"metrics": m})))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:2712`. Registration: `akasha-daemon/src/main.rs:4559`.

<a id="post-v1-ml-embed" />

## POST `/v1/ml/embed` [#post-v1mlembed]

Ml embed

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-4]

**Json** — `EmbedRequest`

| Field      | Rust type                          | Required on input         | Notes                                                                                                                                                                        |
| ---------- | ---------------------------------- | ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `text`     | `String`                           | Yes                       |                                                                                                                                                                              |
| `chunk`    | `bool`                             | No; optional or defaulted | When true, long text is automatically chunked and each chunk is embedded separately.  The response contains a `vectors` array instead of a single `vector`. Serde: `default` |
| `chunking` | `Option<chunking::ChunkingConfig>` | No; optional or defaulted | Optional per-request chunking overrides.                                                                                                                                     |

```rust
struct EmbedRequest {
    text: String,
    /// When true, long text is automatically chunked and each chunk is
    /// embedded separately.  The response contains a `vectors` array instead
    /// of a single `vector`.
    #[serde(default)]
    chunk: bool,
    /// Optional per-request chunking overrides.
    chunking: Option<chunking::ChunkingConfig>,
}
```

### Response [#response-4]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"vector": v, "chunks": 1})
```

```rust
serde_json::json!({
            "vectors": vectors,
            "chunks": chunks.len(),
        })
```

```rust
serde_json::json!({"vector": v})
```

### Errors and validation [#errors-and-validation-4]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_embed(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Json(req): Json<EmbedRequest>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();

        if req.chunk {
            // Use per-request config or fall back to the global chunker.
            let chunker = match req.chunking {
                Some(cfg) => chunking::TextChunker::new(cfg),
                None => (*state.chunker).clone(),
            };
            let chunks = chunker.chunk(&req.text);

            if chunks.len() <= 1 {
                // No chunking needed -- embed as-is.
                let v = db
                    .ml_embed_text(&req.text)
                    .await
                    .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
                return Ok(Json(serde_json::json!({"vector": v, "chunks": 1})));
            }

            let mut vectors: Vec<serde_json::Value> = Vec::with_capacity(chunks.len());
            for ch in &chunks {
                let v = db
                    .ml_embed_text(&ch.text)
                    .await
                    .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
                vectors.push(serde_json::json!({
                    "vector": v,
                    "chunk_index": ch.chunk_index,
                    "start_offset": ch.start_offset,
                    "end_offset": ch.end_offset,
                }));
            }
            Ok(Json(serde_json::json!({
                "vectors": vectors,
                "chunks": chunks.len(),
            })))
        } else {
            let v = db
                .ml_embed_text(&req.text)
                .await
                .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
            Ok(Json(serde_json::json!({"vector": v})))
        }
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:2737`. Registration: `akasha-daemon/src/main.rs:4560`.

<a id="post-v1-ml-generate" />

## POST `/v1/ml/generate` [#post-v1mlgenerate]

Ml generate

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-5]

**Json** — `MlGenerateRequest`

| Field         | Rust type       | Required on input         | Notes |
| ------------- | --------------- | ------------------------- | ----- |
| `model_id`    | `String`        | Yes                       |       |
| `prompt`      | `String`        | Yes                       |       |
| `max_tokens`  | `Option<usize>` | No; optional or defaulted |       |
| `temperature` | `Option<f32>`   | No; optional or defaulted |       |

```rust
struct MlGenerateRequest {
    model_id: String,
    prompt: String,
    max_tokens: Option<usize>,
    temperature: Option<f32>,
}
```

### Response [#response-5]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"text": text})
```

### Errors and validation [#errors-and-validation-5]

Directly referenced error variants: `InvalidRequest`, `ServiceDisabled`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_generate(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Json(req): Json<MlGenerateRequest>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        let model = {
            let ml = db.ml();
            let store = ml
                .model_store()
                .map_err(|e| DaemonError::ServiceDisabled(e.to_string()))?;
            let view = store.read();
            view.get_model(&req.model_id)
                .ok_or_else(|| DaemonError::InvalidRequest("model not found".into()))?
                .clone()
        };
        let text = db
            .ml_generate_text(
                &model,
                &req.prompt,
                req.max_tokens.unwrap_or(256),
                req.temperature.unwrap_or(0.7),
            )
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        Ok(Json(serde_json::json!({"text": text})))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:2829`. Registration: `akasha-daemon/src/main.rs:4561`.

<a id="post-v1-ml-tokenizers-load" />

## POST `/v1/ml/tokenizers/load` [#post-v1mltokenizersload]

Ml tokenizer load

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-6]

**Json** — `MlTokenizerLoadReq`

| Field      | Rust type | Required on input | Notes |
| ---------- | --------- | ----------------- | ----- |
| `model_id` | `String`  | Yes               |       |

```rust
struct MlTokenizerLoadReq {
    model_id: String,
}
```

### Response [#response-6]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"ok": true})
```

### Errors and validation [#errors-and-validation-6]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_tokenizer_load(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Json(req): Json<MlTokenizerLoadReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        db.ml_load_tokenizer_for_model(&req.model_id)
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;
        Ok(Json(serde_json::json!({"ok": true})))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:2862`. Registration: `akasha-daemon/src/main.rs:4562`.

<a id="post-v1-ml-train-supervised" />

## POST `/v1/ml/train/supervised` [#post-v1mltrainsupervised]

Ml train supervised http

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | See handler source and return expressions.                       |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-7]

**Json** — `MlTrainSupervisedReq`

| Field         | Rust type                 | Required on input         | Notes            |
| ------------- | ------------------------- | ------------------------- | ---------------- |
| `model_name`  | `String`                  | Yes                       |                  |
| `input_dim`   | `usize`                   | Yes                       |                  |
| `num_classes` | `usize`                   | Yes                       |                  |
| `samples`     | `Vec<MlSupervisedSample>` | Yes                       |                  |
| `params`      | `MlTrainingParams`        | No; optional or defaulted | Serde: `default` |

```rust
struct MlTrainSupervisedReq {
    model_name: String,
    input_dim: usize,
    num_classes: usize,
    samples: Vec<MlSupervisedSample>,
    #[serde(default)]
    params: MlTrainingParams,
}
```

### Response [#response-7]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({
        "model_id": info.id,
        "name": info.name,
        "version": info.version,
        "metrics": info.metrics,
    })
```

### Errors and validation [#errors-and-validation-7]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_train_supervised_http(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Json(req): Json<MlTrainSupervisedReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        if req.samples.is_empty() {
            return Err(DaemonError::InvalidRequest(
                "no training samples provided".into(),
            ));
        }
        let samples = req
            .samples
            .into_iter()
            .map(|s| akasha_ml::training::SupervisedSample {
                features: s.features,
                label: s.label,
            })
            .collect();

        let mut params = akasha_ml::training::TrainingParams::default();
        if let Some(lr) = req.params.learning_rate {
            params.learning_rate = lr;
        }
        if let Some(wd) = req.params.weight_decay {
            params.weight_decay = wd;
        }
        if let Some(epochs) = req.params.epochs {
            params.epochs = epochs;
        }
        if let Some(batch) = req.params.batch_size {
            params.batch_size = batch;
        }

        let info = db
            .ml_train_supervised(
                &req.model_name,
                req.input_dim,
                req.num_classes,
                samples,
                params,
            )
            .await
            .map_err(|e| DaemonError::InvalidRequest(e.to_string()))?;

        Ok(Json(serde_json::json!({
            "model_id": info.id,
            "name": info.name,
            "version": info.version,
            "metrics": info.metrics,
        })))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:2972`. Registration: `akasha-daemon/src/main.rs:4563`.

<a id="post-v1-ml-train-hrm" />

## POST `/v1/ml/train/hrm` [#post-v1mltrainhrm]

Ml train hrm http

| Availability         | Source contract                                                  |
| -------------------- | ---------------------------------------------------------------- |
| Registration         | `config.enable_ml`                                               |
| Runtime service      | No prefix-level service check; handler dependencies still apply. |
| Handler dependencies | `Cognitive`                                                      |

**Access:** Daemon authentication and capability namespace authority; memory-domain permissions apply where mapped.

### Request [#request-8]

**Json** — `MlTrainHrmReq`

| Field                | Rust type                        | Required on input         | Notes            |
| -------------------- | -------------------------------- | ------------------------- | ---------------- |
| `domain`             | `String`                         | Yes                       |                  |
| `dataspace`          | `String`                         | Yes                       |                  |
| `primitive_keyspace` | `String`                         | Yes                       |                  |
| `checkpoint_name`    | `String`                         | Yes                       |                  |
| `reservoir_id`       | `Option<String>`                 | No; optional or defaulted | Serde: `default` |
| `epochs`             | `Option<usize>`                  | No; optional or defaulted | Serde: `default` |
| `batch_size`         | `Option<usize>`                  | No; optional or defaulted | Serde: `default` |
| `model_config`       | `serde_json::Value`              | Yes                       |                  |
| `training_config`    | `serde_json::Value`              | Yes                       |                  |
| `inputs`             | `Option<Vec<serde_json::Value>>` | No; optional or defaulted | Serde: `default` |
| `targets`            | `Option<Vec<serde_json::Value>>` | No; optional or defaulted | Serde: `default` |

```rust
struct MlTrainHrmReq {
    domain: String,
    dataspace: String,
    primitive_keyspace: String,
    checkpoint_name: String,
    #[serde(default)]
    reservoir_id: Option<String>,
    #[serde(default)]
    epochs: Option<usize>,
    #[serde(default)]
    batch_size: Option<usize>,
    model_config: serde_json::Value,
    training_config: serde_json::Value,
    #[serde(default)]
    #[allow(dead_code)]
    inputs: Option<Vec<serde_json::Value>>,
    #[serde(default)]
    #[allow(dead_code)]
    targets: Option<Vec<serde_json::Value>>,
}
```

### Response [#response-8]

**Declared return:** `Result<impl IntoResponse, DaemonError>`

The following are the exact JSON construction expressions in the handler. Values such as `rows`, `result`, and delegated types are runtime values, not literal example payloads.

```rust
serde_json::json!({"status": "ok"})
```

### Errors and validation [#errors-and-validation-8]

Directly referenced error variants: `InvalidRequest`. Middleware and delegated services can return additional errors described in the shared error reference.

<Accordions>
  <Accordion title="Inspect implementation">
    This exact source excerpt includes validation, defaults, delegated calls, and response assembly.

    ```rust
    async fn ml_train_hrm_http(
        State(state): State<AppState>,
        Extension(db): Extension<Arc<AkashaDB>>,
        Json(req): Json<MlTrainHrmReq>,
    ) -> Result<impl IntoResponse, DaemonError> {
        state.record_http_request();
        state.usage_emitter.emit_hrm_inference();
        let db = db.clone();
        let orchestrator = require_service!(state.orchestrator, "Cognitive").clone();

        let reservoir_id = match req.reservoir_id {
            Some(ref id) => Some(
                Uuid::parse_str(id)
                    .map_err(|e| DaemonError::InvalidRequest(format!("invalid reservoir_id: {e}")))?,
            ),
            None => None,
        };

        let submission = cognitive::HrmTrainingSubmission {
            domain: req.domain,
            dataspace: req.dataspace,
            primitive_keyspace: req.primitive_keyspace,
            checkpoint_name: req.checkpoint_name,
            reservoir_id,
            epochs: req.epochs,
            batch_size: req.batch_size,
            model_config: req.model_config,
            training_config: req.training_config,
        };

        orchestrator.train_hrm(db, submission).await?;
        Ok(Json(serde_json::json!({"status": "ok"})))
    }
    ```
  </Accordion>
</Accordions>

Source: `akasha-daemon/src/main.rs:3025`. Registration: `akasha-daemon/src/main.rs:4564`.
