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

# Published Spaces Chat API

> Interact programmatically with published Space chat endpoints using JSON responses or real-time SSE streaming

export const Glossary = ({children, term}) => {
  const glossaryDefinitions = {
    'ai': 'Artificial Intelligence - computer systems that can perform tasks typically requiring human intelligence',
    'artificial-intelligence-ai': 'Computer systems that can perform tasks typically requiring human intelligence',
    'ai-assistant': 'An AI system designed to help users with tasks through conversation',
    'space': 'A dedicated environment with a specialized AI assistant and optional Uploaded Files',
    'spaces': 'Dedicated environments with specialized AI assistants and optional Uploaded Files',
    'knowledge': 'The sub-menu in Space settings where you manage Uploaded Files and Connected Sources',
    'uploaded-files': 'Documents manually uploaded to a Space under the Knowledge tab',
    'prompt': 'Instructions or questions you give to an AI assistant',
    'response': 'The AI assistant\'s answer to your prompt or question',
    'query': 'A question or request for information',
    'context': 'Background information that helps the AI understand your request',
    'llm': 'Large Language Model - an AI system trained on vast amounts of text data to understand and generate human language',
    'large-language-model-llm': 'An AI system trained on vast amounts of text data to understand and generate human language',
    'privacy-filter': 'A system that automatically detects and masks sensitive information before it reaches AI models, and restricts images from being sent to non-EU hosted models for compliance',
    'chat-instructions': 'Custom guidelines that define how an AI assistant behaves and responds in a Space',
    'pattern-matching': 'The process by which AI recognizes and uses patterns in data to provide responses',
    'patterns': 'Recognizable structures or trends in data that AI systems can identify and use',
    'training-data': 'The text and information used to teach an AI system how to understand and respond to requests',
    'natural-language': 'Everyday human language that people use to communicate, as opposed to computer code or formal syntax',
    'hallucination': 'When an AI generates information that sounds plausible but is actually incorrect or fabricated',
    'filtering': 'The process of automatically detecting and temporarily replacing sensitive information to protect it during AI processing',
    'masking': 'Temporarily replacing sensitive information with generic labels to protect it from being seen by external AI models',
    're-insertion': 'The automatic process of putting original sensitive information back into AI responses after they\'ve been generated with filtered data',
    'retrieval': 'The process of finding and accessing relevant documents from Uploaded Files to answer questions',
    'hosting': 'Where an AI model is deployed and made available for use - either by third-party providers, on your organization\'s own servers, or in private cloud environments',
    'cite': 'To reference or mention the source of information, helping you know where an AI\'s answer came from',
    'sidebar': 'A panel that appears on the side of the screen showing additional information and options',
    'toggle': 'A button or control that switches something on or off, like opening and closing a sidebar',
    'navigation': 'The system of menus and buttons that help you move between different parts of Omnifact',
    'favoriting': 'Marking a Space as a favorite to pin it to the main navigation for quick access',
    'pinning': 'Attaching a Space to the main navigation bar so it\'s always visible and easily accessible'
  };
  const definition = glossaryDefinitions[term];
  return <Tooltip tip={definition}>{children}</Tooltip>;
};

Published Spaces allow organization administrators to expose configured <Glossary term="space">Spaces</Glossary> as standalone API endpoints. External applications, custom internal tools, or automated workflows can send chat messages to a published Space and receive AI assistant responses powered by the Space's instructions, models, and Uploaded Files.

<Note>
  Before invoking a Published Space chat endpoint, a team administrator must publish the Space in **Team Settings** > **Published Spaces**. Learn more in [Published Spaces](/en/platform/team-administration/published-spaces).
</Note>

## Endpoint

`POST /v1/endpoints/{endpointId}/chat`

### Request Headers

| Header                             | Type     | Required | Description                                                                         |
| :--------------------------------- | :------- | :------- | :---------------------------------------------------------------------------------- |
| `X-API-Key`                        | `string` | Required | Your team API key generated in Developer Tools.                                     |
| `Content-Type`                     | `string` | Required | Must be `application/json`.                                                         |
| `omnifact-enable-inline-sources`   | `string` | Optional | Set to `"true"` to enable inline source citation formatting in assistant responses. |
| `omnifact-enable-agentic-workflow` | `string` | Optional | Set to `"true"` to allow agentic multi-tool reasoning during response generation.   |

### Request Body (`application/json`)

```json theme={null}
{
  "messages": [
    {
      "role": "user",
      "content": "What is our policy on remote work?"
    }
  ],
  "streaming": false
}
```

