Variables
Workspace variables that prompts, playbooks and tools fill in. Requires `variables:read` to list and `variables:write` to create, change, preview or delete.
The Variable object
Returned by the variables endpoints.
SUCCESS{ "code": "SUCCESS", "message": "Variable deleted successfully" }
List 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()
{ "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
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.
orgagentstaticcomputedcurl 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', })
{ "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
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.
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', })
{ "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
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.
staticcomputedcurl -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', })
{ "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
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.
curl -X DELETE https://api.trycareflow.com/variables/value \ -H "Authorization: Bearer sk_live_••••"
const Variable = await careflow.variables.del('value')
{ "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" }