> ## 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.

> Create a chat session — Creates a new chat session for the organization. Use when orchestrating conversations from code — creating sessions, sending messages, or listing history…

# Create a chat session

## Custom data

Pass top-level `custom_data` to store session-level attributes on the new chat session, such as an order ID, cart value, or routing flag. Values can be strings, numbers, or booleans, and are returned by [Get Session](/api-reference/chat-sessions/get).

```json theme={"dark"}
{
  "channel": { "type": "api" },
  "custom_data": { "order_id": "ord_123", "cart_value": 149.99, "priority": "high" }
}
```

Nested objects are rejected with a `400`. To attach contact-level attributes instead, use `contact.custom_data` on [Send Message](/api-reference/chat-sessions/send).

<Note>
  Session `custom_data` set through this endpoint is stored on the session but is **not** synced to a connected external ticketing system (e.g. Intercom or HubSpot).
</Note>


## OpenAPI

````yaml post /chat/sessions
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:
    post:
      summary: Create a chat session
      description: Creates a new chat session for the organization.
      operationId: createChatSession
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateChatSessionInput'
      responses:
        '200':
          description: Default Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateChatSessionOutput'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorDto'
components:
  schemas:
    CreateChatSessionInput:
      $schema: https://json-schema.org/draft/2020-12/schema
      $id: '#/components/schemas/CreateChatSessionInputInput'
      type: object
      properties:
        contact_id:
          type: string
          format: uuid
          pattern: >-
            ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
        channel:
          default:
            type: api
          type: object
          properties:
            type:
              $ref: '#/components/schemas/SessionChannel'
          required:
            - type
        verified:
          anyOf:
            - type: boolean
            - type: 'null'
        custom_data:
          description: Session-level custom data to store on the chat session.
          type: object
          propertyNames:
            type: string
          additionalProperties:
            anyOf:
              - type: string
              - type: number
              - type: boolean
        contact:
          description: >-
            Contact to associate with the session. When provided (and no
            contact_id is given) a contact is created/updated and linked to the
            session; its custom_data is persisted on the contact. Honors the
            top-level `verified` flag — verified contacts write to custom_data,
            otherwise to non_verified_custom_data.
          type: object
          properties:
            email:
              type: string
              format: email
              pattern: >-
                ^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$
            name:
              type: string
            phone_number:
              type: string
            custom_data:
              description: Custom data to store on the contact for this session.
              type: object
              propertyNames:
                type: string
              additionalProperties:
                type: string
    CreateChatSessionOutput:
      $schema: https://json-schema.org/draft/2020-12/schema
      $id: '#/components/schemas/CreateChatSessionOutput'
      type: object
      properties:
        id:
          type: string
          format: uuid
          pattern: >-
            ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$
      required:
        - id
      additionalProperties: false
    ErrorDto:
      type: object
      properties:
        statusCode:
          type: integer
        message:
          type: string
        error:
          type: string
    SessionChannel:
      $schema: https://json-schema.org/draft/2020-12/schema
      $id: '#/components/schemas/SessionChannel'
      type: string
      enum:
        - web
        - email
        - phone_voice
        - slack
        - sms
        - whatsapp
        - instagram
        - messenger
        - api
        - web_voice
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````