Transport for the Persona API: Bearer auth, the Persona-Version,
Key-Inflection and Idempotency-Key headers, JSON:API request bodies
with unset fields dropped, filter[...]/page[...] query strings,
cursor pagination over links.next, JSON:API read helpers, and errors
parsed into HttpError with PII redacted.
No retries. Nothing here retries a request or waits. A 429 or 5xx
comes back as err(HttpError) with retry-after set; check it with
is-retryable and let Hot back off by failing the run under a handler
or schedule retry policy. Creates accept an idempotency-key, so a
retried create returns the first result instead of making a second
inquiry.
Per-call credentials. Every API-calling function takes an optional
trailing options Map, resolved by resolve: options first, then the
context variables, then the defaults. Nothing from options is written
to ctx, so one run can act for many tenants, and per-call credentials
are masked in call records. An api-key present but blank or null is
an error, never a fallback to context. A per-call base-url needs an
api-key in the same options: persona.api.key is never sent to a
per-call URL.
Context Vars
persona.api.keypersona.api.versionpersona.key-inflection
Values
KEY_INFLECTIONS
KEY_INFLECTIONS: Vec [
"kebab",
"snake",
"camel"
]
MAX_PAGES
MAX_PAGES: Int 1000
REQUEST_OPTION_KEYS
REQUEST_OPTION_KEYS: Vec [
"api-key",
"base-url",
"persona-version",
"key-inflection",
"idempotency-key"
]
RETRYABLE_STATUSES
RETRYABLE_STATUSES: Vec [
408,
429,
500,
502,
503,
504
]
SENSITIVE_KEYS
SENSITIVE_KEYS: Vec [
"socialsecuritynumber",
"ssn",
"birthdate",
"dob",
"dateofbirth",
"identificationnumber",
"idnumber",
"documentnumber",
"taxidentificationnumber",
"tin",
"ein",
"frontphoto",
"backphoto",
"selfiephoto",
"photourls",
"frontphotourl",
"backphotourl",
"sessiontoken",
"onetimelink",
"onetimelinkshort",
"secret",
"secrets",
"apikey",
"authorization"
]
USER_AGENT
USER_AGENT: Str "hot-dev-persona/0.1.0"
Functions
attr
fn (doc: Any, key: Str): Any
An attribute of a resource (or document) by its kebab-case name, in
whichever inflection the response used (has-match, has_match or
hasMatch), or null.
Example
inquiry ::persona::inquiries/get-inquiry("inq_...")
::persona::api/attr(inquiry, "reference-id")
build-headers
fn (method: Str, resolved: Map, has-body: Bool): Map
Request headers from resolved settings (see resolve):
Authorization: Bearer, Accept, Persona-Version, User-Agent,
plus Key-Inflection when set, Idempotency-Key on POSTs when set,
and Content-Type when there is a body. Exposed for testing.
Example
resolved {api-key: "tenant-key", idempotency-key: "signup-42"}
::persona::api/build-headers("POST", resolved, true).Idempotency-Key // "signup-42"
::persona::api/build-headers("GET", resolved, false).Accept // "application/json"
build-request
fn (method: Str, url: Str, body: Any, resolved: Map): ::hot::http/HttpRequest
Build (without sending) the HttpRequest for a Persona call. url is
the full URL including any query string. A non-empty Map body is
compacted and JSON-encoded; otherwise no body is sent. Exposed for
testing.
Example
req ::persona::api/build-request("get", "https://api.withpersona.com/api/v1/inquiries", null, {api-key: "tenant-key"})
req.method // "GET"
req.body // ""
call
fn (method: Str, path: Str): Any
fn (method: Str, path: Str, params: Map): Any
fn (method: Str, path: Str, params: Map, options: Map): Any
Call a Persona endpoint by path (relative to /api/v1) and return the
decoded JSON:API document, or an Err carrying HttpError. params
become the query string for GET and DELETE and the JSON body
otherwise; nulls are omitted. The escape hatch for endpoints without a
typed wrapper.
Example
templates ::persona::api/call("GET", "/inquiry-templates", {page: {size: 10}})
collect
fn (path: Str, filters: Map, limit: Int): Vec
fn (path: Str, filters: Map, limit: Int, options: Map): Vec
Collect up to limit objects from a list endpoint, following
links.next. filters as in list-page.
Example
pending ::persona::api/collect("/inquiries", {status: ["completed", "needs_review"]}, 500)
collect-pages
fn (fetch: Fn, cursor: Str?, limit: Int, acc: Vec, pages-left: Int): Vec
Follow cursors, concatenating each page's data, until limit items,
the last page, or MAX_PAGES. fetch takes the cursor (null first) and
returns one page; the first Err is returned. Exposed for testing;
collect uses it.
Example
fetch (cursor) {
if(is-null(cursor),
{data: [{id: "inq_1"}], links: {next: "/api/v1/inquiries?page%5Bafter%5D=inq_1"}},
{data: [{id: "inq_2"}], links: {next: null}})
}
map(::persona::api/collect-pages(fetch, null, 10, [], 5), %.id) // ["inq_1", "inq_2"]
compact
fn (value: Any): Any
Drop null values recursively through maps and the maps inside vectors,
so unset optionals are omitted rather than sent as JSON null. false,
0 and "" are kept. Exposed for testing.
Example
::persona::api/compact({a: null, b: [{c: null, d: 0}]}) // {b: [{d: 0}]}
document
fn (type-name: Str?, attributes: Map, meta-block: Map): Map
A JSON:API request body: {data: {type?, attributes}, meta}, with
nulls dropped and empty attributes, data and meta left out.
type may be null. Exposed for testing.
Example
::persona::api/document(null, {inquiry-template-id: "itmpl_1", note: null}, {})
// => {data: {attributes: {inquiry-template-id: "itmpl_1"}}}
error-entries
fn (body: Any): Vec
Persona's errors array from a (decoded) error body, each entry as
{title, details, pointer} with absent parts null. Empty when the body
has no errors. Exposed for testing.
Example
::persona::api/error-entries({errors: [{title: "Not found", source: {pointer: "/data/id"}}]})
// [{title: "Not found", details: null, pointer: "/data/id"}]
error-message
fn (status: Int, body: Any, request-id: Str?): Str
The readable message for an error: persona: HTTP {status}: {title}: {details} ({pointer}); ... [{request-id}]. Only Persona's error titles,
details and pointers are used (never the request), and they are passed
through redact-text. Exposed for testing.
Example
::persona::api/error-message(404, {errors: [{title: "Record not found"}]}, "req_abc")
// "persona: HTTP 404: Record not found [req_abc]"
error-status
fn (error: Result): Int?
The HTTP status of a failed call (an HttpError or a Result.Err
holding one), or null for transport errors.
Example
failed err(::persona::api/HttpError(::hot::http/HttpResponse({status: 404, headers: {}, body: ""})))
::persona::api/error-status(failed) // 404
::persona::api/error-status(err("connection refused")) // null
field-values
fn (doc: Any): Map
A resource's fields as plain values: Persona returns
{name-first: {type: "string", value: "Jane"}}, this gives
{name-first: "Jane"}. Field keys keep the template's casing. These
are the end user's PII; don't log them.
Example
doc {data: {type: "inquiry", attributes: {fields: {name-first: {type: "string", value: "Jane"}}}}}
::persona::api/field-values(doc) // {name-first: "Jane"}
find-included
fn (doc: Any, id: Str): Map?
The object in included with this id, or null.
Example
doc {included: [{id: "ver_1", type: "verification/selfie"}]}
::persona::api/find-included(doc, "ver_1").type // "verification/selfie"
::persona::api/find-included(doc, "ver_2") // null
flatten
fn (doc: Any): Map
A compact view of a resource for code and LLMs: {id, type, ...attributes, relationships: {name: id | [ids]}}. Attribute keys keep the response's
inflection; fields is flattened with field-values.
Example
::persona::api/flatten(::persona::inquiries/get-inquiry("inq_..."))
// => {id: "inq_...", type: "inquiry", status: "approved", reference-id: "user-42", fields: {...}, relationships: {account: "act_..."}}
get-bytes
fn (path: Str, options: Map): Bytes
GET a binary endpoint (e.g. /inquiries/{id}/print) and return the body
as Bytes, or an Err carrying HttpError. The bytes are never put into
errors or logs.
Example
pdf ::persona::api/get-bytes("/reports/rep_123/print", {})
// Bytes on success, or an Err carrying HttpError
if(is-err(pdf), ::persona::api/error-status(pdf), length(pdf))
included
fn (doc: Any, type-name: Str): Vec
The objects in a document's included whose type is type-name or
one of its subtypes: included(doc, "verification") matches
verification/government-id, verification/selfie, ...
Example
inquiry ::persona::inquiries/get-inquiry("inq_...", {include: ["verifications"]})
::persona::api/included(inquiry, "verification")
is-not-found
fn (error: Result): Bool
True when a failed call is an HTTP 404.
Example
::persona::api/is-not-found(err(::persona::api/HttpError(::hot::http/HttpResponse({status: 404, headers: {}, body: ""})))) // true
::persona::api/is-not-found(err("connection refused")) // false
is-retryable
fn (error: Result): Bool
True when a failed call is worth retrying later: HTTP 408, 429, 500,
502, 503 or 504. Let the handler or schedule retry policy do the
waiting (see retry-after on the error).
Example
::persona::api/is-retryable(err(::persona::api/HttpError(::hot::http/HttpResponse({status: 429, headers: {}, body: ""})))) // true
::persona::api/is-retryable(err(::persona::api/HttpError(::hot::http/HttpResponse({status: 422, headers: {}, body: ""})))) // false
is-sensitive-key
fn (key: Any): Bool
True when an attribute name is in SENSITIVE_KEYS, in any inflection
(social-security-number, social_security_number,
socialSecurityNumber). Exposed for testing.
Example
::persona::api/is-sensitive-key("social_security_number") // true
::persona::api/is-sensitive-key("status") // false
key-variants
fn (key: Str): Vec<Str>
The kebab, snake and camel spellings of a kebab-case key: "has-match"
gives ["has-match", "has_match", "hasMatch"]. Exposed for testing.
Example
::persona::api/key-variants("has-match") // ["has-match", "has_match", "hasMatch"]
link-cursor
fn (link: Any, key: Str): Str?
The page[after] (or page[before], for key: "before") value inside
a Persona links.next/links.prev URL such as
/api/v1/inquiries?page%5Bafter%5D=inq_123, or null. Exposed for
testing.
Example
::persona::api/link-cursor("/api/v1/inquiries?page%5Bafter%5D=inq_123", "after") // "inq_123"
::persona::api/link-cursor("/api/v1/inquiries", "after") // null
list-page
fn (path: Str, filters: Map, options: Map): Any
fn (path: Str, filters: Map, options: Map, request-options: Map): Any
GET one page of a list endpoint. Returns the JSON:API document:
data (newest first), links: {prev, next}. Read the next cursor
with next-cursor. include is not allowed on list endpoints.
Example
page ::persona::api/list-page("/inquiries", {status: "needs_review"}, {page-size: 25})
more ::persona::api/list-page("/inquiries", {status: "needs_review"}, {page-size: 25, after: ::persona::api/next-cursor(page)})
list-query
fn (filters: Map, options: Map): Map
The query for one list page. filters become filter[...] (Vec values
comma-joined); options takes page-size (page[size], 1 to 100),
after and before (page[after]/page[before], object ids from
the previous page) and fields (sparse fieldsets). Exposed for
testing.
Example
::persona::api/list-query({status: "approved"}, {page-size: 10, after: "inq_1"})
// {filter: {status: "approved"}, page: {size: 10, after: "inq_1"}}
meta-document
fn (meta-block: Map): Map
A body with only meta (the shape of Persona's action endpoints, e.g.
approve or add-tag), nulls dropped; {} when nothing is set.
Example
::persona::api/meta-document({comment: "Looks good", extra: null}) // {meta: {comment: "Looks good"}}
::persona::api/meta-document({}) // {}
next-cursor
fn (page: Any): Str?
The cursor for the page after page (from links.next), or null on the
last page.
Example
::persona::api/next-cursor({links: {next: "/api/v1/inquiries?page%5Bafter%5D=inq_123"}}) // "inq_123"
::persona::api/next-cursor({links: {next: null}}) // null
parse-int
fn (value: Any): Int?
An Int from an Int or a decimal-digit Str; null for anything else. Never errs on bad input. Exposed for testing.
Example
::persona::api/parse-int("42") // 42
::persona::api/parse-int("4.2") // null
query-pairs
fn (params: Map, prefix: Str): Vec<Str>
Flatten query params the way Persona reads them: nested maps nest in
brackets ({filter: {status: ["approved", "declined"]}} gives
filter[status]=approved,declined, {page: {size: 10}} gives
page[size]=10), vectors become comma-separated, and nulls and empty
vectors are dropped. Keys and values are percent-encoded. Exposed for
testing.
Example
::persona::api/query-pairs({page: {size: 10}}, "") // ["page%5Bsize%5D=10"]
query-string
fn (params: Map): Str
?a=1&filter%5Bstatus%5D=approved from params (see query-pairs), or
"" when nothing remains.
Example
::persona::api/query-string({page: {size: 10}}) // "?page%5Bsize%5D=10"
::persona::api/query-string({}) // ""
read-query
fn (options: Map): Map
The query for a single-object read from options: include (a Vec or
comma string of relationship names, e.g. ["verifications", "account"]) and fields (sparse fieldsets, e.g. {inquiry: ["status", "reference-id"]}). Exposed for testing.
Example
::persona::api/read-query({include: ["account"], page-size: 5}) // {include: ["account"]}
redact
fn (value: Any): Any
Remove PII from a decoded body: values under sensitive keys (see
is-sensitive-key) become "[redacted]", and every other string is
masked by redact-text. Applied to every HttpError, so errors are
safe to log. Exposed for testing.
Example
::persona::api/redact({ssn: "123-45-6789", note: "Seen 2024-01-31", status: "ok"})
// {ssn: "[redacted]", note: "Seen [redacted]", status: "ok"}
redact-text
fn (text: Str): Str
Mask what could be PII in free text: every run of four or more digits
(allowing spaces, dots, slashes and dashes inside, so SSNs, birth dates,
phone and id numbers) becomes [redacted], and every email address
becomes [redacted-email]. Exposed for testing.
Example
::persona::api/redact-text("Call 555-123-4567 or jane@example.com") // "Call [redacted] or [redacted-email]"
relationship-ids
fn (doc: Any, name: Str): Vec<Str>
The ids in a relationship (relationships.<name>.data) as a Vec: one id
for a to-one relationship, every id for a to-many, [] when empty.
Example
doc {data: {type: "inquiry", relationships: {
verifications: {data: [{id: "ver_1"}, {id: "ver_2"}]},
account: {data: {id: "act_1"}}
}}}
::persona::api/relationship-ids(doc, "verifications") // ["ver_1", "ver_2"]
::persona::api/relationship-ids(doc, "account") // ["act_1"]
resolve
fn (options: Any): Map
Settings for one call: options (a Map, or a RequestOptions, with
api-key, base-url, persona-version, key-inflection,
idempotency-key) over the context variables, over the defaults (see
resolve-from). An api-key from options is masked in call records
and returned unchanged; nothing is written to ctx, so parallel flows
and tenants never share credentials.
Example
::persona::api/resolve({api-key: "persona_sandbox_tenant_b"}).persona-version // "2026-09-29"
persona.api.key, persona.api.version, persona.key-inflection
resolve-from
fn (options: Map, ctx-values: Map): Map
The one resolver, pure: settings for a call from options first, then
ctx-values (a Map of context variables), then defaults. Returns
{api-key, base-url, persona-version, key-inflection?, idempotency-key?}, or an Err when no API key is set, when api-key
is in options but blank or null (that never falls back to context),
when options has base-url without api-key, or when
key-inflection isn't kebab, snake or camel. Nothing is written
to ctx. Exposed for testing; resolve feeds it the context.
Example
::persona::api/resolve-from({}, {"persona.api.key": "ctx-key"})
// {api-key: "ctx-key", base-url: "https://api.withpersona.com/api/v1", persona-version: "2026-09-29"}
// A blank per-call key never falls back to context
is-err(::persona::api/resolve-from({api-key: ""}, {"persona.api.key": "ctx-key"})) // true
resource
fn (doc: Any): Map?
The primary resource of a JSON:API document (doc.data), or doc
itself when it is already a resource (has type and attributes).
Example
::persona::api/resource({data: {type: "inquiry", id: "inq_1"}}).id // "inq_1"
::persona::api/resource({type: "inquiry", id: "inq_2"}).id // "inq_2"
response-body
fn (body: Any): Any
Normalize a 2xx body: empty text (204) becomes null; anything else passes through. Exposed for testing.
Example
::persona::api/response-body("") // null
::persona::api/response-body({data: []}) // {data: []}
retry-after-seconds
fn (headers: Map): Int?
Seconds to wait from response headers: Retry-After when numeric, else
RateLimit-Reset, else null. Exposed for testing.
Example
::persona::api/retry-after-seconds({retry-after: "30"}) // 30
::persona::api/retry-after-seconds({ratelimit-reset: "12"}) // 12
::persona::api/retry-after-seconds({}) // null
seg
fn (id: Any): Str
Percent-encode one path segment (an object id), so an id from user input can't change which endpoint is called.
Example
::persona::api/seg("inq 1/2") // "inq%201%2F2"
send
fn (method: Str, path: Str, query: Map, body: Any, options: Map): Any
Send one Persona request and return the decoded body on 2xx, or an
Err: HttpError for a non-2xx response, or the transport error.
path is relative to the resolved base-url (::persona/BASE_URL by default); query becomes the query
string and a Map body the JSON body (null sends none). The most
general form; call picks query or body by method.
Example
::persona::api/send("POST", "/inquiries/search", {}, {query: {attribute: "status", operator: "eq", value: "needs_review"}}, {})
without-request-options
fn (opts: Map): Map
opts without the keys resolve reads, for a function that sends the
rest of opts as attributes. Exposed for testing.
Example
::persona::api/without-request-options({note: "vip", idempotency-key: "signup-42"}) // {note: "vip"}
Types
HttpError
HttpError type {
status: Int,
headers: Map,
body: Any,
message: Str,
errors: Vec,
title: Str?,
details: Str?,
pointer: Str?,
request-id: Str?,
retry-after: Int?
}
A non-2xx Persona response.
status: the HTTP statuserrors: Persona'serrorsarray, each{title, details, source: {pointer}, meta}(redacted)title,details: from the first errorpointer: the first error'ssource.pointer, e.g./data/attributes/inquiry-template-idrequest-id: theRequest-Idheader; quote it to Persona supportretry-after: seconds until the rate limit resets (Retry-AfterorRateLimit-Reset), else nullmessage: one readable line, e.g."persona: HTTP 404: Record not found [req_123]"headers,body: the response, with the body redacted
Values under PII-bearing keys and digit runs or emails in free text
are redacted from body, errors and message (see redact), so an
HttpError never carries an SSN, birth date or id number.
RequestOptions
RequestOptions type {
idempotency-key: Str?,
persona-version: Str?,
key-inflection: Str?,
api-key: Str?,
base-url: Str?
}
Per-request options, the optional last argument of every function that calls the API. A plain Map with the same keys works too.
idempotency-key: sent asIdempotency-Keyon POSTs. Persona stores the first response for a key (at least 24 hours) and replays it for a repeat, so a retried create can't make a second inquiry. Use a UUID or a value tied to your own record, e.g."signup-42-kyc".persona-version: overridesPersona-Versionfor this callkey-inflection:"kebab","snake"or"camel"for this callapi-key: overridespersona.api.keyfor this call. Masked in call records. Blank or null is an error, never a fallback to context.base-url: another API root for this call, such as a proxy. Needs anapi-keyin the same options.
Example
::persona::api/RequestOptions({idempotency-key: "signup-42-kyc"})