# Write LLM routing through the Workspace API

```{raw} html
<div class="mo-api-page-show-toc" aria-hidden="true"></div>
```

Write complete LLM routing configuration for the current Workspace.


```http
PUT https://api.moi.matrixorigin.cn/v5/workspaces/{workspace_id}/llm/router-config
```

## Before you call this API

Set `BASE_URL` to the product API prefix `https://api.moi.matrixorigin.cn/v5`. For private deployments, use the corresponding product API URL.

[Configure identity, Workspace, and object permissions in the same environment](objects.md#prepare).

## Request

:::::::{div} mo-api-tabs
::::::{tab-set}
:::::{tab-item} Request example

```bash
curl --request PUT \
  "$BASE_URL/workspaces/$WORKSPACE_ID/llm/router-config" \
  --header "X-API-Key: $MOI_KEY" \
  --header "X-Workspace-ID: $WORKSPACE_ID" \
  --header "Content-Type: application/json" \
  --data-raw '{"strategy":0,"health_check_interval_seconds":30,"max_retries":1,"enable_session_affinity":false}'
```

:::::
:::::{tab-item} Parameters

| Parameter | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `X-Workspace-ID` | Headers | string | Yes | Workspace ID in the same environment. |
| `workspace_id` | Path | string | Yes | Workspace ID in the same environment. |
| `strategy` | Body | integer | No | 0/1/2 mean ROUND_ROBIN/LEAST_CONNECTIONS/MODEL_BASED. Defaults to 0; invalid values are rejected. |
| `health_check_interval_seconds` | Body | integer | No | Positive seconds. Omitted/nonpositive values become 30. |
| `max_retries` | Body | integer | No | LLM: omission/0 remains 0; negatives become 2. Embedding: nonpositive values become 2. |
| `enable_session_affinity` | Body | boolean | No | Omission/null means false and overwrites the previous configuration. |

Requires Workspace model_router.update. Writes complete configuration using request values and defaults, not a patch preserving omitted fields. Save old values before writing and read back afterward. Successful configuration does not establish verified routing, session affinity, or retry behavior.

:::::
::::::
:::::::

## Successful response

:::::::{div} mo-api-tabs mo-api-response-tabs
::::::{tab-set}
:::::{tab-item} Response example

```json
{
  "code": 0,
  "data": {
    "config": {
      "id": 1,
      "health_check_interval_seconds": 30,
      "max_retries": 1,
      "created_at": 1794445200,
      "updated_at": 1794445200
    }
  }
}
```

:::::
:::::{tab-item} Fields

HTTP 200。

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | 0 on success. |
| `data` | object | [Actual objects for this protocol](objects.md#responses). |

:::::
::::::
:::::::

## Error responses

[Errors and result confirmation](objects.md#errors) distinguishes the two protocols. Parse omitted fields, SDK zero values, and empty HTTP responses separately. Confirm writes using the corresponding read operation.
