Variables

Workspace variables that prompts, playbooks and tools fill in. Requires `variables:read` to list and `variables:write` to create, change, preview or delete.

List variables
GET /variables
Create a variable
POST /variables
Preview text with variables filled in
POST /variables/preview
Update a variable
PATCH /variables/{id}
Delete a variable
DEL /variables/{id}

The Variable object

Returned by the variables endpoints.

Attributes
codeenum
—SUCCESS
messagestring
—
The Variable object
{
  "code": "SUCCESS",
  "message": "Variable deleted successfully"
}

List variables

GET https://api.trycareflow.com/variables

Requires `variables:read`. Returns every variable in the API key's workspace, of both scopes, sorted by key. Deleted variables are left out. Sensitive values show as `••••••••`.

curl https://api.trycareflow.com/variables \
  -H "Authorization: Bearer sk_live_••••"
const Variable = await careflow.variables.list()
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "variables": [
      {
        "_id": "66f1c2a9e4b0f1a2b3c4d5f1",
        "createdAt": "2026-09-20T08:00:00Z",
        "updatedAt": "2026-09-20T08:00:00Z",
        "businessId": "66f1c2a9e4b0f1a2b3c4d501",
        "key": "hotel.checkin_time",
        "scope": "org",
        "description": "Standard check-in time shown to guests",
        "type": "string",
        "source": "static",
        "value": "3:00 PM"
      },
      {
        "_id": "66f1c2a9e4b0f1a2b3c4d5f2",
        "createdAt": "2026-09-21T10:00:00Z",
        "updatedAt": "2026-09-21T10:00:00Z",
        "businessId": "66f1c2a9e4b0f1a2b3c4d501",
        "key": "pms.api_key",
        "scope": "org",
        "description": "Key for the booking system",
        "type": "string",
        "source": "static",
        "value": "••••••••",
        "sensitive": true,
        "allowedDomains": [
          "api.harbourviewhotel.example"
        ]
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "server error",
  "error": "failed to list variables: <database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Create a variable

POST https://api.trycareflow.com/variables

Requires `variables:write`. Creates a variable. Each key can exist once for the workspace and once per agent. For a credential, set `sensitive` to true and list the hosts it may be sent to in `allowedDomains`. Its value is masked in every response from then on.

Parameters
keystringrequired
Lowercase letters, digits and underscores, with dots for nesting, up to 128 characters. Can't start with `case.`, `env.` or `d:`. Stored lowercase and trimmed. Ignored on update.
scopeenumoptional
Any value other than `agent` means `org`. Ignored on update.orgagent
agentIdstringoptional
For `agent` scope: the agent's 24-character ID. Ignored on update.
descriptionstringoptional
—
typestringoptional
The value's type: `string`, `integer`, `number`, `boolean`, `date`, `money`, `enum`, `list` or `object`. Other text is accepted and stored as is.
enumarray<string>optional
Allowed values. Required, with at least one entry, when `type` is `enum`.
sourceenumoptional
Any value other than `computed` means `static`.staticcomputed
valuestringoptional
The static value.
exprstringoptional
For `computed`: the template. Required for that source.
sensitivebooleanoptional
Mark the value as a credential or personal data.
allowedDomainsarray<string>optional
For a sensitive variable: hosts it may be sent to, such as `api.example.com` or `*.example.com`. A pasted URL is reduced to its host. Ignored when `sensitive` is false.
curl https://api.trycareflow.com/variables \
  -H "Authorization: Bearer sk_live_••••" \
  -d key=hotel.checkin_time \
  -d scope=org \
  -d agentId=66f1c2a9e4b0f1a2b3c4d5a7 \
  -d description=Standard check-in time shown to guests
const Variable = await careflow.variables.create({
  key: 'hotel.checkin_time',
  scope: 'org',
  agentId: '66f1c2a9e4b0f1a2b3c4d5a7',
  description: 'Standard check-in time shown to guests',
})
Response
{
  "code": "SUCCESS",
  "message": "Variable created successfully",
  "data": {
    "variable": {
      "_id": "66f1c2a9e4b0f1a2b3c4d5f1",
      "createdAt": "2026-09-20T08:00:00Z",
      "updatedAt": "2026-09-20T08:00:00Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d501",
      "key": "hotel.checkin_time",
      "scope": "org",
      "description": "Standard check-in time shown to guests",
      "type": "string",
      "source": "static",
      "value": "3:00 PM"
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid payload",
  "error": "bad json"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "already exists",
  "error": "a variable named hotel.checkin_time already exists in this scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "server error",
  "error": "failed to create variable: <database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Preview text with variables filled in

POST https://api.trycareflow.com/variables/preview

Requires `variables:write`. Fills the `{key}` tokens in each template with the workspace's current values and returns the result, without sending anything to anyone. Pass `agentId` to include that agent's own variables. System tokens such as `{env.date}`, `{env.time}` and `{env.now}` work too. Sensitive variables, and anything computed from them, come back as `••••••••`. Sensitive variables are filled in with their real values, so treat the response as secret.

Parameters
templatesarray<string>optional
Text containing `{key}` tokens to resolve.
agentIdstringoptional
Resolve as this agent would, including its `agent` variables. Leave it out for workspace values only.
curl https://api.trycareflow.com/variables/preview \
  -H "Authorization: Bearer sk_live_••••" \
  -d templates=Check-in at Harbourview starts at {hotel.checkin_time}.,Today is {env.date}. \
  -d agentId=66f1c2a9e4b0f1a2b3c4d5a7
const Variable = await careflow.variables.create({
  templates: 'Check-in at Harbourview starts at {hotel.checkin_time}.,Today is {env.date}.',
  agentId: '66f1c2a9e4b0f1a2b3c4d5a7',
})
Response
{
  "code": "SUCCESS",
  "message": "ok",
  "data": {
    "results": [
      {
        "template": "Check-in at Harbourview starts at {hotel.checkin_time}.",
        "resolved": "Check-in at Harbourview starts at 3:00 PM.",
        "tokens": [
          "hotel.checkin_time"
        ],
        "missing": null
      },
      {
        "template": "Ask for {hotel.concierge_name}.",
        "resolved": "Ask for {hotel.concierge_name}.",
        "tokens": [
          "hotel.concierge_name"
        ],
        "missing": [
          "hotel.concierge_name"
        ]
      }
    ]
  }
}
{
  "code": "ERROR",
  "message": "invalid payload",
  "error": "bad json"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "server error",
  "error": "failed to build context: <database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Update a variable

PATCH https://api.trycareflow.com/variables/{id}

Requires `variables:write`. Changes a variable's value and settings. `description`, `sensitive` and `allowedDomains` are always overwritten, so send their current values even when you aren't changing them; leaving out `sensitive` turns it off. The key, scope and agent can't be changed: delete and create again instead. To keep a sensitive value, leave `value` empty or send `••••••••`. To stop treating a variable as sensitive, send the value in use again; any other stored value is cleared.

Path parameters
idstringrequired
The variable's ID, a 24-character hex string.
Parameters
descriptionstringoptional
—
typestringoptional
The value's type: `string`, `integer`, `number`, `boolean`, `date`, `money`, `enum`, `list` or `object`. Other text is accepted and stored as is.
enumarray<string>optional
Allowed values. Required, with at least one entry, when `type` is `enum`.
sourceenumoptional
Any value other than `computed` means `static`.staticcomputed
valuestringoptional
The new static value. Empty or `••••••••` keeps the stored one.
exprstringoptional
The new template. Empty or `••••••••` keeps the stored one.
sensitivebooleanoptional
Always applied: leaving it out sets it to `false`. Turning it off for a sensitive variable requires sending the value in use again (`value`, or `expr` for computed).
allowedDomainsarray<string>optional
For a sensitive variable: hosts it may be sent to, such as `api.example.com` or `*.example.com`. A pasted URL is reduced to its host. Ignored when `sensitive` is false.
curl -X PATCH https://api.trycareflow.com/variables/value \
  -H "Authorization: Bearer sk_live_••••" \
  -d description=Standard check-in time shown to guests \
  -d type=string \
  -d enum=value \
  -d source=static
const Variable = await careflow.variables.update({
  description: 'Standard check-in time shown to guests',
  type: 'string',
  enum: 'value',
  source: 'static',
})
Response
{
  "code": "SUCCESS",
  "message": "Variable updated successfully",
  "data": {
    "variable": {
      "_id": "66f1c2a9e4b0f1a2b3c4d5f1",
      "createdAt": "2026-09-20T08:00:00Z",
      "updatedAt": "2026-09-22T11:30:00Z",
      "businessId": "66f1c2a9e4b0f1a2b3c4d501",
      "key": "hotel.checkin_time",
      "scope": "org",
      "description": "Standard check-in time shown to guests",
      "type": "string",
      "source": "static",
      "value": "2:00 PM"
    }
  }
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "invalid variable ID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "not found",
  "error": "no such variable"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "server error",
  "error": "failed to update variable: <database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}

Delete a variable

DEL https://api.trycareflow.com/variables/{id}

Requires `variables:write`. Removes the variable. Tokens that used it stay as written in messages and tool calls. It returns success even when no variable has this ID.

Path parameters
idstringrequired
The variable's ID, a 24-character hex string.
curl -X DELETE https://api.trycareflow.com/variables/value \
  -H "Authorization: Bearer sk_live_••••"
const Variable = await careflow.variables.del('value')
Response
{
  "code": "SUCCESS",
  "message": "Variable deleted successfully"
}
{
  "code": "ERROR",
  "message": "invalid id",
  "error": "invalid variable ID"
}
{
  "code": "ERROR",
  "message": "unauthorized",
  "error": "invalid or revoked API key"
}
{
  "code": "ERROR",
  "message": "insufficient_scope",
  "error": "this API key needs the knowledge:write scope"
}
{
  "code": "ERROR",
  "message": "too_many_requests",
  "error": "You have exceeded the rate limit for api. Please try again in 12s."
}
{
  "code": "ERROR",
  "message": "server error",
  "error": "failed to delete variable: <database error>"
}
{
  "code": "ERROR",
  "message": "service_unavailable",
  "error": "key lookup failed"
}