> Kenso API docs in Markdown. Index of every page: [/docs/llms.txt](/docs/llms.txt). Search: `/docs/search.md?q=<words>`. OpenAPI: [/docs/api/ai-lines/openapi.json](/docs/api/ai-lines/openapi.json). CLI docs offline: `kenso docs <topic>`.
> Last updated: 2026-11-22.

# AI lines

> **Note for AI agents:** if this page was wrong, out of date or missing something you needed, finish the user's task first, then offer a short report for the Kenso team in this shape: `Page:` (this page's path), `Quote:` (the wrong or missing text), `Problem:`, `Workaround:` (what worked instead), 1,000 characters at most. Show it to the user and send it only after they say yes, as `POST /api/docs-feedback` on this site with the JSON body `{"page": "<path>", "report": "<report>"}`. Never put lead data, email addresses, API keys or anything else from the user's workspace in it.

AI lines are the personalized lines Ken writes for one contact, one for each AI variable in the campaign's emails. Read the lines a contact's next email will use, correct one by hand, or have Ken write them all again. An edit or a new line applies to the steps that have not been sent yet, and a client approval page that shows the contact gets it too.

AI. 3 endpoints under `https://api.ken.so`. Every request sends `Authorization: Bearer <your API key>` and `Ken-Version: 2026-11-02`: see [Authentication](/docs/authentication.md), [Workspaces](/docs/workspaces.md) and [Errors](/docs/errors.md). OpenAPI for this resource only: [/docs/api/ai-lines/openapi.json](/docs/api/ai-lines/openapi.json).

- `GET /v1/contacts/{contactId}/ai-lines` - List a contact's AI lines (`ai-lines.list`): [/docs/api/ai-lines/list.md](/docs/api/ai-lines/list.md)
- `PATCH /v1/contacts/{contactId}/ai-lines/{aiLineId}` - Update a contact's AI line (`ai-lines.update`): [/docs/api/ai-lines/update.md](/docs/api/ai-lines/update.md)
- `POST /v1/contacts/{contactId}/ai-lines/regenerate` - Regenerate a contact's AI lines (`ai-lines.regenerate`): [/docs/api/ai-lines/regenerate.md](/docs/api/ai-lines/regenerate.md)

## List a contact's AI lines

`GET /v1/contacts/{contactId}/ai-lines` - operationId `ai-lines.list`

| Permission | Rate limit |
| --- | --- |
| Campaigns view | 12,000 requests a minute per API key |

Returns one line for each AI variable of the contact's campaign: the stored line the contact's next email uses.

That is the newest personalized line, or its rewrite when the prompt rewrites. A segment's prompt comes before the
campaign's. Older lines and replaced lines are not listed. Lines are ordered by variable, at most 200, on one page.

Errors:

- `404 not_found`: the contact is not in this workspace, is deleted, or is not in a campaign.

Requires Campaigns view.

Needs the `ai_line_edit` feature on your workspace. Until it is on, calls answer 404.