| Field       | Type      | Required | Description                                                                                         |
| :---------- | :-------- | :------- | :-------------------------------------------------------------------------------------------------- |
| `messages`  | `array`   | Required | Array of message objects (`role`: `"user"` \| `"assistant"`, `content`: `string`).                  |
| `streaming` | `boolean` | Optional | Set to `true` for Server-Sent Events (SSE) streaming; `false` for standard JSON (default: `false`). |

***

## Response Modes

### 1. Standard JSON Response (`streaming: false`)

When `streaming` is `false` (or omitted), the endpoint processes the entire conversation and returns a single JSON object.

#### Example Request

```bash theme={null}
curl -X POST "https://connect.omnifact.ai/v1/endpoints/ep_abc123/chat" \
  -H "X-API-Key: your_omnifact_api_key_here" \
  -H "Content-Type: application/json" \
  -H "omnifact-enable-inline-sources: true" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "What are our primary core values?"
      }
    ],
    "streaming": false
  }'
```

#### JSON Response (`200 OK`)

```json theme={null}
{
  "id": "msg_xyz789",
  "role": "assistant",
  "content": "According to our company handbook, our core values are transparency, innovation, and privacy [1].",
  "references": [
    {
      "id": 1,
      "title": "Employee_Handbook_2026.pdf",
      "documentId": "doc_98765"
    }
  ]
}
```

***

### 2. SSE Streaming Response (`streaming: true`)

When `streaming` is set to `true`, the server streams the response as real-time Server-Sent Events (SSE) using `Content-Type: text/event-stream`.

#### SSE Event Types

The event stream emits typed SSE events as response generation progresses:

| Event Name        | Description                                  | Payload Structure                                                 |
| :---------------- | :------------------------------------------- | :---------------------------------------------------------------- |
| `assistant_write` | Streamed text chunk from assistant response. | `{"delta": "text chunk"}`                                         |
| `references`      | Array of source document references cited.   | `{"references": [{ "id": 1, "title": "filename.pdf" }]}`          |
| `message_source`  | Status indicator for tools/retrieval used.   | `{"source": "UPLOADED_FILES", "status": "RETRIEVED", "count": 3}` |
| `error`           | An error occurred during generation.         | `{"error": "Description of error"}`                               |
| `done`            | Stream completed.                            | `{"done": true}`                                                  |

#### Example Streaming Request

```bash theme={null}
curl -N -X POST "https://connect.omnifact.ai/v1/endpoints/ep_abc123/chat" \
  -H "X-API-Key: your_omnifact_api_key_here" \
  -H "Content-Type: application/json" \
  -d '{
    "messages": [
      {
        "role": "user",
        "content": "Summarize our quarterly goals."
      }
    ],
    "streaming": true
  }'
```

#### SSE Stream Output Example

```http theme={null}
event: message_source
data: {"source":"UPLOADED_FILES","status":"RETRIEVED","count":2}

event: assistant_write
data: {"delta":"Our "}

event: assistant_write
data: {"delta":"quarterly "}

event: assistant_write
data: {"delta":"goals focus on..."}

event: references
data: {"references":[{"id":1,"title":"Q3_Goals.pdf"}]}

event: done
data: {"done":true}
```

***

## Code Examples

<Tabs>
  <Tab title="JavaScript / Node.js">
    ```javascript theme={null}
    const response = await fetch("https://connect.omnifact.ai/v1/endpoints/ep_abc123/chat", {
      method: "POST",
      headers: {
        "X-API-Key": process.env.OMNIFACT_API_KEY,
        "Content-Type": "application/json",
        "omnifact-enable-inline-sources": "true"
      },
      body: JSON.stringify({
        messages: [
          { role: "user", content: "What is our remote work budget allowance?" }
        ],
        streaming: false
      })
    });

    const data = await response.json();
    console.log("Assistant:", data.content);
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    import requests
    import os

    url = "https://connect.omnifact.ai/v1/endpoints/ep_abc123/chat"
    headers = {
        "X-API-Key": os.getenv("OMNIFACT_API_KEY"),
        "Content-Type": "application/json",
        "omnifact-enable-inline-sources": "true"
    }
    payload = {
        "messages": [
            {"role": "user", "content": "What is our remote work budget allowance?"}
        ],
        "streaming": False
    }

    response = requests.post(url, headers=headers, json=payload)
    data = response.json()
    print("Assistant:", data.get("content"))
    ```
  </Tab>
</Tabs>

## Next Steps

* Explore document operations with the [Documents API](/en/api-reference/documents)
* Review [Published Spaces](/en/platform/team-administration/published-spaces) documentation to manage endpoint access
