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

> Full-text search across contacts (by name, email, phone) and chat messages. Use when orchestrating conversations from code — creating sessions, sending messages, or listing…

# Search contacts and messages



## OpenAPI

````yaml get /chat/sessions/search
openapi: 3.1.0
info:
  title: OpenCX API
  description: >

    OpenCX is an AI-powered, all-in-one platform for customer support and
    outbound communications.


    Use this API to manage your OpenCX organization's AI agents, actions,
    conversations, contacts, and more.


    To get started, generate a new API key from the dashboard.


    ## Authentication

    All API endpoints require authentication using a Bearer token. You can
    generate an API key from your OpenCX dashboard.


    ## Rate Limiting

    API requests are rate limited to ensure fair usage. The current limits are:

    - 100 requests per minute for standard endpoints

    - 1000 requests per minute for streaming endpoints


    ## Error Handling

    The API uses standard HTTP status codes and returns detailed error messages
    in the response body.
  version: 1.0-beta
  license:
    name: MIT
    url: https://opensource.org/licenses/MIT
servers:
  - url: https://api.open.cx
    description: Production
security:
  - bearerAuth: []
paths:
  /chat/sessions/search:
    get:
      summary: Search contacts and messages
      description: >-
        Full-text search across contacts (by name, email, phone) and chat
        messages. Returns matching contacts and messages with their session IDs.
        Pass `contact_id` to scope message hits to a single contact — strongly
        recommended for customer-facing workflows so the response can never leak
        another customer’s messages.
      operationId: searchContactsAndMessages
      parameters:
        - schema:
            type: string
            minLength: 1
          in: query
          name: q
          required: true
          description: Search query (a name, email, phone, or keyword)
        - schema:
            type: string
            minLength: 1
          in: query
          name: contact_id
          required: false
          description: >-
            Restrict message hits to sessions belonging to this contact. When
            set, the contacts[] response is also restricted to this contact (no
            BM25 fan-out).
      responses:
        '200':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SearchPublicResponseDto'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
components:
  schemas:
    SearchPublicResponseDto:
      $schema: https://json-schema.org/draft/2020-12/schema
      $id: '#/components/schemas/SearchPublicResponseDto'
      type: object
      properties:
        contacts:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                description: Contact ID
              name:
                anyOf:
                  - type: string
                  - type: 'null'
                description: Contact name
              email:
                anyOf:
                  - type: string
                  - type: 'null'
                description: Contact email
              phone:
                anyOf:
                  - type: string
                  - type: 'null'
                description: Contact phone number
            required:
              - id
              - name
              - email
              - phone
            additionalProperties: false
        messages:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
                description: Message ID
              session_id:
                type: string
                description: Session this message belongs to
              message:
                anyOf:
                  - type: string
                  - type: 'null'
                description: Message content
              type:
                type: string
                description: Message type
            required:
              - id
              - session_id
              - message
              - type
            additionalProperties: false
      required:
        - contacts
        - messages
      additionalProperties: false
    ErrorDto:
      type: object
      properties:
        statusCode:
          type: integer
        message:
          type: string
        error:
          type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````