Skip to main content
SONZAI
Api

Sessions

End a chat session

POST
/agents/{agentId}/sessions/end
AuthorizationBearer <token>

API key issued to a Sonzai project. Format: Bearer sk_....

In: header

Path Parameters

agentId*string

Agent UUID or URL-encoded agent name

Query Parameters

force_sync?boolean

Force the legacy synchronous inline path regardless of the server's ENABLE_ASYNC_SESSION_END setting. Used by benchmarks that must read memory immediately after session-end.

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/problem+json

curl -X POST "https://loading/api/v1/agents/string/sessions/end" \  -H "Content-Type: application/json" \  -d '{    "duration_seconds": 0,    "session_id": "string",    "total_messages": 0,    "user_id": "string"  }'
{
  "$schema": "/api/v1/schemas/EndSessionOutputBody.json",
  "agent_id": "string",
  "async": true,
  "enqueued_at": "string",
  "processing_id": "string",
  "session_id": "string",
  "status_url": "string",
  "success": true
}
{
  "$schema": "/api/v1/schemas/ErrorModel.json",
  "detail": "Property foo is required but is missing.",
  "errors": [
    {
      "location": "string",
      "message": "string",
      "value": null
    }
  ],
  "instance": "https://example.com/error-log/abc123",
  "status": 400,
  "title": "Bad Request",
  "type": "https://example.com/errors/example"
}

Start a chat session

POST
/agents/{agentId}/sessions/start
AuthorizationBearer <token>

API key issued to a Sonzai project. Format: Bearer sk_....

In: header

Path Parameters

agentId*string

Agent UUID or URL-encoded agent name

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/problem+json

curl -X POST "https://loading/api/v1/agents/string/sessions/start" \  -H "Content-Type: application/json" \  -d '{    "session_id": "string",    "user_id": "string"  }'
{
  "$schema": "/api/v1/schemas/StartSessionOutputBody.json",
  "success": true
}
{
  "$schema": "/api/v1/schemas/ErrorModel.json",
  "detail": "Property foo is required but is missing.",
  "errors": [
    {
      "location": "string",
      "message": "string",
      "value": null
    }
  ],
  "instance": "https://example.com/error-log/abc123",
  "status": 400,
  "title": "Bad Request",
  "type": "https://example.com/errors/example"
}

Set session tool definitions

PUT
/agents/{agentId}/sessions/{sessionId}/tools
AuthorizationBearer <token>

API key issued to a Sonzai project. Format: Bearer sk_....

In: header

Path Parameters

agentId*string

Agent UUID or URL-encoded agent name

sessionId*string

Session identifier

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

JSON array of tool definitions

Response Body

application/json

application/problem+json

curl -X PUT "https://loading/api/v1/agents/string/sessions/string/tools" \  -H "Content-Type: application/json" \  -d '[    {      "name": "string"    }  ]'
{
  "$schema": "/api/v1/schemas/SetSessionToolsOutputBody.json",
  "success": true
}
{
  "$schema": "/api/v1/schemas/ErrorModel.json",
  "detail": "Property foo is required but is missing.",
  "errors": [
    {
      "location": "string",
      "message": "string",
      "value": null
    }
  ],
  "instance": "https://example.com/error-log/abc123",
  "status": 400,
  "title": "Bad Request",
  "type": "https://example.com/errors/example"
}

Poll async session-end processing status

GET
/sessions/end/status/{processingId}
AuthorizationBearer <token>

API key issued to a Sonzai project. Format: Bearer sk_....

In: header

Path Parameters

processingId*string

UUID returned by POST /sessions/end when the server is in async=true mode.

Response Body

application/json

application/problem+json

curl -X GET "https://loading/api/v1/sessions/end/status/string"
{
  "$schema": "/api/v1/schemas/SessionEndStatusOutputBody.json",
  "agent_id": "string",
  "attempt": 0,
  "enqueued_at": "string",
  "error": "string",
  "finished_at": "string",
  "session_id": "string",
  "started_at": "string",
  "state": "string"
}
{
  "$schema": "/api/v1/schemas/ErrorModel.json",
  "detail": "Property foo is required but is missing.",
  "errors": [
    {
      "location": "string",
      "message": "string",
      "value": null
    }
  ],
  "instance": "https://example.com/error-log/abc123",
  "status": 400,
  "title": "Bad Request",
  "type": "https://example.com/errors/example"
}