|
@@ -44,6 +44,7 @@ A non-admin key may carry a `scope` object that restricts what it can do. Scoped
|
|
|
|
|
|
|
|
**The Origin allow-list now covers the collections LISTING too** (0.15.0+). It always covered document and vector operations; the listing authorized through the project grant plus the scope filter and never consulted the list, so a key with an allow-list could enumerate a project's collection names, document counts and sizes from ANY origin while being refused every document in them. That mattered because a browser-publishable key is, by definition, a key anyone can read. Now `GET /projects/{p}/collections` answers **403** `forbidden` for an origin outside the list, exactly as a document read does.
|
|
**The Origin allow-list now covers the collections LISTING too** (0.15.0+). It always covered document and vector operations; the listing authorized through the project grant plus the scope filter and never consulted the list, so a key with an allow-list could enumerate a project's collection names, document counts and sizes from ANY origin while being refused every document in them. That mattered because a browser-publishable key is, by definition, a key anyone can read. Now `GET /projects/{p}/collections` answers **403** `forbidden` for an origin outside the list, exactly as a document read does.
|
|
|
- **A key with NO `origins` is unaffected** - an empty list means any origin, which is what a server-side key should use.
|
|
- **A key with NO `origins` is unaffected** - an empty list means any origin, which is what a server-side key should use.
|
|
|
|
|
+- `ip_allow` on a KEY scope is **refused with 422 `unsupported_option`**, not stored. Nothing checks it for an API key, and a control that reads back from the server while never being applied is worse than one that is absent - an operator would believe a key was pinned to their office address. It is a **function policy** field only (see the policy route). For a browser key, `origins` is the control that works; a server-side key has none today, because a non-browser client sends no `Origin` header.
|
|
|
- **An ABSENT `Origin` header is refused when a list IS set**, on the listing and on every other capability-checked route alike. This is long-standing behaviour rather than new, and it is why **a key intended for server-side use must not carry an allow-list at all**: a non-browser client sends no Origin, so it can never satisfy one. A test pins the two routes to the same answer so they cannot drift apart again.
|
|
- **An ABSENT `Origin` header is refused when a list IS set**, on the listing and on every other capability-checked route alike. This is long-standing behaviour rather than new, and it is why **a key intended for server-side use must not carry an allow-list at all**: a non-browser client sends no Origin, so it can never satisfy one. A test pins the two routes to the same answer so they cannot drift apart again.
|
|
|
|
|
|
|
|
**A scope refusal names what it refused and what you hold** (0.15.0+). A 403 `forbidden` from a scoped key carries a message naming the collection and the operation asked, plus the collections the key IS granted, and `error.details` with `collection`, `operation` and `granted` (each `{collection, ops}`). **The status is 403 whether the collection is outside your scope OR does not exist, and that is deliberate** - answering 404 for an absent collection would let a scoped key discover which collections exist in its project outside its own scope. So the message says as much: only you can tell a misspelled name from one nobody provisioned, and the answer will not tell you. Before 0.15.0 the message was just "scope does not permit this operation", which named neither and sent people to re-verify their key rather than the string.
|
|
**A scope refusal names what it refused and what you hold** (0.15.0+). A 403 `forbidden` from a scoped key carries a message naming the collection and the operation asked, plus the collections the key IS granted, and `error.details` with `collection`, `operation` and `granted` (each `{collection, ops}`). **The status is 403 whether the collection is outside your scope OR does not exist, and that is deliberate** - answering 404 for an absent collection would let a scoped key discover which collections exist in its project outside its own scope. So the message says as much: only you can tell a misspelled name from one nobody provisioned, and the answer will not tell you. Before 0.15.0 the message was just "scope does not permit this operation", which named neither and sent people to re-verify their key rather than the string.
|
|
@@ -133,7 +134,12 @@ Arbitrary JSON CRUD under a `kind=json` collection.
|
|
|
|
|
|
|
|
**It requires the document to exist** (**404** otherwise) and never creates one: the starting document is yours to describe. The idiom for a counter that may not exist yet is: increment; on **404** `POST .../documents` the document under a fixed `id` with its starting values; on **409** `duplicate_values` (someone else just created it) increment again.
|
|
**It requires the document to exist** (**404** otherwise) and never creates one: the starting document is yours to describe. The idiom for a counter that may not exist yet is: increment; on **404** `POST .../documents` the document under a fixed `id` with its starting values; on **409** `duplicate_values` (someone else just created it) increment again.
|
|
|
- `DELETE /api/v1/projects/{project}/collections/{name}/documents/{id}` - Delete a document. Returns **409** `relation_restricted` (with `error.details.impacts`) if a restrict relation has children referencing it; see delete-impact below to preview this first.
|
|
- `DELETE /api/v1/projects/{project}/collections/{name}/documents/{id}` - Delete a document. Returns **409** `relation_restricted` (with `error.details.impacts`) if a restrict relation has children referencing it; see delete-impact below to preview this first.
|
|
|
-- `GET /api/v1/projects/{project}/collections/{name}/documents` - Find documents. Every row carries the same `_id`/`_version` metadata a single GET returns, so a filtered listing is a usable starting point for a conditional write without a second request per row.
|
|
|
|
|
|
|
+- `GET /api/v1/projects/{project}/collections/{name}/documents` - Find documents. Returns `{documents, count, has_more, total}`. Every row carries the same `_id`/`_version` metadata a single GET returns, so a filtered listing is a usable starting point for a conditional write without a second request per row.
|
|
|
|
|
+ **`count` is the PAGE size; `total` is the exact number of rows matching your filters.** Both `has_more` and `total` are new in 0.18.2 and are emitted unconditionally, so an absent field means an older server and never "nothing to report". `total` is computed by the database before pagination and is exact rather than an estimate - it is not capped by `limit`, and it answers a multi-field filter, which nothing else here can: `indexes/{field}/values` counts ONE field over the whole collection. Before 0.18.2 the only way to get this number was to page the entire matching set, and one consumer measured that as a full scan plus 1750 documents of encoding to obtain a single integer, which is why their review portal shipped without a result count.
|
|
|
|
|
+ **`limit` DOES NOT BOUND THE SERVER'S WORK, and the natural assumption is the opposite.** The database builds the whole match set, sorts it, and only then applies `offset`/`limit`, so `limit=20` and `limit=1000` scan identically. What `limit` saves is materialising and encoding the rows you did not ask for - which is real and is usually the whole cost (one consumer's queue screen went from 2.9 s to 453 ms by stopping at a page), but it means a narrow filter does not make a read cheaper and a small page is not a cheap query. Measured 2026-11-20 against a 13,093-row collection: the same predicate at `limit=1` and at `limit=1000` costs the same server-side.
|
|
|
|
|
+ **Omitting `limit` gives you 100 rows, not every row.** A sweep written without one stops at 100 and returns a clean short page, which is indistinguishable from a set that really holds 100 rows - so pass `limit` explicitly, and use `has_more` rather than a short page to decide whether to continue.
|
|
|
|
|
+ **A filter is index-accelerated only when it is genuinely selective, and "selective" means under ~10% of the collection.** Declaring an index does not make a filter on it cheap. The database picks, per VALUE rather than per field, the most selective indexed equality whose match count is under `rows/10`, and otherwise scans - because reading an index candidate costs a full document decode where a scan costs one parse, measured upstream at a ratio of ~8.6x, so a broad index plan is slower than scanning. It can also intersect two equalities, but only if the INTERSECTION clears the same bar. Worked example from prod: on 13,093 rows, `channel:eq:audio` matches 6,836 (52%) and `departmentKey:eq:ber` matches 3,520 (27%), so each is declined alone; together they match 1,750 (13.4%), which misses the 1,309-row threshold and is declined too, after paying to read and intersect 10,356 index entries. Filter ORDER is irrelevant - the planner measures each candidate's exact size first and takes the smallest - so there is nothing to tune by reordering. A field with few distinct values (a status, a boolean, a channel) will essentially never be index-served on its common values, only on its rare ones.
|
|
|
|
|
+ **`sort` sorts the entire match set, not your page.** Sorting a filter that matches 13,000 rows to show 20 of them is a 13,000-element sort on every request.
|
|
|
- `GET /api/v1/projects/{project}/collections/{name}/documents/{id}/delete-impact` - Preview what deleting this document would affect, without deleting it: `{would_be_blocked, impacts:[{relation, child_collection, child_field, on_delete, child_count, sample_child_ids, blocks}]}`. Read-only; follows the collection's read grant (a scoped key with a read rule may call it).
|
|
- `GET /api/v1/projects/{project}/collections/{name}/documents/{id}/delete-impact` - Preview what deleting this document would affect, without deleting it: `{would_be_blocked, impacts:[{relation, child_collection, child_field, on_delete, child_count, sample_child_ids, blocks}]}`. Read-only; follows the collection's read grant (a scoped key with a read rule may call it).
|
|
|
|
|
|
|
|
**Filter grammar**: `field:op:value`, repeatable and ANDed. On documents it is the `?filter=` query param; on vector search it is the `filters` body array. The same grammar, operators and semantics apply to both, because the database evaluates them.
|
|
**Filter grammar**: `field:op:value`, repeatable and ANDed. On documents it is the `?filter=` query param; on vector search it is the `filters` body array. The same grammar, operators and semantics apply to both, because the database evaluates them.
|
|
@@ -227,7 +233,13 @@ Requires a `kind=vector` collection. Vectors are stored with cosine-similarity i
|
|
|
All settings endpoints require an admin key.
|
|
All settings endpoints require an admin key.
|
|
|
|
|
|
|
|
- `GET /api/v1/settings` - Return current settings as JSON. `openai_api_key` is masked: the field is absent and `openai_api_key_set` (bool) indicates whether a key is configured.
|
|
- `GET /api/v1/settings` - Return current settings as JSON. `openai_api_key` is masked: the field is absent and `openai_api_key_set` (bool) indicates whether a key is configured.
|
|
|
-- `PUT /api/v1/settings` `{openai_api_base?, openai_api_key?, default_embedding_model?, cors_origins?, session_ttl_minutes?, webui_enabled?, default_project?, embedding_connect_timeout_sec?, embedding_read_timeout_sec?, embedding_cache_size?, embedding_cache_ttl_sec?, embedding_cache_max_bytes?, embedding_cache_normalize?, embedding_client_pool_size?, captcha_provider?, captcha_secret?, captcha_verify_url?}` - Merge the supplied fields into the current settings and persist. Omit `openai_api_key` or `captcha_secret` (or pass an empty string) to keep the existing secret. Changes are hot-reloaded immediately; cache settings are applied instantly via `reconfigure()`.
|
|
|
|
|
|
|
+- `PUT /api/v1/settings` `{openai_api_base?, openai_api_key?, default_embedding_model?, cors_origins?, session_ttl_minutes?, webui_enabled?, default_project?, embedding_connect_timeout_sec?, embedding_read_timeout_sec?, embedding_cache_size?, embedding_cache_ttl_sec?, embedding_cache_max_bytes?, embedding_cache_normalize?, embedding_client_pool_size?, captcha_provider?, captcha_secret?, captcha_verify_url?, client_ip_header?, client_ip_header_is_list?, trusted_proxy_cidrs?}` - Merge the supplied fields into the current settings and persist. Omit `openai_api_key` or `captcha_secret` (or pass an empty string) to keep the existing secret. Changes are hot-reloaded immediately; cache settings are applied instantly via `reconfigure()`.
|
|
|
|
|
+
|
|
|
|
|
+**Who the server thinks is calling** (`client_ip_header`, `client_ip_header_is_list`, `trusted_proxy_cidrs`). These decide the address a function policy's `ip_allow` is matched against, and the address written to the server's own access log. The rule that matters: a header is believed **only when the request arrived from an address in `trusted_proxy_cidrs`** - a header is text the client writes, so otherwise the caller would choose its own answer. Defaults are `X-Real-IP`, not-a-list, and loopback, which is what nginx in front of a loopback-bound vectorapi produces.
|
|
|
|
|
+- `client_ip_header: ""` reads no header at all and treats the peer address as the caller. That is the correct setting when nothing proxies the port.
|
|
|
|
|
+- `client_ip_header_is_list: true` for an `X-Forwarded-For` style header. The **last** element is used, not the first: nginx's `$proxy_add_x_forwarded_for` is "whatever the client sent, plus the real peer appended", so the first element is caller-controlled and only the last was vouched for by the proxy.
|
|
|
|
|
+- A `trusted_proxy_cidrs` entry that is not a CIDR range or bare address is refused with **422 `validation`** naming the entry, rather than dropped silently: a typo that disabled proxy trust would make every request appear to come from the proxy, which still looks like an address and so goes unnoticed.
|
|
|
|
|
+- **Getting these wrong refuses every caller of a function that uses `ip_allow`, not merely the wrong ones.** That is the deliberate fail-closed direction.
|
|
|
|
|
|
|
|
## Project embedding settings
|
|
## Project embedding settings
|
|
|
|
|
|
|
@@ -376,7 +388,8 @@ export default async function (ctx) {
|
|
|
- `GET /api/v1/projects/{project}/functions/{id}` - Get one function, **including** `source`.
|
|
- `GET /api/v1/projects/{project}/functions/{id}` - Get one function, **including** `source`.
|
|
|
- `PUT /api/v1/projects/{project}/functions/{id}` `{source, path?}` - Push code. The id the script declares must equal the id in the URL; a mismatch is **422** `id_mismatch` (with `error.details.declared` and `error.details.url`) rather than a rename, because the URL would otherwise move code onto another function's policy. A PUT to an unused id registers it (**201**).
|
|
- `PUT /api/v1/projects/{project}/functions/{id}` `{source, path?}` - Push code. The id the script declares must equal the id in the URL; a mismatch is **422** `id_mismatch` (with `error.details.declared` and `error.details.url`) rather than a rename, because the URL would otherwise move code onto another function's policy. A PUT to an unused id registers it (**201**).
|
|
|
- `DELETE /api/v1/projects/{project}/functions/{id}` - Delete the function, its code and its policy.
|
|
- `DELETE /api/v1/projects/{project}/functions/{id}` - Delete the function, its code and its policy.
|
|
|
-- `PUT /api/v1/projects/{project}/functions/{id}/policy` `{policy:{rules, origins?, rate_limit_per_min?, expires_at?}}` **(admin)** - Replace what the function may touch. Same vocabulary as a key scope (`rules` of `{collection, ops}` over `read`/`list`/`search`/`insert`/`update`/`delete`), with one difference: an **empty** rule set is legal and means the function reaches nothing. This is the only route that changes a policy.
|
|
|
|
|
|
|
+- `PUT /api/v1/projects/{project}/functions/{id}/policy` `{policy:{rules, origins?, ip_allow?, rate_limit_per_min?, expires_at?}}` **(admin)** - Replace what the function may touch. Same vocabulary as a key scope (`rules` of `{collection, ops}` over `read`/`list`/`search`/`insert`/`update`/`delete`), with one difference: an **empty** rule set is legal and means the function reaches nothing. This is the only route that changes a policy.
|
|
|
|
|
+ - `ip_allow` (array of CIDR ranges or bare addresses, default empty = no restriction) pins the function to caller addresses. **It fails closed**: a non-empty list refuses any request whose address the server could not establish, so a wrong `trusted_proxy_cidrs` refuses everyone rather than the wrong ones. A malformed entry is refused at write time with 422 `validation`; one that somehow reached storage removes only itself and never widens the list. Checked **before** authentication and before the rate limit, so a refused caller cannot spend the function's minute budget - and the refusal writes **no run-log row**, because nothing ran.
|
|
|
- `PUT /api/v1/projects/{project}/functions/{id}/enabled` `{enabled}` - Enable or disable a function.
|
|
- `PUT /api/v1/projects/{project}/functions/{id}/enabled` `{enabled}` - Enable or disable a function.
|
|
|
- `POST /api/v1/projects/{project}/functions/{id}/invoke` `{method?, path?, params?, query?, headers?, body?}` - Run the function once and record the run. Every field is optional: an empty body invokes it with its declared route as the path and `POST` as the method.
|
|
- `POST /api/v1/projects/{project}/functions/{id}/invoke` `{method?, path?, params?, query?, headers?, body?}` - Run the function once and record the run. Every field is optional: an empty body invokes it with its declared route as the path and `POST` as the method.
|
|
|
**THE BODY IS AN ENVELOPE DESCRIBING THE REQUEST TO SYNTHESISE, NOT THE FUNCTION'S PAYLOAD - and getting that wrong used to answer 200.** A payload goes under `body`:
|
|
**THE BODY IS AN ENVELOPE DESCRIBING THE REQUEST TO SYNTHESISE, NOT THE FUNCTION'S PAYLOAD - and getting that wrong used to answer 200.** A payload goes under `body`:
|
|
@@ -398,6 +411,11 @@ export default async function (ctx) {
|
|
|
- The key is used for the gate and is **not** forwarded to the function - `Authorization` has always been stripped - so a function cannot see, log or reuse the caller's credential.
|
|
- The key is used for the gate and is **not** forwarded to the function - `Authorization` has always been stripped - so a function cannot see, log or reuse the caller's credential.
|
|
|
- **A key-gated function (`auth: 'key'`) AUTHENTICATES the caller and grants them NOTHING - so send your LEAST privileged key, not one scoped to the collections the function reads.** The function still reads and writes under its own stored policy, exactly as it does when public; the key only answers "may this caller invoke the route at all". A key with an empty rule set works and is the right choice. Worth stating because the natural guess is the opposite - that a function reading `kb_facts` needs a caller key carrying `search` on `kb_facts` - and guessing that way over-grants a credential that is, by design, going into a third-party tool configuration. Reported by a consumer who used a least-privileged key, found it worked, and pointed out that nothing said so.
|
|
- **A key-gated function (`auth: 'key'`) AUTHENTICATES the caller and grants them NOTHING - so send your LEAST privileged key, not one scoped to the collections the function reads.** The function still reads and writes under its own stored policy, exactly as it does when public; the key only answers "may this caller invoke the route at all". A key with an empty rule set works and is the right choice. Worth stating because the natural guess is the opposite - that a function reading `kb_facts` needs a caller key carrying `search` on `kb_facts` - and guessing that way over-grants a credential that is, by design, going into a third-party tool configuration. Reported by a consumer who used a least-privileged key, found it worked, and pointed out that nothing said so.
|
|
|
**Order the rollout header-first.** Put the `Authorization` header into the calling tool, confirm it works against the still-ungated route, and only then set `auth: 'key'`. Reversed, the route answers 401 for however long it takes someone to notice - and in front of an assistant or voice agent that presents as "it does not know anything" rather than as an auth failure.
|
|
**Order the rollout header-first.** Put the `Authorization` header into the calling tool, confirm it works against the still-ungated route, and only then set `auth: 'key'`. Reversed, the route answers 401 for however long it takes someone to notice - and in front of an assistant or voice agent that presents as "it does not know anything" rather than as an auth failure.
|
|
|
|
|
+- **A function policy may pin the route to caller ADDRESSES** (`ip_allow`, 0.18.2+). Outside the list is **403** `ip_not_allowed`. Four properties, none of them guessable:
|
|
|
|
|
+ - **It is checked FIRST**, ahead of the `auth: 'key'` gate and ahead of the rate limit. So a caller who is not permitted to be here cannot spend the function's minute budget, and cannot have a token checked.
|
|
|
|
|
+ - **The refusal writes NO run-log row**, because nothing ran. That matters if you currently gate a public function with a token compared inside the script: a script-side check RUNS the function first, so every wrong-token request appends a row to your own run log, and a sustained flood evicts your real runs. An address gate refuses before the runner is involved.
|
|
|
|
|
+ - **It fails closed.** A non-empty list refuses any request whose address the server could not establish, so a wrong `trusted_proxy_cidrs` in global settings refuses *everyone* rather than the wrong ones.
|
|
|
|
|
+ - **The message does not echo your address back.** It is in the server's own access log for an operator to read; reflecting it would hand a prober a free "what do you think my address is" oracle. Ask an operator rather than guessing from the response.
|
|
|
- **The function's `rate_limit_per_min` policy now applies to CALLS on this route** (since 0.15.0), not only to the function's data access. `0` means unlimited, as everywhere else. Over the ceiling is **429** `rate_limited` with `Retry-After: 60`. Three things worth knowing:
|
|
- **The function's `rate_limit_per_min` policy now applies to CALLS on this route** (since 0.15.0), not only to the function's data access. `0` means unlimited, as everywhere else. Over the ceiling is **429** `rate_limited` with `Retry-After: 60`. Three things worth knowing:
|
|
|
- **The two ceilings are counted SEPARATELY against the same number.** A limit of 60 means up to 60 calls a minute AND up to 60 data operations a minute; it does not mean a function doing three reads per call gets 15 calls. Adding a read to a script therefore cannot lower its own request ceiling.
|
|
- **The two ceilings are counted SEPARATELY against the same number.** A limit of 60 means up to 60 calls a minute AND up to 60 data operations a minute; it does not mean a function doing three reads per call gets 15 calls. Adding a read to a script therefore cannot lower its own request ceiling.
|
|
|
- **The ceiling is per FUNCTION, not per caller.** It bounds the DAMAGE - mail sent, paid API calls made, on the tenant's quota and sender reputation - rather than the denial: one abusive caller can still exhaust a public function's minute and shut out legitimate ones. Per-caller limiting needs an identity, which is what `auth: 'key'` gives you and an anonymous request does not have.
|
|
- **The ceiling is per FUNCTION, not per caller.** It bounds the DAMAGE - mail sent, paid API calls made, on the tenant's quota and sender reputation - rather than the denial: one abusive caller can still exhaust a public function's minute and shut out legitimate ones. Per-caller limiting needs an identity, which is what `auth: 'key'` gives you and an anonymous request does not have.
|