---
slug: 90-builtins
title: Builtins index
description: A categorized index of Synsema's built-in functions — collections, text, math, bytes, time, JSON, I/O, HTTP, DB, memory and response helpers.
example_ids: [builtins]
---

# Builtins index

A categorized map of the built-ins. The full signatures live on each topic page; the core ones are doctested here so this reference can't drift.

```synsema
-- Doc reference: a few core builtins, doctested so the reference can't drift.
intent: "doc reference: core builtins"

print("upper(\"hi\") = " + upper("hi") + ",  join([a,b],\"-\") = " + join(["a", "b"], "-"))

test "collections"
    assert_eq(length([1, 2, 3]), 3)
    assert(contains([1, 2, 3], 2))
    assert_eq(slice([1, 2, 3, 4], 1, 3), [2, 3])     -- Python-style end-exclusive
    assert_eq(keys({"a": 1, "b": 2}), ["a", "b"])
    assert_eq(values({"a": 1, "b": 2}), [1, 2])

test "text"
    assert_eq(upper("hi"), "HI")
    assert_eq(trim("  x  "), "x")
    assert_eq(split("a,b,c", ","), ["a", "b", "c"])
    assert_eq(join(["a", "b"], "-"), "a-b")
    assert(starts_with("hello", "he"))

test "intentional ops"
    assert_eq(apply((n) => n * 2, [1, 2, 3]), [2, 4, 6])
    assert_eq(where([1, 2, 3, 4], (n) => n > 2), [3, 4])
    assert_eq(reduce([1, 2, 3], (a, b) => a + b, 0), 6)

test "intentional ops accept both orders (fn-first and list-first)"
    assert_eq(apply([1, 2, 3], (n) => n * 2), [2, 4, 6])     -- list-first also works
    assert_eq(where((n) => n > 2, [1, 2, 3, 4]), [3, 4])     -- fn-first also works
    assert_eq(reduce((a, b) => a + b, [1, 2, 3], 10), 16)    -- extra args stay at the end

test "unique and index_of"
    assert_eq(unique([3, 1, 3, 2, 1]), [3, 1, 2])            -- first-appearance order
    assert_eq(index_of([10, 20, 30], 20), 1)                 -- by item
    assert_eq(index_of([1, 2, 3], (n) => n > 1), 1)          -- by predicate
    assert_eq(index_of([1, 2], 9), nothing)                  -- absent → nothing, not -1

test "program & subprocess: args() and self_path() (no capability)"
    assert_eq(type_of(args()), "list")           -- the program's argv (empty under `synsema test`)
    assert_eq(type_of(self_path()), "text")       -- this executable's path
    assert(length(self_path()) > 0)
```

## By category

