Skip to main content
PATCH
/
v0
/
logs
/
{log_id}
/
fields
/
{field_name}
/
atomic
curl --request PATCH \
  --url 'https://api.unify.ai/v0/logs/<log_id>/fields/<field_name>/atomic' \
  --header "Authorization: Bearer $UNIFY_KEY"
  --header 'Content-Type: application/json' \
  --data '{
    "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"
    }
}'
{
    "new_value": 42.0
}
Apply an atomic operation to a numeric field in a log entry. This endpoint performs race-safe atomic updates directly in PostgreSQL, ensuring correct results even under high concurrent load. Supported operations:
  • +N: Add N to the current value
  • -N: Subtract N from the current value
  • *N: Multiply the current value by N
  • /N: Divide the current value by N
If the field doesn’t exist or is NULL, it is treated as 0 before the operation.

Authorizations

Authorization
string
required
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

log_id
integer
required
The ID of the log to update
field_name
string
required
The name of the field to update atomically

Body

operation
string
required
Atomic operation to apply. Supported formats: +N, -N, *N, /N where N is a number.
field
string | null
(Upsert mode) Name of the numeric field to update atomically.
project
string | null
(Upsert mode) Name of the project.
context
string | null
(Upsert mode) Context path for the log.
unique_keys
object | null
(Upsert mode) Unique key configuration for the context. Maps key names to types (str, int, float).
initial_data
object | null
(Upsert mode) Data to use when creating a new log entry. Must include all unique key values.
add_to_all_context
boolean
default:"false"
(Upsert mode) If true, also adds the log to the ‘All/*’ archive context.
curl --request PATCH \
  --url 'https://api.unify.ai/v0/logs/<log_id>/fields/<field_name>/atomic' \
  --header "Authorization: Bearer $UNIFY_KEY"
  --header 'Content-Type: application/json' \
  --data '{
    "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"
    }
}'
{
    "new_value": 42.0
}