> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kairn.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Invoke an agent

> Run an agent for a user. Returns a full JSON response by default. Set `stream: true` or `Accept: text/event-stream` to receive a streaming SSE response instead.



## OpenAPI

````yaml POST /v1/agent/invoke
openapi: 3.1.0
info:
  title: Kairn API
  version: 1.0.0
  description: >-
    The Kairn API. All requests require an `X-API-Key` header with your tenant
    API key.
servers:
  - url: https://api.kairn.sh
    description: Production
security:
  - ApiKey: []
tags:
  - name: Agent
    description: Invoke agents and stream responses.
  - name: Memory
    description: Read and write per-user agent memory.
  - name: Souls
    description: Manage agent identities.
  - name: Skills
    description: Manage custom skills (instructions and webhook tools).
  - name: Mandates
    description: Schedule autonomous agent tasks.
  - name: Invocations
    description: Inspect past agent runs.
  - name: Sessions
    description: Access multi-turn conversation history.
  - name: Audit
    description: Audit log for all agent activity.
paths:
  /v1/agent/invoke:
    post:
      tags:
        - Agent
      summary: Invoke an agent
      description: >-
        Run an agent for a user. Returns a full JSON response by default. Set
        `stream: true` or `Accept: text/event-stream` to receive a streaming SSE
        response instead.
      operationId: invoke
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InvokeRequest'
      responses:
        '200':
          description: >-
            Invocation completed. Returns JSON or SSE stream depending on
            request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvokeResponse'
            text/event-stream:
              schema:
                type: string
                description: >-
                  Server-sent events stream. Event types: `token`, `tool_start`,
                  `tool_end`, `memory_delta`, `done`, `error`.
        '400':
          description: Invalid request body.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '422':
          description: Soul not found or invalid configuration.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Rate limit or monthly quota exceeded.
          headers:
            Retry-After:
              schema:
                type: integer
              description: Seconds until the limit resets.
            X-RateLimit-Remaining:
              schema:
                type: integer
            X-Plan-Remaining:
              schema:
                type: integer
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '502':
          description: LLM provider error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '504':
          description: Agent invocation timed out.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    InvokeRequest:
      type: object
      required:
        - user_id
        - soul
        - input
      properties:
        user_id:
          type: string
          description: Your user's ID. Scopes memory and session to this user.
          example: user_123
        soul:
          type: string
          description: The soul name to invoke.
          example: support
        role:
          type: string
          default: default
          description: Memory and session scope within the user. Defaults to `default`.
        input:
          type: string
          description: The user's message or task input.
          example: My invoice looks wrong.
        session_id:
          type: string
          description: >-
            Session ID for multi-turn conversation continuity. Omit for a
            stateless invocation.
          example: chat_abc123
        stream:
          type: boolean
          description: >-
            Set `true` to receive a streaming SSE response. Alternatively, send
            `Accept: text/event-stream`.
    InvokeResponse:
      type: object
      properties:
        invocation_id:
          type: string
          description: Unique ID for this invocation.
          example: a1b2c3d4-...
        output:
          type: string
          description: The agent's final text response.
        memory_delta:
          type: object
          additionalProperties:
            type: string
          description: Memory keys written during this turn.
        tool_calls:
          type: array
          items:
            $ref: '#/components/schemas/ToolCall'
        tokens_input:
          type: integer
        tokens_output:
          type: integer
        duration_ms:
          type: integer
        session_id:
          type: string
        status:
          type: string
          enum:
            - completed
            - failed
    Error:
      type: object
      properties:
        error:
          type: string
        error_type:
          type: string
    ToolCall:
      type: object
      properties:
        name:
          type: string
        input:
          type: object
        result_summary:
          type: string
        duration_ms:
          type: integer
  securitySchemes:
    ApiKey:
      type: apiKey
      in: header
      name: X-API-Key

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.