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

# Create Session Chat

> Creates a new chat inside the given session. Callers may pass `{ id }` to claim a deterministic chat id — useful for optimistic UI flows where the client generates the id locally and then persists it. If a chat with that id already exists in **this** session the call is idempotent and returns the existing row; if it exists in **another** session, 409 is returned.



## OpenAPI

````yaml api-reference/openapi/sessions.json POST /api/sessions/{sessionId}/chats
openapi: 3.1.0
info:
  title: Recoup API - Sessions
  description: >-
    Sessions — sandboxed runs of an LLM-driven agent with tool use, lifecycle
    hooks, and persistence. Each session pairs one Vercel Sandbox with one or
    more chat threads.
  license:
    name: MIT
  version: 1.0.0
servers:
  - url: https://api.recoupable.dev
security:
  - ApiKeyAuth: []
  - BearerAuth: []
paths:
  /api/sessions/{sessionId}/chats:
    post:
      summary: Create session chat
      description: >-
        Creates a new chat inside the given session. Callers may pass `{ id }`
        to claim a deterministic chat id — useful for optimistic UI flows where
        the client generates the id locally and then persists it. If a chat with
        that id already exists in **this** session the call is idempotent and
        returns the existing row; if it exists in **another** session, 409 is
        returned.
      parameters:
        - name: sessionId
          in: path
          required: true
          description: The id of the parent session.
          schema:
            type: string
      requestBody:
        required: false
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSessionChatRequest'
      responses:
        '200':
          description: >-
            Chat created, or existing chat returned (idempotent on same-session
            reuse).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateSessionChatResponse'
        '400':
          description: >-
            Invalid chat id — body contained `id` but it was an empty string or
            not a string.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/InvalidChatIdError'
        '401':
          description: Unauthorized — invalid or missing API key / Bearer token.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: Forbidden — the authenticated account does not own this session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '404':
          description: Not found — no session exists with the given id.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: >-
            Chat id conflict — a chat with the requested id already exists on a
            different session.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatIdConflictError'
        '500':
          description: Server error — the chat could not be persisted.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CreateSessionChatRequest:
      type: object
      description: >-
        Body for `POST /api/sessions/{sessionId}/chats`. Both an empty body and
        an omitted body are valid.
      properties:
        id:
          type: string
          minLength: 1
          description: >-
            Optional client-supplied chat id (used for optimistic UI flows).
            When omitted, the server generates a UUID. When supplied, must be a
            non-empty string.
    CreateSessionChatResponse:
      type: object
      required:
        - chat
      properties:
        chat:
          $ref: '#/components/schemas/Chat'
    InvalidChatIdError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          enum:
            - Invalid chat id
    Error:
      type: object
      required:
        - status
        - error
      properties:
        status:
          type: string
          enum:
            - error
          description: Always `"error"` for error responses.
        error:
          type: string
          description: Human-readable error message.
    ChatIdConflictError:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          enum:
            - Chat ID conflict
    Chat:
      type: object
      required:
        - id
        - sessionId
        - title
        - modelId
        - createdAt
        - updatedAt
      properties:
        id:
          type: string
          description: Chat id (nanoid).
        sessionId:
          type: string
          description: Owning session id.
        title:
          type: string
          description: >-
            Display title for the chat. The initial chat created with a session
            is titled `New chat`.
        modelId:
          type: string
          description: >-
            AI Gateway model identifier the chat is configured to use (e.g.
            `openai/gpt-5.4`).
        activeStreamId:
          type: string
          nullable: true
          description: Id of an in-flight assistant stream, if one is active.
        lastAssistantMessageAt:
          type: string
          format: date-time
          nullable: true
          description: Timestamp of the most recent assistant message in this chat.
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
    BearerAuth:
      type: http
      scheme: bearer

````