- **Collections:** `length`, `contains`, `slice`, `keys`, `values`, `apply`, `where`, `reduce`, `sort_by`, `group_by`, `find_first`, `every`, `some`, `collect`, `count_where`, `flatten`, `chunk`, `zip_with`, `unique` (dedupe, first-appearance order, structural equality), `index_of` (0-based index of item or predicate match; absent → `nothing`, not -1). `enumerate(list)` → `[{index, item}, …]` for indexed loops (language and templates). The intentional ops that take a callable accept **both** orders — `apply(fn, list)` and `apply(list, fn)` read equally well; two tasks or two lists where one-and-one is expected is an explicit error.
- **Text:** `upper`, `lower`, `fold`, `trim`, `starts_with`, `split`, `join`, `replace_text`, `replace_re`, `matches`, `capture`, `text`, `fmt`, `strip_ansi` (engine v0.6.8+: terminal output → plain text; CSI/OSC/charset escapes and control bytes removed, `\r` redraws keep the last frame).
- **Numbers / math:** `+ - * / % **`, `number`, constants `pi`/`tau`/`e`/`inf`/`nan`; `abs`, `sign`, `min`, `max`, `clamp`, `sqrt`, `cbrt`, `hypot`, `pow`, `exp`, `ln`, `log10`, `log2`, `log_base`, `floor`, `ceil`, `round`, `trunc`, `round_to`, `sin`/`cos`/`tan`/`asin`/`acos`/`atan`/`atan2`, `radians`/`degrees`, `sinh`/`cosh`/`tanh`/`asinh`/`acosh`/`atanh`, `gcd`, `lcm`, `factorial`, `is_nan`/`is_infinite`/`is_finite`, `gamma`/`lgamma`/`erf`/`erfc`/`beta`; `decimal`, `complex`/`real`/`imag`/`conj`/`arg`; type predicates `is_decimal`, `is_complex`, `is_array`, `is_bytes`, `type_of`; arrays `array`, `arange`, `linspace`, `zeros`, `ones`, `eye`, `full`, `reshape`, `shape`, `ndim`, `size`, `transpose`, `trace`, `dot`, `norm`, `matmul`, `solve`, `det`, `inv`, `eig`, `svd`; `bytes_to_int`, `int_to_bytes`, `int_to_bytes_le` — see [Bytes, math & arrays](/en/0.6.x/35-bytes-math-arrays).
- **Bytes / crypto:** `bytes`, `decode` (encodings: `utf8`, `hex`, `base64`, `base64url`, `base58`, `base32`), `sha256`, `sha512`, `hmac_sha256`, `verify_hmac`, `constant_time_eq`.
- **Web auth** (engine v0.5.5+ — see [Login & sessions](/en/0.6.x/40a-web-auth)): `password_hash`, `password_verify`, `jwt_sign`, `jwt_verify`, `totp`, `totp_verify` (pure); `random_bytes`, `token` (`require random`); responses `with_header`, `set_cookie`, `clear_cookie`; `request.cookies`; 2-param `auth with` task.
- **Web Push** (engine v0.6.15+ — see [Your app on the phone](/en/0.6.x/41b-pwa)): `push_vapid_keys()` → `{public, private}` (`require random`; the private key comes back as a `secret` labelled `vapid_private`); `push_send(subscription, payload, opts)` → `{status, ok, gone, retry_after, body}` (`require net("<host of the endpoint>")` — `fcm.googleapis.com` and `jmt17.google.com` (Chrome uses either), `*.notify.windows.com`, `updates.push.services.mozilla.com`, `web.push.apple.com`; `opts.vapid = {public, private: secret, subject}` required, `ttl`, `urgency`, `topic`, `timeout`; payload text / map→JSON / bytes / `nothing`, ≤ 3993 bytes; `gone` on 404/410). RFC 8291 `aes128gcm` + RFC 8292 VAPID, no provider needed; not in the wasm profile.
- **Agent identity & auth** (engine v0.5.6+ — see [Agent identity](/en/0.6.x/46-agent-identity)): capability tokens `captoken_mint`, `captoken_attenuate` (offline, no key), `captoken_verify`, `captoken_allows` (pure); signed requests `http_sign` (`require sign("KEY")` + audit) and `http_signature_verify` (pure, `opts.alg` mandatory); third-party OIDC `oidc_verify` (`iss`+`aud` mandatory; JWKS needs `require net(host)`); `mtls_identity(cert, key, opts?)` with `opts.hosts` scoping (`require file.read`); per-identity metering: `spend_total(unit, identity?)`, identity-scoped rate limits and `SYNSEMA_SPEND_CEILING_PER_IDENTITY="agent=UNIT:max"` (any unit — no currency is privileged); discovery at `/.well-known/synsema-auth`.
- **Time / random:** `now`, `format_time`, `parse_time`, `date_parts` (→ `{year, month, day, hour, minute, second}`, UTC), `sleep`, `random`, `random_int` (`random`, `random_bytes` and `token` need `require random`).
- **JSON:** `json_encode`, `json_decode`; `json_for_script` (same JSON with `<`/`>`/`&` escaped `\u00XX` — the safe way to embed data in an inline `<script>`).
- **CSV:** `csv_parse`, `csv_encode`.
- **Statistics:** `median`, `percentile`, `histogram` (also `sum`, `mean`, `std`, `var`).
- **Charts:** `chart_svg`; `chart` (negotiated content node).
- **I/O (capability-gated):** `read_file`, `write_file`, `append_file`, `edit_file`, `file_exists`, `file_info`, `list_dir`, `grep`, `read_file_bytes`.
- **HTTP:** `http`, `http_get`, `http_post`, `http_put`, `http_delete`, `fetch`.
- **WebSocket:** `ws_connect`, `ws_send`, `ws_recv`, `ws_close`, plus multiplexing/resilience `ws_select`, `ws_select_all`, `ws_broadcast`, `ws_status`, `ws_stats` (all gated by `net`). `ws_connect` opts: `subprotocols`, `max_queue`, `max_queue_bytes`, `on_full`, `reconnect` (`{max_retries, backoff, backoff_max, on_reconnect}`), `keepalive` (`{interval, timeout}`).
- **Blockchain (pure):** `keccak256`, `sha512_256`, `secp256k1_verify/recover/pubkey`, `ed25519_verify/pubkey`, `eth_address`, `rlp_encode/decode`, `abi_encode/decode/selector`, `eip191_digest`, `eip712_digest`, `solana_message/tx`, `solana_pda`, `spl_ata`, `spl_transfer_data`, `spl_transfer_checked_data`, `algorand_tx_encode/tx`, `algo_address`, `bytes_to_int`, `int_to_bytes`, `int_to_bytes_le`.
- **Blockchain (gated):** `secp256k1_sign` / `ed25519_sign` / `schnorr_sign` (`require sign`); `mnemonic_generate`, `mnemonic_to_seed`, `hd_derive`, `algorand_mnemonic`, `keystore_import`/`keystore_export`, `wif_import` (`require wallet`).
- **Bitcoin (pure):** `hash160`, `btc_address`, `btc_address_decode`, `btc_script`, `btc_txid`, `schnorr_verify`, `schnorr_pubkey`, `btc_tx`, `btc_tx_raw`, `psbt_encode`, `psbt_decode`, `psbt_finalize`.
- **Bitcoin (read side, gated by `net`):** `btc_utxos`, `btc_balance`, `btc_fee_estimates`, `btc_send`, `btc_wait`, `btc_rpc`.
- **Blockchain read side (gated by `net`, like HTTP):** `eth_rpc`, `eth_nonce`, `eth_balance`, `eth_gas_price`, `eth_chain_id`, `eth_estimate_gas`, `eth_call`, `eth_fee_history`, `eth_send_raw`, `eth_receipt`, `eth_wait_receipt`; `solana_rpc`, `solana_latest_blockhash`, `solana_balance`, `solana_send`, `solana_confirm`, `spl_balance`; `algorand_params`, `algorand_account`, `algorand_send`, `algorand_wait`. Plus the pure builders `tx_eip1559` / `tx_eip1559_raw`.
- **DB:** `db_open`, `db_close`, `sql`, `sql_exec`, `sql_batch`, `sql_tables`, `paged`; `mongo_find`, `mongo_find_one`, `mongo_insert`, `mongo_insert_many`, `mongo_update`, `mongo_delete`, `mongo_count`, `mongo_aggregate`, `mongo_collections`; `redis_get`/`set`/`del`/`exists`/`mget`/`mset`/`keys`/`type`, `redis_incr`/`decr`/`incrby`, `redis_expire`/`ttl`/`persist`, `redis_hget`/`hset`/`hdel`/`hgetall`/`hincrby`, `redis_lpush`/`rpush`/`lpop`/`rpop`/`lrange`/`llen`, `redis_sadd`/`srem`/`smembers`/`sismember`, `redis_lock`/`unlock` — see [SQL, Mongo & Redis](/en/0.6.x/33-sql-mongo-redis).
- **Serve — responses, content, state:** `ok`, `created`, `not_found`, `fail`, `html`, `respond`, `redirect`, `binary`, `render`, `with_header`, `set_cookie`, `clear_cookie`; content nodes `page`, `heading`, `prose`, `list`, `ordered_list`, `link`, `image`, `section`, `code`, `raw`, `content`, `chart`; shared state `state_set`, `state_get`, `state_incr`, `state_delete`, `state_all` — see [HTTP server](/en/0.6.x/40-serve).
- **Cron:** `cron_every`, `cron_after`, `cron_cancel`, `cron_list`, `cron_status`.
- **Agentic apps** (engine v0.6.7+ — see [Agentic apps](/en/0.6.x/47-agentic-apps)): one wait `select(targets, timeout?)`; live processes `proc_spawn`, `proc_recv`, `proc_select`, `proc_send`, `proc_close_stdin`, `proc_resize` (v0.6.8+, pty only), `proc_status`, `proc_kill`, `proc_wait`, `proc_stats`, `proc_close` (gated by `exec`, like `run`; `proc_spawn(…, {"pty": true})` from v0.6.8; kill reaches the whole process tree and `{"process_group": false}` detaches on purpose, v0.6.9+); file-watch `watch`, `watch_recv`, `watch_stats`, `watch_close` (v0.6.9+, gated by `file.read` like `list_dir`; polling with a snapshot, same events on every OS); the program's own terminal `term_open`, `term_recv`, `term_size`, `term_write`, `term_stats`, `term_close` (v0.6.11+, gated by `stdin`; raw mode, every key as an event, in `select`; `term_open` is `nothing` without a TTY); event bus `bus_publish`, `bus_subscribe`, `bus_recv`, `bus_unsubscribe`, `bus_topics` (no capability); agent control `agents`, `agent_stop`; the `socket` binding of a `route … socket` block is a WebSocket handle for the `ws_*` family.
- **Program & subprocess** (engine v0.6.14+): `args()` → the program's own argv (what follows `--` in `synsema run`, or the whole argv of a `synsema build` binary) — **no capability** (it's input the caller typed); `self_path()` → this executable's path, exactly as the OS gives it (pass it to `run`/`proc_spawn` — the `exec` scope matches byte-for-byte) — no capability; `platform()` → `{os, arch}` (v0.6.18+: `"windows"`/`"macos"`/`"linux"` and other names as Rust reports them; `"x86_64"`/`"aarch64"`; `"wasm"`/`"wasm32"` in the browser build) — no capability, the same answer under `--sandbox` and `--profile pure` (a fact of the binary, like `args()`); `shutdown(reason?)` (v0.6.18+) → asks the running server for its ordered drain and exit 0 — from a route, a socket, a cron job or an agent; idempotent; an error under `run` and before anything listens; a `secret` reason is refused; no capability — see **[Your app on the desktop](/en/0.6.x/41c-desktop)**; `run_program(source, opts)` — **`require sandbox_run`** — runs another Synsema program in a **child process** under a ceiling that is the intersection with the parent's, its `env`/`cwd`/`timeout` its own and its audit returned as a value — see **[Running Synsema under a ceiling](/en/0.6.x/22-sandbox)**.
- **LLM / tools:** `llm_available`, `llm_usage` (tokens consumed by this process; `0` offline — see [LLM primitives](/en/0.6.x/50-llm-primitives)), `llm_step`, `call`, `call_tool`.
- **Money / spend ledger** (`require spend("UNIT")` — see [Capabilities](/en/0.6.x/20-capabilities)): `spend(amount, unit, reason)` → the unit's accumulated total (audited in `spend.log`, host ceiling `SYNSEMA_SPEND_CEILING`); `spend_total(unit)` → the process total, no capability.
- **Memory / progress / rules** (the whole family needs `require memory("name")` — see **[Memory & state](/en/0.6.x/61-memory)**): `remember`, `recall`, `forget_memory`, `memory_summary`, `create_progress`, `start_step`, `complete_step`, `fail_step`, `resume_point`, `progress_display`, `progress_percent`, `add_rule`, `check_rules`, `get_rules`.
- **Secrets:** `secret`, `as_secret`, `bearer`, `reveal`.
- **Responses (serve):** `ok`, `created`, `fail`, `not_found`, `respond`, `redirect`, `render`, `content`, `paged`; `form of request` (parsed urlencoded/multipart form body, file uploads as exact bytes).
- **Errors:** `raise`, `assert`, `assert_eq`, `assert_ne`, `assert_error`.
