> ## Documentation Index
> Fetch the complete documentation index at: https://developers.clay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# routines create

> Create a routine from an existing function or workflow.

Create a routine from an existing object — a function (a table) or a workflow. The routine id is built from the `type` and `objectId` you pass: e.g. `function` + `tbl_abc` becomes `function:tbl_abc`. Returns the new routine in the same shape as [`clay routines get`](/cli/reference/routines-get); update it later with [`clay routines update`](/cli/reference/routines-update).

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
clay routines create <type> <objectId> [flags]
```

## Arguments

| Argument   | Description                                                                               |
| ---------- | ----------------------------------------------------------------------------------------- |
| `type`     | Routine type. One of `function` or `workflow`. Required.                                  |
| `objectId` | Underlying object id — a table id for `function`, a workflow id for `workflow`. Required. |

## Flags

| Flag                          | Description                                                                                                     |
| ----------------------------- | --------------------------------------------------------------------------------------------------------------- |
| `--name <name>`               | Routine name (6–100 characters).                                                                                |
| `--description <description>` | Optional description (max 500 characters).                                                                      |
| `--entity-type <type>`        | MCP entity type. One of `contact` or `company`. Required for function routines; rejected for workflow routines. |
| `--integrations <csv>`        | Integrations to expose the routine on. Comma-separated list of `api`, `mcp`, or `claygent`.                     |

## Output

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{
  "id": "function:tbl_abc123",
  "type": "function",
  "name": "My contact routine",
  "description": null,
  "entityType": "contact",
  "access": {
    "integrations": ["api", "mcp"]
  }
}
```

| Field                 | Type                       | Description                                                                  |
| --------------------- | -------------------------- | ---------------------------------------------------------------------------- |
| `id`                  | string                     | Routine id, built as `<type>:<objectId>`.                                    |
| `type`                | `"function" \| "workflow"` | Routine type.                                                                |
| `name`                | string                     | Display name.                                                                |
| `description`         | string \| null             | Description, or `null` if not set.                                           |
| `entityType`          | `"contact" \| "company"`   | MCP entity type. Omitted for workflow routines.                              |
| `access.integrations` | string\[]                  | Integrations the routine is exposed on. Each is `api`, `mcp`, or `claygent`. |
| `inputSchema`         | object                     | Input schema for the routine. Omitted when the routine has none.             |

## Errors

| Code               | Exit | Notes                                                                                                      |
| ------------------ | ---- | ---------------------------------------------------------------------------------------------------------- |
| `validation_error` | 2    | Invalid type, missing required flags, `--entity-type` on a workflow routine, or invalid integration value. |
| `auth_forbidden`   | 3    | The API key lacks the `cli:all` scope (or `all`).                                                          |

## Examples

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
clay routines create function tbl_abc123 --name "My contact routine" --entity-type contact --integrations api,mcp
clay routines create workflow wf_abc123 --name "My workflow routine" --integrations api,mcp
clay routines create function tbl_abc123 --name "My contact routine" --entity-type contact --integrations api,mcp | jq -r '.id'
```
