Sessions

Create a session

Creates a new session for the specified agent, along with the underlying conversation, so the caller only needs this single call to start interacting with the agent. No actor is created: pass actor_id to attach an existing actor as the session's end user. When it is omitted the session has no actor, and generations in it carry no end-user attribution — they are not billed to an actor in the usage meter and they match no actor-scoped quota.

post/v1/projects/{project_id}/sessions

Request

  • Base URL: https://api.naturali.ai
  • URL: https://api.naturali.ai/v1/projects/{project_id}/sessions
  • Auth: one of:
    • HTTP bearer
    • OAuth 2 (authorization code, authorization URL https://api.naturali.ai/authorize, token URL https://api.naturali.ai/token, scopes: mcp:access)

Request body

agent_idstring required

Agent this session belongs to. With a credential scoped to a project, it may also be an agent another project shares with that project; the session is then that project's.

namestring

Optional session name

tagsTagBag

Key-value labels on a resource. A flat object of string values — an array, a nested object or a number is rejected with 400 VALIDATION_FAILED, never coerced. Keys are opaque and stored verbatim, so cost_center and costCenter are two different tags. Matched by JSONB containment wherever tags are read: the ?tags= filter and knowledge search.

Keys beginning system. are reserved: the platform writes them to record which conversation, actor, agent and role a row came from, and a write naming one is refused with 400 RESERVED_TAG_KEY. They are read and filtered like any other tag.

The bag is bounded, because every pair reaches the IAM context of every access check on the resource: at most 50 keys, each key at most 128 characters and each value at most 256. A write past a bound — including a merge that would grow the stored bag past the key count — is 400 VALIDATION_FAILED with meta.limit naming the bound it crossed. system.* keys are the platform's and do not count against the 50.

actor_idstring

Optional public ID of an existing actor to use as the user actor. Actors are created separately (POST /actors); this field only links one. Omit it and the session has no end user, so its generations match no actor-scoped quota.

auto_generateboolean

When true, automatically triggers generation after each user message.

tool_contextobject nullable

Key-value pairs forwarded as X-Naturali-Context-<key> headers on every http and mcp tool call in this session. The header name is the deployment's configured context prefix (X-Naturali-Context- by default) plus the key verbatim — no character is re-cased. Keys are stored exactly as sent and never case-converted. A key that is not a valid HTTP header name, or two keys that map to the same header, are rejected with 400 INVALID_TOOL_CONTEXT_KEY. session_id, actor_id and actor_external_id are server-derived and dropped from the stored bag, in any casing. Write-only: no read of a session returns it. It also does not outlive the session: closing or expiring it clears the bag.

inactivity_ttl_secondsinteger

Number of seconds of inactivity after which the session expires. 0 means the session never expires.

message_delay_secondsinteger nullable

Number of seconds to wait after the last user message before sending to the LLM. Acts as a debounce: each new message resets the timer. null or absent means no delay (immediate processing).

max_context_messagesinteger nullable

Maximum number of recent conversation messages sent to the model on each generation, taking precedence over the agent's max_context_messages. null or absent defers to the agent.

Example request

{
  "agent_id": "agent_V1StGXR8Z5jdHi6B",
  "name": "Support chat",
  "tags": {
    "team": "finance",
    "env": "prod"
  },
  "actor_id": "actor_V1StGXR8Z5jdHi6B",
  "inactivity_ttl_seconds": 300,
  "message_delay_seconds": 3,
  "max_context_messages": 20
}

Response

Session created

idstring

Session public ID

agent_idstring

Agent public ID, kept after a shared agent is deleted by its owner.

conversation_idstring

Underlying conversation public ID

status'open' | 'closed' | 'expired'
namestring nullable
actor_idstring nullable

Public ID of the user actor, or null when the session was created without one

tagsTagBag

Key-value labels on a resource. A flat object of string values — an array, a nested object or a number is rejected with 400 VALIDATION_FAILED, never coerced. Keys are opaque and stored verbatim, so cost_center and costCenter are two different tags. Matched by JSONB containment wherever tags are read: the ?tags= filter and knowledge search.

Keys beginning system. are reserved: the platform writes them to record which conversation, actor, agent and role a row came from, and a write naming one is refused with 400 RESERVED_TAG_KEY. They are read and filtered like any other tag.

The bag is bounded, because every pair reaches the IAM context of every access check on the resource: at most 50 keys, each key at most 128 characters and each value at most 256. A write past a bound — including a merge that would grow the stored bag past the key count — is 400 VALIDATION_FAILED with meta.limit naming the bound it crossed. system.* keys are the platform's and do not count against the 50.

auto_generateboolean

When true, automatically triggers generation after each user message (if no generation is in progress).

generating_atstring date-time nullable

Timestamp when the current generation started, or null if not generating.

created_atstring date-time
updated_atstring date-time
inactivity_ttl_secondsinteger

Number of seconds of inactivity after which the session expires. 0 means the session never expires.

message_delay_secondsinteger nullable

Number of seconds to wait after the last user message before sending to the LLM. Acts as a debounce: each new message resets the timer. null or absent means no delay (immediate processing).

max_context_messagesinteger nullable

Maximum number of recent conversation messages sent to the model on each generation. Takes precedence over the agent's max_context_messages; null defers to it. A fork keeps its parent's value.

last_activity_atstring date-time nullable

Timestamp of the last activity on the session (message added or response generated).

forked_from_session_idstring nullable

Public ID of the session this one was forked from, or null when it was not forked. Also null once that parent is deleted — a fork survives its parent and keeps its own history.

forked_from_positioninteger nullable

The parent conversation position this session branched after, or null when it is not a fork or was forked at the tip.

Example response

{
  "id": "sess_V1StGXR8Z5jdHi6B",
  "agent_id": "agent_V1StGXR8Z5jdHi6B",
  "conversation_id": "conv_V1StGXR8Z5jdHi6B",
  "status": "open",
  "name": "Support chat",
  "actor_id": "actor_V1StGXR8Z5jdHi6B",
  "tags": {
    "team": "finance",
    "env": "prod"
  },
  "inactivity_ttl_seconds": 300,
  "message_delay_seconds": 3,
  "max_context_messages": 20,
  "forked_from_session_id": "sess_V1StGXR8Z5jdHi6B",
  "forked_from_position": 7
}

Changes

No recorded changes to this operation across all 1 revision of this API.