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

# Chat with an agent (headless)

> Runs one generative turn and spends one message credit atomically (D-16). JSON by default; send `Accept: text/event-stream` for SSE. Continue a conversation with `conversationId`. `Idempotency-Key` (JSON mode) makes a retry replay the first answer without spending a second credit.



## OpenAPI

````yaml /openapi.json post /v1/agents/{agentId}/chat
openapi: 3.0.0
info:
  title: wondeya Developer API
  description: >-
    The public REST API for building on wondeya: agents, projects, pages,
    knowledge, assets, brand, theme, usage, retrieval and chat, authenticated by
    a workspace API key (`Authorization: Bearer wdy_live_…`).
  version: 0.1.0
  contact:
    name: wondeya
    url: https://wondeya.com
    email: team@wondeya.com
  license:
    name: Proprietary
    url: https://wondeya.com/terms
servers:
  - url: https://api.wondeya.com
    description: Production
  - url: http://localhost:8080
    description: Development
security: []
tags:
  - name: Identity
  - name: Agents
  - name: Projects
  - name: Pages
  - name: Knowledge
  - name: Assets
  - name: Brand
  - name: Usage
  - name: Chat
paths:
  /v1/agents/{agentId}/chat:
    post:
      tags:
        - Chat
      summary: Chat with an agent (headless)
      description: >-
        Runs one generative turn and spends one message credit atomically
        (D-16). JSON by default; send `Accept: text/event-stream` for SSE.
        Continue a conversation with `conversationId`. `Idempotency-Key` (JSON
        mode) makes a retry replay the first answer without spending a second
        credit.
      operationId: PublicChatController_chat_v1
      parameters:
        - name: agentId
          required: true
          in: path
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PublicChatDto'
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicChatResponseDto'
        '402':
          description: '`wondeya.usage.quota_exhausted`: the workspace is out of messages'
        '404':
          description: No such agent in this workspace
      security:
        - api-key: []
components:
  schemas:
    PublicChatDto:
      type: object
      properties:
        message:
          type: string
          minLength: 1
          maxLength: 1000
          description: The visitor question the agent answers.
        locale:
          type: string
          enum:
            - es
            - en
          default: es
        conversationId:
          type: string
          description: >-
            Continue a conversation: pass the `conversationId` a previous turn
            returned. Omit to start a new one; the server owns the transcript.
      required:
        - message
    PublicChatResponseDto:
      type: object
      properties:
        conversationId:
          type: string
          description: The server-owned conversation this turn is in.
        reply:
          type: string
          description: The assistant’s text answer.
        components:
          description: The generative-UI components the agent chose to render.
          type: array
          items:
            $ref: '#/components/schemas/PublicChatComponentDto'
        cached:
          type: boolean
          description: True when the turn was replayed from cache (spent no credit).
      required:
        - conversationId
        - reply
        - components
        - cached
    PublicChatComponentDto:
      type: object
      properties:
        slot:
          type: string
          description: The catalog component the agent rendered.
        props:
          type: object
          additionalProperties: true
          nullable: true
          description: The validated props of the component (ids only, never HTML).
      required:
        - slot
        - props
  securitySchemes:
    api-key:
      scheme: bearer
      bearerFormat: opaque
      type: http
      description: >-
        A workspace API key: wdy_live_… / wdy_test_…. Created at POST
        /workspaces/{tenantId}/keys and shown exactly once.

````