v1

latestOpenAPI 3.1.02026-07-13154170539.0 KB
Logs

Atomic Field Upsert

Atomic find-or-create with atomic field update (upsert mode).

This endpoint atomically:

  1. Ensures the context exists with correct unique_keys configuration
  2. Acquires an advisory lock on the unique key values (prevents race on first insert)
  3. Finds an existing log by unique_keys or creates it with initial_data
  4. Applies an atomic operation to the specified field
  5. If add_to_all_context=true, mirrors the log to the All/* archive context

Required body fields for upsert mode:

  • project: Name of the project
  • context: Context path for the log
  • unique_keys: Key name to type mapping (e.g., {"_assistant_id": "str", "month": "str"})
  • initial_data: Data for new log entry (must include all unique key values)
  • operation: Atomic operation (+N, -N, *N, /N)

This is race-safe for concurrent first inserts - only one request will create the log, and all concurrent requests will correctly increment the field.

post/v0/logs/atomic

Request body

operationstring required

Atomic operation to apply. Supported formats: +N, -N, *N, /N where N is a number.

fieldstring nullable

(Upsert mode) Name of the numeric field to update atomically.

projectstring nullable

(Upsert mode) Name of the project.

contextstring nullable

(Upsert mode) Context path for the log.

unique_keysobject nullable

(Upsert mode) Unique key configuration for the context. Maps key names to types (str, int, float).

initial_dataobject nullable

(Upsert mode) Data to use when creating a new log entry. Must include all unique key values.

add_to_all_contextboolean

(Upsert mode) If true, also adds the log to the 'All/*' archive context.

Example request

{
  "operation": "+1",
  "field": "cumulative_spend",
  "project": "Assistants",
  "context": "42/7/Spending/Monthly",
  "unique_keys": {
    "_assistant_id": "str",
    "month": "str"
  },
  "initial_data": {
    "_assistant_id": "123",
    "_org_id": 456,
    "month": "2026-01"
  }
}

Response

Atomic upsert applied successfully

new_valuenumber required

The new value of the field after the operation.

log_idinteger nullable

ID of the log entry (included in upsert mode).

createdboolean nullable

True if a new log was created (upsert mode only).

mirrored_contextsstring[] nullable

List of archive contexts the log was mirrored to (upsert mode only).