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

# Send a chat message

> One ModelHub chat turn. The message (and any attachment text) is screened for personal data and masked before any model sees it, routed to a model (or the one you picked), and streamed back as server-sent events with masked values restored for you.

Events, each as `data: {json}`:

- `masked`: your turn in masked form, plus a display-safe reveal map
- `routing`: which model was chosen and why, and the prompt tidy-up applied
- `pii`: what the privacy scan found
- `delta`: a chunk of the answer
- `done`: final analysis, ids, masked history entries and the restore map
- `error`: what went wrong

A message containing a credential or government identifier is held: you get `pii` then `error`, and must resend with `overridePiiBlock: true`. The server keeps no conversation state; send prior turns in `history` (masked forms, from `done.masked`) and the accumulated `restoreMap`.

**Auth:** session. **Permission:** member of the organization and project named in the body.



## OpenAPI

````yaml /api-reference/openapi.json post /chat/stream
openapi: 3.1.0
info:
  title: CorePillar API
  version: 1.0.0
  description: >-
    REST API for AgentHub and ModelHub. Ingestion endpoints authenticate with a
    project tracing key; all other endpoints use the signed-in user's browser
    session.
servers:
  - url: https://pillarforge.corepillar.ai/api/v1
    description: AgentHub
security: []
tags:
  - name: Ingestion
    description: 'Send traces with a tracing key: JSON ingest and OpenTelemetry (OTLP).'
  - name: Traces
    description: Read traces and spans.
  - name: Evaluations
    description: Evaluate traces with evaluator collections.
  - name: Evaluators
    description: Built-in and custom evaluators.
  - name: Evaluator collections
    description: Ordered groups of evaluators.
  - name: Organizations
    description: Organizations you belong to.
  - name: Members
    description: Organization members, invites and roles.
  - name: Projects
    description: Projects inside an organization.
  - name: SSO
    description: Okta SSO configuration.
  - name: Tracing keys
    description: Create, list and revoke project tracing keys.
  - name: Cost calculator
    description: Estimate, generate and execute scenario runs.
  - name: Synthetic
    description: Synthetic agent and data setup from source material.
  - name: Chat
    description: ModelHub chat. Served at https://modelhub.corepillar.ai/api/v1.
  - name: Auth
    description: Sign-in helpers.
  - name: E2E
    description: Internal end-to-end encryption key directory.
paths:
  /chat/stream:
    servers:
      - url: https://modelhub.corepillar.ai/api/v1
        description: ModelHub
    post:
      tags:
        - Chat
      summary: Send a chat message
      description: >-
        One ModelHub chat turn. The message (and any attachment text) is
        screened for personal data and masked before any model sees it, routed
        to a model (or the one you picked), and streamed back as server-sent
        events with masked values restored for you.


        Events, each as `data: {json}`:


        - `masked`: your turn in masked form, plus a display-safe reveal map

        - `routing`: which model was chosen and why, and the prompt tidy-up
        applied

        - `pii`: what the privacy scan found

        - `delta`: a chunk of the answer

        - `done`: final analysis, ids, masked history entries and the restore
        map

        - `error`: what went wrong


        A message containing a credential or government identifier is held: you
        get `pii` then `error`, and must resend with `overridePiiBlock: true`.
        The server keeps no conversation state; send prior turns in `history`
        (masked forms, from `done.masked`) and the accumulated `restoreMap`.


        **Auth:** session. **Permission:** member of the organization and
        project named in the body.
      operationId: chatStream
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - conversationId
                - message
                - modelConfigId
                - orgSlug
                - projectSlug
              properties:
                conversationId:
                  type:
                    - string
                    - 'null'
                  format: uuid
                  description: '`null` starts a new conversation.'
                history:
                  type: array
                  maxItems: 40
                  default: []
                  description: >-
                    Prior turns, oldest first, in masked form. At most 20
                    exchanges.
                  items:
                    type: object
                    required:
                      - role
                      - text
                    properties:
                      role:
                        type: string
                        enum:
                          - user
                          - assistant
                      text:
                        type: string
                message:
                  type: string
                  minLength: 1
                  maxLength: 32000
                attachments:
                  type: array
                  maxItems: 5
                  default: []
                  description: >-
                    Text from `POST /chat/attachments`. Up to 50,000 characters
                    each and 100,000 in total.
                  items:
                    type: object
                    required:
                      - name
                      - text
                    properties:
                      name:
                        type: string
                        minLength: 1
                        maxLength: 240
                      text:
                        type: string
                        minLength: 1
                        maxLength: 50000
                modelConfigId:
                  type:
                    - string
                    - 'null'
                  format: uuid
                  description: A specific model, or `null` to let routing choose.
                optimizePrompt:
                  type: boolean
                  default: true
                  description: >-
                    Tidy the prompt (whitespace, stock politeness) before
                    sending.
                overridePiiBlock:
                  type: boolean
                  description: Continue after a held turn. The value is still masked.
                orgSlug:
                  type: string
                  minLength: 1
                projectSlug:
                  type: string
                  minLength: 1
                restoreMap:
                  type: object
                  additionalProperties:
                    type: string
                    maxLength: 2000
                  description: >-
                    Placeholder to real value, accumulated from earlier `done`
                    events. At most 400 entries.
      responses:
        '200':
          description: Server-sent event stream.
          content:
            text/event-stream:
              schema:
                type: string
              example: >+
                data: {"type":"masked","user":"Email [EMAIL_01] the
                summary","revealMap":{}}


                data: {"type":"routing", "...": "..."}


                data: {"type":"delta","text":"Here is"}


                data: {"type":"done", "...": "..."}

        '400':
          description: Malformed request (`INVALID_BODY`).
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
        '401':
          description: Not signed in (`UNAUTHENTICATED`).
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
        '404':
          description: >-
            Organization or project not found (`ORG_NOT_FOUND`,
            `PROJECT_NOT_FOUND`).
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
        '409':
          description: No models are configured for this project (`NO_MODELS`).
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      code:
                        type: string
                      message:
                        type: string
      security:
        - session: []
components:
  securitySchemes:
    session:
      type: apiKey
      in: cookie
      name: session
      description: >-
        The session cookie set when you sign in to AgentHub or ModelHub in a
        browser. The cookie name shown here is illustrative. There are no API
        tokens for these endpoints.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.