Documents: files a user submitted (government ID images, proof of address, business documents) and what Persona extracted from them.

Responses carry file metadata, not bytes: {filename, url, byte-size}, where url is a signed link (valid 6 hours by default) that needs no API key. The signed URL is itself a credential for the image: never log it or put it in errors. download-file fetches the bytes; its errors carry only the HTTP status.

Values

FILE_KEYS

FILE_KEYS: Vec [
  "files",
  "files-normalized",
  "front-photo",
  "back-photo",
  "selfie-photo"
]

Functions

download-file

fn (url: Str): Bytes

Download a signed Persona file URL and return its Bytes. Only https://files.withpersona.com/ URLs (or other withpersona.com hosts) are fetched, and no API key is sent. On failure the Err says only the HTTP status: never the URL or the bytes.

Example

doc ::persona::documents/get-document("doc_123")
url ::persona::documents/file-url(doc, "front-photo", 0)
image ::persona::documents/download-file(url)
length(image)

file-url

fn (doc: Any, key: Str, index: Int): Str?

The signed URL of a document's file: key is "files", "files-normalized", "front-photo", "back-photo" or "selfie-photo", and index picks within a list (0 for single files). Null when absent. Treat the result as a secret.

Example

doc {data: {type: "document/government-id", attributes: {
  front-photo: {filename: "front.jpg", byte-size: 81234, url: "https://files.withpersona.com/front.jpg"}
}}}
::persona::documents/file-url(doc, "front-photo", 0)  // "https://files.withpersona.com/front.jpg"
::persona::documents/file-url(doc, "selfie-photo", 0)  // null

files

fn (doc: Any): Vec

The file metadata on a document, one entry per file: {key, filename, byte-size, has-url}. Signed URLs are deliberately left out so the result is safe to log or hand to an LLM; read a URL with file-url when you need to download. Exposed for testing.

Example

doc {data: {type: "document/government-id", attributes: {
  front-photo: {filename: "front.jpg", byte-size: 81234, url: "https://files.withpersona.com/front.jpg"}
}}}
::persona::documents/files(doc)
// [{key: "front-photo", filename: "front.jpg", byte-size: 81234, has-url: true}]

get-document

fn (document-id: Str): Map
fn (document-id: Str, options: Map): Map

GET /documents/{id} - Retrieve a document (doc_...): status (initiated, submitted, processed, errored), type, extracted fields and file metadata.

Example

doc ::persona::documents/get-document("doc_...")
::persona::documents/files(doc)  // [{key: "files", filename: "front.jpg", byte-size: 81234, has-url: true}]

is-persona-file-url

fn (url: Any): Bool

True for an https:// URL on withpersona.com or a subdomain. Exposed for testing.

Example

::persona::documents/is-persona-file-url("https://files.withpersona.com/a.jpg")  // true
::persona::documents/is-persona-file-url("https://example.com/a.jpg")  // false