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

# Custom variables: Create a custom variable

> **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 [Custom variables](/docs/api/custom-variables.md). Authentication, workspaces and errors: [/docs.md](/docs.md).

## Create a custom variable

`POST /v1/campaigns/{campaignId}/custom-variables` - operationId `custom-variables.create`

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

Adds a custom variable to the campaign, so its sequence steps can use the `{key}` token before any contact
has a value for it. Returns `201` with the variable and its `Location`.

`variableKey` is required. Kenso normalizes it to lowercase snake_case, so `Renewal Date` becomes
`renewal_date`. The normalized key must start with a letter and hold only letters, digits and underscores.
It cannot be a field Kenso fills itself, such as `first_name`, `email` or `custom_image`.
`name` defaults to the key.

When the campaign already has the key, the call updates that variable and still returns `201`. It applies
`useAsAiContext` and `isRequiredForSending` if you send them, and keeps the stored name.

Errors:

- `400 validation_failed`: `variableKey` is missing, cannot be used as a token or is a reserved field,
or the campaign already has 50 custom variables.
- `404 not_found`: the campaign does not exist in this workspace.

Requires Campaigns edit.

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

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `campaignId` | path | integer (int64) | yes | Id of the campaign. |
| `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.

The variable to create.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `variableKey` | string | yes | Key of the variable. Required. Kenso normalizes it to lowercase snake_case, so `Renewal Date` becomes `renewal_date`. |
| `name` | string | no | Display name. Omitted uses the normalized key. |
| `useAsAiContext` | boolean | no | Whether Ken reads this variable as context for AI content. Omitted is true for a new variable and keeps the value of an existing one. |
| `isRequiredForSending` | boolean | no | Whether a contact needs a value for this variable to be ready to send. Omitted is false for a new variable and keeps the value of an existing one. |

### Response 201

`data` is a `CustomVariable`.

| Field | Type | Description |
| --- | --- | --- |
| `variableKey` | string | The key in lowercase snake_case, such as `renewal_date` for the `{renewal_date}` token. |
| `name` | string | Display name, such as `Renewal Date`. |
| `useAsAiContext` | boolean | When true, Ken reads each contact's value for this variable as context when it writes AI content for the contact. |
| `isRequiredForSending` | boolean | When true, a contact needs a non-blank value for this variable to be ready to send. |
| `aiOnly` | boolean | When true, the variable is AI context only: Ken may read it when it writes for the contact, and a `{key}` token for it renders empty in every message. Leave it out of variable pickers. True for `linkedin_topic`, `linkedin_topic_post` and `linkedin_topic_comment`. |

### Request

```bash
curl -X POST "https://api.ken.so/v1/campaigns/812/custom-variables" \
  -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 '{
  "variableKey": "string",
  "name": "string",
  "useAsAiContext": true,
  "isRequiredForSending": true
}'
```

### Example response

```json
{
  "success": true,
  "data": {
    "variableKey": "renewal_date",
    "name": "string",
    "useAsAiContext": true,
    "isRequiredForSending": true,
    "aiOnly": true
  }
}
```
