Canonical formats and semantics for agents
This reference is checked against ekoDB v0.87.0 and ekodb-client v0.37.0. Read the installed server's version before applying compatibility notes. Use scoped credentials for the task; changing instance configuration is an administrator action.
Values and native objects
With use_typed_values: true (the server default), record fields in responses carry type metadata, for example {"type":"String","value":"Ada"}. Plain mode returns ordinary JSON values. Use SDK extraction helpers rather than assuming every response is in one mode. The primary key is returned as an opaque string; keep the returned value for subsequent requests.
Ordinary JSON is accepted on writes. Object fields store nested objects, arrays and arrays of objects. Array fields store arrays, including arrays of objects. Booleans remain booleans. For example, this record needs no stringified JSON, json wrapper or stringified boolean:
{
"name": "Ada",
"active": true,
"profile": { "preferences": { "alerts": true }, "labels": ["reader"] },
"items": [{ "sku": "A-100", "quantity": 2 }]
}
A top-level array cannot be written into a field already typed Object; use an Array field or put the array under an object key.
The envelope {"type":"<ekoDB type>","value":...} is also input syntax for explicitly typed values. Never use that shape for an application object: the server can interpret it as a typed value. Choose application keys such as kind and payload instead. Use explicit envelopes for ambiguous types such as UUID, DateTime, Decimal, Vector and Binary; a raw UUID-looking string is a String on write.
Binary values and transport paths
For JSON, a binary field can be written as {"type":"Binary","value":"SGVsbG8="} (base64) or with a byte array as its value. Bytes also accepts byte arrays. A filename or filesystem path is a string, not an uploaded file. Read the bytes in the application and encode them for the chosen transport.
JSON and MessagePack are transport encodings, separate from a field's Binary type. The v0.37.0 TypeScript client uses MessagePack on the insert/update/delete paths, including their batch variants, and JSON on other paths. Let the SDK set Content-Type; do not send base64 text as an entire MessagePack request body. Data types and client transport selection define these two layers.
Schemaless writes still pin types
The first value written for a new field establishes its schema type. Later incompatible types are refused. A first value of null records the type Null; that type accepts later values without enforcing a concrete type. Omit an unknown field until it has a real value, or declare its type when creating the collection. Explicit null is allowed for an already typed field.
PUT /api/schemas/{collection} changes constraints on existing fields; it does not introduce a field. First insert a record carrying the new field, or declare the field in the collection's initial schema. The body is {"constraints":{"field_name":{...}}}.
On the pinned v0.87.0 server, each constraint entry is a partial update: omitted keys are preserved. null clears default, min, max or regex; enums: [] clears the enum restriction. Unknown keys are refused. Older servers replaced the supplied field's constraints and required unique, required and enums: when targeting that contract, read the schema and send every constraint to retain. Do not apply the older replacement rule to the pinned server. See the collection reference.
Use unique: true for uniqueness. An absent field is skipped by uniqueness checking; an explicit null participates. Test the intended null/absence policy before importing data. A transactional unique violation is reported at commit, not necessarily when the write is staged.
Filters are an AST
filter is a tagged Condition or Logical expression, not a MongoDB operator object. Operators and type tags are case-sensitive. A query body is:
{
"filter": {
"type": "Logical",
"content": {
"operator": "And",
"expressions": [
{ "type": "Condition", "content": { "field": "active", "operator": "Eq", "value": true } },
{ "type": "Condition", "content": { "field": "items.0.sku", "operator": "Eq", "value": "A-100" } }
]
}
},
"sort": [{ "field": "name", "ascending": true }],
"limit": 25
}
And/Or contain expressions; Not takes one expression in that array. Dotted paths reach nested objects, and numeric segments index arrays: profile.preferences.alerts, items.0.sku. Address the stored field directly, without adding .value for response envelopes. Avoid dots, commas and colons in application field names.
Use findById or a Condition on id with the exact returned ID; do not substitute _id, decode encrypted IDs or invent an ID from another field. A configured primary-key alias changes the returned key name; read the schema and preserve it. Query expressions gives the full operator list and projection options.
Limits, paging and absent resources
| Request | Contract |
|---|---|
REST find or WebSocket Query, omitted limit | default_query_limit, normally 1,000, bounded by the instance's max_query_limit |
Explicit limit above max_query_limit | Refused, not clamped; REST returns 400 |
skip above max_query_skip | Refused; REST returns 400 |
limit: 0 | All matches only if they fit max_unpaginated_records; overflow is an error, never silent truncation |
| Chat session/message lists | Their own limit/skip; the 1,000-record find default does not apply |
The ceilings depend on instance memory or administrator overrides. Always pass a bounded explicit limit. For deep paging, keep a cursor in the application using a stable, unique sort field and a Gt filter on the last value. Use a tie-breaker when sort values can repeat. Do not invent a REST cursor parameter or increase skip indefinitely. See limits and paging.
| Missing resource | HTTP result |
|---|---|
find on a never-written collection | 200 with [] |
search on a never-written collection | 200 with results: [] and total: 0 in the search response object |
findById for a missing record | 404 |
deleteCollection for a missing collection | 404 |
kvGet for a missing key | 404 |
kvDelete for a missing key | Idempotent 200 |
An authentication, permission, validation or transport failure is an error. Never catch every error and turn it into an empty result.
TTL belongs to the record
default_ttl applies to KV keys only, never to collection records. Record insert, update and each record in batchInsert can carry ttl, for example "30s", "5m", "1h", "30d", integer seconds or a future RFC3339 timestamp.
On update, omitting ttl preserves the existing expiry. A supplied valid TTL sets a new expiry. ttl: null, an invalid TTL or a time in the past is refused; an update cannot clear expiry by sending null. Keep TTL as a top-level record directive, not inside an application object's metadata. See record directives.
Stored-function stages
Define parameters under parameters, pass values when calling the function, and use "{{param}}" in its definition. This is server substitution, not client-side string interpolation. A Query has inline filter, sort, limit and skip; it has no join. Use an SDK find with JoinBuilder when a join is needed.
This non-transactional function counts every active record:
{
"label": "count_active",
"name": "Count active records",
"parameters": { "active": { "required": false, "default": true } },
"functions": [
{
"type": "Query",
"collection": "agent_tasks",
"filter": { "type": "Condition", "content": { "field": "active", "operator": "Eq", "value": "{{active}}" } }
},
{ "type": "Count", "output_field": "count" }
]
}
Count replaces the working set with one record containing count; read records[0].count from the function result, using the SDK's value helper if wrapped. It does not add a field to each input row. An immediately adjacent Query + Count, with no limit or skip and a literal count output field, uses count_matching over all matches without loading them or applying the client 1,000-record default. Otherwise Count counts the current working set.
Query.limit and Query.skip accept parameter placeholders. A placeholder that remains unresolved can remain literal text; declare parameters and defaults, and exercise each function with test arguments. See parameter semantics.
| Stage / mode | Rule |
|---|---|
Upsert | Match by key/value, then update or insert record; lookup and write need concurrency protection when callers can race |
| Transactional functions | Support Insert, Update, Delete, savepoints and SWR; Upsert and arbitrary read/control-flow stages are not supported |
LockAcquire | Writes records[0].<output_field> with acquired and, on success, a fencing token; it does not wait for a busy lock |
RateLimit | Writes records[0].<output_field> with allowed, count, limit and window_secs when the stage returns; default on_exceed: "fail" fails the call above the limit |
LockAcquire and RateLimit write their output directly, creating a working record if needed; no Return stage is needed to expose it. Lock keys are lock:<key>; rate keys are rate:<key>:<bucket>. Grant KV writes on the corresponding lock: / rate: resources. Pass the logical key to RateLimit: it prepends rate: automatically. Branch on acquired before performing protected work, and release the lock with its returned token. These stages do not make Upsert valid inside a transactional function. See function results and chaining.
Transaction failures: Conflict versus Apply
Commit failures must be classified before retrying. A conflict consumes the transaction: begin a new transaction and repeat the whole read/write operation with a bounded retry policy.
| Pinned v0.87.0 commit response | Action |
|---|---|
409, retryable: true, Conflict(...) | Retry the complete transaction with fresh reads |
400, retryable: false, invalid write / constraint | Correct the request or data |
500, retryable: false, store failure | Surface the failure; do not loop on the same commit |
404, transaction missing | Do not retry the consumed transaction ID |
Older servers can report both Conflict(...) and Apply("...") as 409. Apply is not evidence of a concurrency conflict; a constraint failure needs corrected data, regardless of an older retryable flag. Never retry solely because the status is 409. The v0.37.0 clients preserve transaction errors (including Transaction error (409) in Rust/Python) and do not automatically re-send commit operations. See error codes and transactions.
Choose a surface
- SDK references: TypeScript, Python, Rust, Go, Kotlin.
- REST API for direct HTTP requests.
- ekodb-cli for the implemented command verbs and JSON output.
- MCP and human approvals for hosted agent tools.