# Send chat message (/docs/api-reference/chat-sessions/sendChatMessage)

> Send one message as the customer and get the agent's reply, plus the tools it called on this turn with their arguments and results.

**POST** `/chat/sessions/{session_id}/message`

Send one message as the customer and get the agent's reply, plus the
tools it called on this turn with their arguments and results.

The agent can close the chat itself, as on a call: with its end call
tool (`end_call`) when the conversation is done, or its transfer tool
(`transfer_call`) when the customer must go to a person, in which case
it tells them the number. The response then has `status: ended`,
`ended_by`, `transferred_to` and the whole `transcript`. The chat is
already saved: show the reply and stop. Both tools follow the agent's
own end call and transfer settings.

In a test chat, `tool_results` here applies to this turn only, on top
of the ones set when the session was created; use it to make a tool
fail on one turn. A live chat refuses `tool_results`.

```yaml
operationId: sendChatMessage
parameters:
  - name: session_id
    in: path
    required: true
    schema:
      type: integer
    description: The `session_id` from Create chat session.
requestBody:
  required: true
  content:
    application/json:
      schema:
        type: object
        required:
          - message
        properties:
          message:
            type: string
            description: What the caller says.
            example: Can I book a cleaning for tomorrow at 10?
          tool_results:
            type: object
            additionalProperties: true
            description: |
              Test chats only. What each of the agent's tools returns, keyed by
              tool name. The agent sees the value as the tool's result. Script a
              failure as `{"status": "error", "error": "<short_code>"}`. A tool you
              leave out returns `{"status": "ok", "data": {}}`.
            example:
              book_appointment:
                status: error
                error: calendar_unavailable
              lookup_order:
                status: ok
                data:
                  state: shipped
responses:
  '200':
    description: The agent's reply.
    content:
      application/json:
        schema:
          type: object
          properties:
            session_id:
              type: integer
              example: 4521
            reply:
              type: string
              description: What the agent said.
              example: Tomorrow at 10 is open. Can I have your name?
            tool_calls:
              type: array
              description: Tools the agent called on this turn, with their arguments and the result it got.
              items:
                type: object
                properties:
                  function_name:
                    type: string
                  args:
                    description: The arguments the agent passed.
                  result:
                    description: What the tool returned to the agent.
                  success:
                    type: boolean
                  error:
                    type: string
                  source:
                    type: string
                    enum:
                      - scripted
                      - default
                      - real
                    description: |
                      Test chats only. Where the result came from: your
                      `tool_results` (`scripted`), an empty success because you
                      scripted nothing for this tool (`default`), or the tool itself
                      (`real`: the end call and transfer tools).
            should_end:
              type: boolean
              description: True when the agent ended the chat on this turn (same as `status` being `ended`).
            status:
              type: string
              enum:
                - active
                - ended
              description: |
                `ended` when the agent closed the chat on this turn, with its end
                call or transfer tool. The chat is already saved: show the reply,
                and do not call End chat session. The fields below are then set.
            ended_by:
              type: string
              nullable: true
              enum:
                - agent
                - transfer
                - client
                - idle
                - turn_limit
              description: |
                How the chat ended: the agent ran its end call tool (`agent`) or
                transfer tool (`transfer`), you called End chat session (`client`),
                nobody wrote for 30 minutes (`idle`), or the agent sent 100 replies
                (`turn_limit`). Null while the chat is active.
            transferred_to:
              type: string
              nullable: true
              description: When the agent transferred the chat, the number it sent the customer to.
              example: '+15551234567'
            transcript:
              type: array
              description: The whole chat, oldest first, once it has ended. The greeting has no customer line.
              items:
                type: object
                properties:
                  role:
                    type: string
                    enum:
                      - agent
                      - customer
                  text:
                    type: string
              example:
                - role: agent
                  text: Hi, this is Sam from Demo Dental. How can I help?
                - role: customer
                  text: I need to talk to a person.
                - role: agent
                  text: Sure, I am transferring you to +15551234567 now.
  '400':
    description: Empty message or malformed body.
    content:
      application/json:
        schema:
          type: object
          properties:
            error:
              type: string
              description: Machine-readable error code.
            error_description:
              type: string
              description: Human-readable explanation.
            code:
              type: string
              description: |
                Stable, specific reason. Present on the newer endpoints (Voice
                cloning, WhatsApp); older endpoints return only `error`.
            request_id:
              type: string
              description: |
                Correlates this response with the server log. Present alongside
                `code`. Also sent as the `X-Request-Id` header.
        example:
          error: invalid_request
          error_description: message is required.
  '401':
    description: Missing or invalid API key.
  '402':
    description: Your balance is too low for another chat message.
    content:
      application/json:
        schema:
          type: object
          properties:
            error:
              type: string
              description: Machine-readable error code.
            error_description:
              type: string
              description: Human-readable explanation.
            code:
              type: string
              description: |
                Stable, specific reason. Present on the newer endpoints (Voice
                cloning, WhatsApp); older endpoints return only `error`.
            request_id:
              type: string
              description: |
                Correlates this response with the server log. Present alongside
                `code`. Also sent as the `X-Request-Id` header.
        example:
          error: insufficient_balance
          error_description: Your balance is too low for another chat message. Please top up.
  '404':
    description: Session not found in your organization.
    content:
      application/json:
        schema:
          type: object
          properties:
            error:
              type: string
              description: Machine-readable error code.
            error_description:
              type: string
              description: Human-readable explanation.
            code:
              type: string
              description: |
                Stable, specific reason. Present on the newer endpoints (Voice
                cloning, WhatsApp); older endpoints return only `error`.
            request_id:
              type: string
              description: |
                Correlates this response with the server log. Present alongside
                `code`. Also sent as the `X-Request-Id` header.
        example:
          error: session_not_found
          error_description: Chat session not found or access denied
  '409':
    description: The session has ended. Create a new one.
    content:
      application/json:
        schema:
          type: object
          properties:
            error:
              type: string
              description: Machine-readable error code.
            error_description:
              type: string
              description: Human-readable explanation.
            code:
              type: string
              description: |
                Stable, specific reason. Present on the newer endpoints (Voice
                cloning, WhatsApp); older endpoints return only `error`.
            request_id:
              type: string
              description: |
                Correlates this response with the server log. Present alongside
                `code`. Also sent as the `X-Request-Id` header.
        example:
          error: session_ended
          error_description: This chat session has ended. Create a new one.
          ended_by: idle
  '502':
    description: The agent did not answer. Retry the request.
    content:
      application/json:
        schema:
          type: object
          properties:
            error:
              type: string
              description: Machine-readable error code.
            error_description:
              type: string
              description: Human-readable explanation.
            code:
              type: string
              description: |
                Stable, specific reason. Present on the newer endpoints (Voice
                cloning, WhatsApp); older endpoints return only `error`.
            request_id:
              type: string
              description: |
                Correlates this response with the server log. Present alongside
                `code`. Also sent as the `X-Request-Id` header.
        example:
          error: agent_unavailable
          error_description: The agent did not answer. Try the message again.
```

**curl**

```bash
curl -X POST "https://omnidim.io/api/v1/chat/sessions/{session_id}/message" \
  -H "Authorization: Bearer $OMNIDIM_API_KEY"
```