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

# Create Message

> Create a new message in a chat thread to query your data using natural language

## Overview

Create a new message in a chat thread to query your data using natural language. This endpoint processes your question, generates appropriate queries, executes them against your connected resource, and returns intelligent responses.


## OpenAPI

````yaml POST /chats/messages
openapi: 3.1.0
info:
  title: Ledgerbeam API
  description: >-
    Conversational analytics API for querying data using natural language,
    managing resources, and interacting with data sources
  version: 1.0.0
  contact:
    name: Ledgerbeam Support
    email: support@ledgerbeam.com
  license:
    name: MIT
servers:
  - url: https://api.ledgerbeam.com/v1
    description: Production server
security:
  - apiKeyAuth: []
paths:
  /chats/messages:
    post:
      summary: Create message
      description: >-
        Create a new message in a chat thread to query your data using natural
        language
      operationId: createMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateMessageRequest'
      responses:
        '200':
          description: Message created successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateMessageResponse'
        '400':
          description: Bad request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CreateMessageRequest:
      type: object
      required:
        - resource_id
        - content
      properties:
        resource_id:
          type: string
          description: The unique identifier of the resource (data source) to query
          example: res_123456789
        content:
          type: string
          description: Your natural language question or query
          example: What are my top 10 customers by revenue this month?
        thread_id:
          type: string
          description: >-
            Optional. The thread ID to continue an existing conversation. If not
            provided, a new thread will be created.
          example: thread_abc123
        stream:
          type: boolean
          description: >-
            Optional. Set to true to enable streaming responses via Server-Sent
            Events (SSE). Defaults to false.
          default: false
        action:
          type: string
          description: >-
            Optional. Specify an action type for the query (e.g., 'analyze',
            'visualize', 'summarize').
    CreateMessageResponse:
      type: object
      properties:
        user_message:
          $ref: '#/components/schemas/Message'
        assistant_message:
          $ref: '#/components/schemas/Message'
        meta:
          $ref: '#/components/schemas/QueryMetrics'
        thread_id:
          type: string
          description: Thread ID
          example: thread_abc123
    Error:
      type: object
      properties:
        error:
          oneOf:
            - type: string
            - type: object
              properties:
                description:
                  type: array
                  items:
                    type: string
          description: Error message or validation errors
          example: Unauthorized access
    Message:
      type: object
      properties:
        id:
          type: string
          description: Message ID
          example: msg_abc123
        content:
          type: array
          items:
            $ref: '#/components/schemas/MessageContent'
          description: Message content
        role:
          type: string
          enum:
            - user
            - assistant
          description: Message role
          example: user
        meta:
          type: object
          description: Additional metadata
          additionalProperties: true
    QueryMetrics:
      type: object
      properties:
        answer:
          type: string
          description: Natural language answer
          example: Your top 10 customers by revenue this month are...
        row_count:
          type: integer
          description: Number of rows returned
          example: 10
        query_time:
          type: string
          description: Query execution time
          example: 0.45s
        query_type:
          type: string
          description: Type of query executed
          example: SELECT
        query:
          type: string
          description: Generated SQL query
          example: >-
            SELECT customer_name, SUM(revenue) as total_revenue FROM orders
            WHERE ...
        rows:
          type: array
          items:
            type: object
            additionalProperties: true
          description: Query result rows
        thinking:
          type: array
          items:
            type: string
          description: AI thinking steps
        rendered:
          type: object
          description: Rendered content (tables, charts, etc.)
          additionalProperties: true
    MessageContent:
      type: object
      properties:
        type:
          type: integer
          description: Content type (1 = text, 2 = table, etc.)
          example: 1
        value:
          type: string
          description: Content value
          example: Here are your top customers...
        meta:
          type: object
          description: Additional metadata
          additionalProperties: true
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: API-KEY
      description: API key for authentication

````