> 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-runs/openapi.json](/docs/api/ai-runs/openapi.json). CLI docs offline: `kenso docs <topic>`.
> Last updated: 2026-11-22.

# AI runs: Start an AI run

> **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.

One endpoint of [AI runs](/docs/api/ai-runs.md). Authentication, workspaces and errors: [/docs.md](/docs.md).

## Start an AI run

`POST /v1/campaigns/{campaignId}/ai-runs` - operationId `ai-runs.create`

| Permission | Credits | Rate limit |
| --- | --- | --- |
| Campaigns edit and the `ask` permission | 50 credits per 1,000 contact rows (`ai_qualification`); 300 credits per 1,000 contact rows (`ai_personalization`) | 30 requests a minute and 200 a day per workspace (Free plan: 3 a minute and 20 a day) |

Queues a run of one flow over the campaign's eligible contacts and answers `202` with the run. Poll it until
`status` is `succeeded`, `failed` or `canceled`. A refused run changes nothing. With
`dryRun: true` it answers `200` with what the run would process. Personalization and rewriting run one
segment at a time, so they need `segmentId`: start one run per segment.

Errors:

- `400 validation_failed`: a body field is missing or not valid, such as no `segmentId` for
personalization or rewriting.
- `402 plan_limit_reached`: no credits are left. `error.refusal` has the balance.
- `404 not_found`: the campaign is not in this workspace, or `segmentId` is not one of its segments.
- `409 runs_on_agent`: the workspace gave this flow to its own agent in the agent work settings, so Kenso's AI
does not run it. Run it with `kenso work run`.
- `429 rate_limited`: an AI run quota is used up. Retry after `Retry-After` seconds.
- `503 service_unavailable`: the run queue is full, or the workspace's agent work setting could not be read.
Retry later.

Requires Campaigns edit and the `ask` permission.

[Try it on developer.ken.so](https://developer.ken.so/reference/#kenso-api/tag/ai-runs/POST/v1/campaigns/%7BcampaignId%7D/ai-runs)

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `campaignId` | path | integer (int64) | yes | The campaign to process. |
| `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 |
| --- | --- | --- | --- |
| `flow` | string | yes | The flow to run: `qualification`, `personalization`, `rewriting` or `segmentation`. Required. |
| `batchSize` | integer (int32) | no | The most contacts this run processes, at least 1. Kenso lowers a value above the flow's limit to the limit: 2,000 for qualification and segmentation, 5,000 for personalization and 500 for rewriting. Omitted means 500, or the flow's limit when `processAll` is true. |
| `processAll` | boolean | no | True runs up to the flow's limit when `batchSize` is omitted. Default false. |
| `segmentId` | integer (int64) | no | A segment of the campaign, to process only its contacts. Required for personalization and rewriting, which run one segment at a time. Omit it for qualification and segmentation to run every segment. `0` is `400 validation_failed`, not "no segment". |
| `provider` | string | no | The AI provider for this run only, such as `openai` or `anthropic`. Omitted uses the flow's saved model settings. Kenso ignores an override it cannot use, such as a model the provider does not offer for the flow, and runs the saved settings. |
| `model` | string | no | The AI model id for this run only. With no `provider`, Kenso picks the provider from the model. Omitted uses the flow's saved model settings. |
| `dryRun` | boolean | no | True checks the request and returns what the run would process (`200`) without queueing it, reserving quota or spending credits. Default false. |

### Response 200

Also answers `202`. `data` is a `AiRunDryRun`.

| Field | Type | Description |
| --- | --- | --- |
| `dryRun` | boolean | Always true. |
| `campaignId` | integer (int64) | The campaign the run would process. |
| `flow` | string | The flow the run would process. |
| `segmentId` | integer (int64) | The segment from the request. Omitted when the run would cover every segment. |
| `processAll` | boolean | The `processAll` value from the request. |
| `provider` | string | The provider from the request. Omitted when the request named none. |
| `model` | string | The model id from the request. Omitted when the request named none. |
| `batchSize` | integer (int32) | The most contacts the run would process: `batchSize` from the request, lowered to the flow's limit, else the flow's limit with `processAll`, else 500. |
| `eligibleCount` | integer (int32) | Contacts eligible for the flow now, only those in `segmentId` when it is set. |
| `projectedContactCount` | integer (int32) | The lower of `eligibleCount` and `batchSize`. The run would process at most this many contacts. |
| `blockingGate` | string | The check that left no contact eligible. Omitted when contacts are eligible. |
| `blockingReason` | string | Why no contact is eligible and what to change, for a person to read. Omitted with `blockingGate`. |

### Request

```bash
curl -X POST "https://api.ken.so/v1/campaigns/812/ai-runs" \
  -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 '{
  "flow": "qualification",
  "batchSize": 1,
  "processAll": true,
  "segmentId": 812,
  "provider": "openai",
  "model": "string",
  "dryRun": true
}'
```

### Example response

```json
{
  "success": true,
  "data": {
    "dryRun": true,
    "campaignId": 812,
    "flow": "string",
    "segmentId": 812,
    "processAll": true,
    "provider": "string",
    "model": "string",
    "batchSize": 1,
    "eligibleCount": 1,
    "projectedContactCount": 1,
    "blockingGate": "string",
    "blockingReason": "string"
  }
}
```