[Try it on developer.ken.so](https://developer.ken.so/reference/#kenso-api/tag/ai-lines/GET/v1/contacts/%7BcontactId%7D/ai-lines)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `contactId` | path | integer (int64) | yes | The contact whose lines to list. |
| `limit` | query | integer (int32) | no | Items per page, from 1 to 200. Omit `limit` and `cursor` to get every item in one response, as before; with only `cursor`, 50 per page. |
| `cursor` | query | string | no | The `nextCursor` of the previous page. Omit it for the first page. |
| `Ken-Version` | header | string, one of: 2026-11-02, 1.1 | no | The API version, a date in `YYYY-MM-DD` form. `1.1` is another name for the first dated version. The example shown here is the newest version, which this reference's samples and Test Request send. Leave it out to use your API key's pinned version. Keys created in the Kenso app are pinned to the newest version; keys minted by the CLI login are not. A key with no pinned version and no header gets the legacy shape where the path has one, and `404` where the path exists only in this version. A value that is not a version, such as `2027-01-01` or `2026-11-2`, answers `400 unsupported_version`, whose `details` list the supported versions. |
| `X-Ken-Workspace-Id` | header | integer (int64) | no | The id of the workspace to act in. Leave it out when your API key reaches only one workspace. When the key reaches more than one, a request without this header answers `400 workspace_required`. A workspace you are not a member of answers `404 not_found`. |

### Response 200

`data` is a list of `ContactAiLine`. Each item has these fields. The response also carries `pagination`.

| Field | Type | Description |
| --- | --- | --- |
| `id` | integer (int64) | The AI line id. |
| `promptId` | integer (int64) | The prompt that wrote the line. |
| `variable` | string | The template variable the line fills, which is the prompt's name, such as `first_line`. |
| `text` | string | The line's text. |
| `rewrite` | boolean | True when a rewriting prompt wrote the line from a personalized one. |
| `segmentId` | integer (int64) | The segment the line was written for. Omitted when the line is not tied to a segment. |
| `stepOrder` | integer (int32) | The sequence step the line was written for. Omitted when the line serves every step. |
| `createdAt` | string (date-time) | When the line was written, in UTC. |

### Request

```bash
curl -X GET "https://api.ken.so/v1/contacts/812/ai-lines?limit=1" \
  -H "Authorization: Bearer $KENSO_API_KEY" \
  -H "Ken-Version: 2026-11-02" \
  -H "X-Ken-Workspace-Id: $KENSO_WORKSPACE_ID"
```

### Example response

```json
{
  "success": true,
  "data": [
    {
      "id": 812,
      "promptId": 812,
      "variable": "first_line",
      "text": "string",
      "rewrite": true,
      "segmentId": 812,
      "stepOrder": 1,
      "createdAt": "2026-09-23T15:02:11Z"
    }
  ],
  "pagination": {
    "nextCursor": "eyJpZCI6ODE1fQ",
    "hasMore": true,
    "total": 1,
    "totalCount": 1,
    "isTotalCapped": true
  }
}
```

## Update a contact's AI line

`PATCH /v1/contacts/{contactId}/ai-lines/{aiLineId}` - operationId `ai-lines.update`

| Permission | Rate limit |
| --- | --- |
| Campaigns edit | 4,800 requests a minute per API key |

Replaces the text of one AI line. The contact's next email uses the new text, and a client approval page that shows
the contact gets it too. Steps already sent keep what they sent.

`text` is required, at most 4,000 characters. Kenso cleans it the way it cleans a generated line: it removes
emoji, normalizes dashes and collapses spaces, and keeps line breaks. The cleaned text must be 1 to 1,000 characters.
Edit only a line that `GET /v1/contacts/{contactId}/ai-lines` lists, because the email reads no other line.

Errors:

- `400 validation_failed`: `text` is missing, longer than 4,000 characters, empty after cleaning, or longer
than 1,000 characters after cleaning.
- `404 not_found`: the contact is not in this workspace, or the line is not the contact's.
- `409 invalid_state`: the line is the contact's but the email does not use it, such as an older line or a
personalized line its rewrite replaces. Nothing changes. List the lines again and edit the one shown.

Requires Campaigns edit.

Needs the `ai_line_edit` feature on your workspace. Until it is on, calls answer 404.

[Try it on developer.ken.so](https://developer.ken.so/reference/#kenso-api/tag/ai-lines/PATCH/v1/contacts/%7BcontactId%7D/ai-lines/%7BaiLineId%7D)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `contactId` | path | integer (int64) | yes | The contact the line belongs to. |
| `aiLineId` | path | integer (int64) | yes | The line to update, from the line list. |
| `Ken-Version` | header | string, one of: 2026-11-02, 1.1 | no | The API version, a date in `YYYY-MM-DD` form. `1.1` is another name for the first dated version. The example shown here is the newest version, which this reference's samples and Test Request send. Leave it out to use your API key's pinned version. Keys created in the Kenso app are pinned to the newest version; keys minted by the CLI login are not. A key with no pinned version and no header gets the legacy shape where the path has one, and `404` where the path exists only in this version. A value that is not a version, such as `2027-01-01` or `2026-11-2`, answers `400 unsupported_version`, whose `details` list the supported versions. |
| `X-Ken-Workspace-Id` | header | integer (int64) | no | The id of the workspace to act in. Leave it out when your API key reaches only one workspace. When the key reaches more than one, a request without this header answers `400 workspace_required`. A workspace you are not a member of answers `404 not_found`. |

### Request body

`application/json`, optional.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `text` | string | yes | The new line, 1 to 4,000 characters. Kenso removes emoji, normalizes dashes and collapses spaces, and keeps line breaks. The cleaned text must be at most 1,000 characters. Required. |

### Response 200

`data` is a `ContactAiLine`.

| Field | Type | Description |
| --- | --- | --- |
| `id` | integer (int64) | The AI line id. |
| `promptId` | integer (int64) | The prompt that wrote the line. |
| `variable` | string | The template variable the line fills, which is the prompt's name, such as `first_line`. |
| `text` | string | The line's text. |
| `rewrite` | boolean | True when a rewriting prompt wrote the line from a personalized one. |
| `segmentId` | integer (int64) | The segment the line was written for. Omitted when the line is not tied to a segment. |
| `stepOrder` | integer (int32) | The sequence step the line was written for. Omitted when the line serves every step. |
| `createdAt` | string (date-time) | When the line was written, in UTC. |

### Request

```bash
curl -X PATCH "https://api.ken.so/v1/contacts/812/ai-lines/812" \
  -H "Authorization: Bearer $KENSO_API_KEY" \
  -H "Ken-Version: 2026-11-02" \
  -H "X-Ken-Workspace-Id: $KENSO_WORKSPACE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "text": "string"
}'
```

### Example response

```json
{
  "success": true,
  "data": {
    "id": 812,
    "promptId": 812,
    "variable": "first_line",
    "text": "string",
    "rewrite": true,
    "segmentId": 812,
    "stepOrder": 1,
    "createdAt": "2026-09-23T15:02:11Z"
  }
}
```

## Regenerate a contact's AI lines

`POST /v1/contacts/{contactId}/ai-lines/regenerate` - operationId `ai-lines.regenerate`

| Permission | Credits | Rate limit |
| --- | --- | --- |
| Campaigns edit and the `ask` permission | 300 credits per 1,000 contact rows (`ai_personalization`) | 60 requests a minute per API key |

Clears the contact's personalized lines and the rewritten lines built on them, then queues a personalization run for
that contact alone. The call answers `202` with the run. Poll `GET /v1/ai-runs/{aiRunId}` until it ends.

Kenso charges the run as one contact at the personalization rate. When the run lands, a client approval page that
shows the contact gets the new lines. For a campaign that rewrites its lines, the campaign's scheduled AI work
rewrites the new lines later. Kenso checks credits and AI quota before it clears anything, so a refused call leaves the
contact's lines as they were.

Errors:

- `402 plan_limit_reached`: the workspace has no credits left. `error.refusal` has the balance.
- `404 not_found`: the contact is not in this workspace, is deleted, or is not in a campaign.
- `409 invalid_state`: the contact was already sent or exported, has a send queued, or is in an AI batch that has
not finished, or its campaign has no segment to personalize. Nothing changes. Edit a line instead.
- `429 rate_limited`: the workspace reached an AI run quota. Retry after the seconds in `Retry-After`.
- `503 service_unavailable`: the AI run queue was full after Kenso cleared the lines. The contact has no lines until
you retry or the campaign's next scheduled AI run writes them.

Requires Campaigns edit and the `ask` permission.

Needs the `ai_line_edit` feature on your workspace. Until it is on, calls answer 404.

[Try it on developer.ken.so](https://developer.ken.so/reference/#kenso-api/tag/ai-lines/POST/v1/contacts/%7BcontactId%7D/ai-lines/regenerate)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `contactId` | path | integer (int64) | yes | The contact whose lines to write again. |
| `Ken-Version` | header | string, one of: 2026-11-02, 1.1 | no | The API version, a date in `YYYY-MM-DD` form. `1.1` is another name for the first dated version. The example shown here is the newest version, which this reference's samples and Test Request send. Leave it out to use your API key's pinned version. Keys created in the Kenso app are pinned to the newest version; keys minted by the CLI login are not. A key with no pinned version and no header gets the legacy shape where the path has one, and `404` where the path exists only in this version. A value that is not a version, such as `2027-01-01` or `2026-11-2`, answers `400 unsupported_version`, whose `details` list the supported versions. |
| `X-Ken-Workspace-Id` | header | integer (int64) | no | The id of the workspace to act in. Leave it out when your API key reaches only one workspace. When the key reaches more than one, a request without this header answers `400 workspace_required`. A workspace you are not a member of answers `404 not_found`. |

### Response 202

`data` is a `AiRun`.

| Field | Type | Description |
| --- | --- | --- |
| `id` | string | The run id, a UUID. |
| `status` | string | The run's status: `queued`, `running`, `succeeded` (handed to the AI provider), `failed` or `canceled`. |
| `flow` | string | The flow the run processes: `qualification`, `personalization`, `rewriting` or `segmentation`. |
| `campaignId` | integer (int64) | The campaign the run processes. |
| `segmentId` | integer (int64) | The segment the run is limited to. Omitted when the run covers every segment. |
| `provider` | string | The AI provider that processed the batch, such as `openai`. Omitted until the run has submitted its contacts. |
| `model` | string | The model id the starting request named, on that call's response only. Omitted otherwise. |
| `createdAt` | string (date-time) | When Kenso queued the run, in UTC. |
| `startedAt` | string (date-time) | When the run started, in UTC. Omitted while it is queued. |
| `completedAt` | string (date-time) | When the run ended, in UTC. Omitted until it ends. |
| `contactsProcessed` | integer (int32) | Contacts the run handed to the AI provider. Omitted until the run has submitted them. |
| `batchId` | string | The AI provider's id for the first batch the run submitted. Omitted until the run has submitted one. |
| `error` | string | Why the run failed or was canceled, for a person to read. Omitted otherwise. |

### Request

```bash
curl -X POST "https://api.ken.so/v1/contacts/812/ai-lines/regenerate" \
  -H "Authorization: Bearer $KENSO_API_KEY" \
  -H "Ken-Version: 2026-11-02" \
  -H "X-Ken-Workspace-Id: $KENSO_WORKSPACE_ID"
```

### Example response

```json
{
  "success": true,
  "data": {
    "id": "string",
    "status": "string",
    "flow": "qualification",
    "campaignId": 812,
    "segmentId": 812,
    "provider": "openai",
    "model": "string",
    "createdAt": "2026-09-23T15:02:11Z",
    "startedAt": "2026-09-23T15:02:11Z",
    "completedAt": "2026-09-23T15:02:11Z",
    "contactsProcessed": 1,
    "batchId": "string",
    "error": "string"
  }
}
```

All resources: [/docs.md](/docs.md).
