# Create model configuration

Create a model configuration that is referenced by the agent. This interface does not upload or save provider keys.

```text
POST https://moi.matrixorigin.cn/newmoi/workspaces/{workspace_id}/model-configs
```

## Before you call

Prepare a personal access token and target workspace ID that has access to the target workspace.

The example below uses:

- `$AI_STUDIO_API_KEY`: The actual personal access token, passed through the `X-API-Key` Header.
- `$WORKSPACE_ID`: The workspace ID of the configuration to be created, passed in the `X-Workspace-ID` Header and also as `workspace_id` in the path.

Referenced resources such as connections, credentials, etc. must be valid; the interface itself does not receive provider keys.

## Request example

```bash
curl -X POST "https://moi.matrixorigin.cn/newmoi/workspaces/$WORKSPACE_ID/model-configs" \
  -H "X-API-Key: $AI_STUDIO_API_KEY" \
  -H "X-Workspace-ID: $WORKSPACE_ID" \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "销售分析模型",
    "model_name": "<MODEL_NAME>",
    "model_category": "chat"
  }'
```

## Path parameters

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `workspace_id` | string | Yes | Current workspace ID, must be consistent with `X-Workspace-ID`. |

## Request body

| Parameters | Type | Is it required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Configuration name. |
| `model_name` | string | Yes | Model name. |
| `description` | string | No | Configuration description. |
| `status` | string | No | Configuration status. |
| `source_kind` | string | No | Model source type. |
| `model_category` | string | No | Model category. |
| `provider_ref` | string | No | Provider reference. |
| `display_name` | string | No | The configured display name. |
| `connection_ref` | string | No | An existing connection resource reference. |
| `credential_ref` | string | No | An existing credential reference. |
| `parameters` | object | No | Model parameters. |
| `parameter_schema` | object | No | Structural definition of model parameters. |
| `capabilities` | string[] | No | Model capabilities. |
| `limits` | object | No | Model usage restrictions. |
| `pricing_ref` | string | No | Pricing configuration reference. |
| `labels` | object | No | Tag key-value pair. |
| `annotations` | object | No | Annotation key-value pair. |
| `metadata` | object | No | Extended metadata. |

`[]` after a type denotes an array. `[]` in a field path denotes each item in an array.

## Successful response

Returns `201` on success. `data` configured for new models.

```json
{
  "code": 0,
  "data": {
    "id": "mc_01",
    "workspace_id": "ws_01",
    "name": "销售分析模型",
    "status": "active",
    "source_kind": "workspace",
    "model_category": "chat",
    "model_name": "<MODEL_NAME>",
    "version": 1,
    "created_at": "2026-08-18T01:00:00Z",
    "updated_at": "2026-08-18T01:00:00Z"
  }
}
```

The response fields are as follows.

| Field | Type | Description |
| --- | --- | --- |
| `code` | integer | `0` on success. |
| `data.id` | string | Model configuration ID. |
| `data.workspace_id` | string | ID of the workspace to which it belongs. |
| `data.name` | string | Configuration name. |
| `data.status` | string | Configuration status. |
| `data.source_kind` | string | Model source type. |
| `data.model_category` | string | Model category. |
| `data.model_name` | string | Model name. |
| `data.version` | integer | Configuration version. |
| `data.created_at` | string | Creation and update time. |
| `data.updated_at` | string | Creation and update time. |

`[]` after a type denotes an array. `[]` in a field path denotes each item in an array.

## Error response

```json
{
  "code": 2,
  "message": "模型配置参数无效"
}
```

### Common HTTP errors

```{list-table}
:header-rows: 1
:widths: 12 22 32 34

* - HTTP status code
  - error code
  - Common causes
  - Recommended actions
* - `400`
  - `2`（`INVALID_ARGUMENT`）
  - The request body, resource reference, or model configuration field is invalid.
  - Check request fields and reference IDs.
* - `401`
  - `6`（`UNAUTHENTICATED`）
  - Credentials are missing or invalid.
  - Check API Key.
* - `403`
  - `5`（`PERMISSION_DENIED`）
  - The current identity does not have permission to create configurations in the workspace.
  - Use valid credentials, or contact your administrator for authorization.
* - `409`
  - `4`（`ALREADY_EXISTS`）
  - Configuration ID or name conflict.
  - Modify the logo or process the existing configuration.
* - `503`
  - `15`（`UNAVAILABLE`）
  - The model configuration service is unavailable.
  - Try again later.
```

## Follow-up operations

Save `data.id` and reference the configuration in agent model binding.
