---
updatedAt: 2026-04-15T11:43:58.000Z
agentTools:
  projectIndex: https://developers.happeo.com/llms.txt
---

# Start a new discussion or return existing one

Creates a new discussion with the specified agentId and optional contextId. If a discussion already exists with the same parameters, returns the existing discussion.

# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Chat API",
    "version": "1.0",
    "description": "Chat API for managing discussions, entries, tool tasks, and AI conversations with streaming responses."
  },
  "tags": [
    {
      "name": "Chat",
      "description": "Chat system endpoints for managing discussions, entries, and AI conversations"
    }
  ],
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "x-universe-auth"
      }
    },
    "schemas": {
      "Discussion": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "userId": {
            "type": "string"
          },
          "organisationId": {
            "type": "string"
          },
          "agentId": {
            "type": "string"
          },
          "contextId": {
            "type": "string",
            "nullable": true
          },
          "createdAt": {
            "type": "integer"
          },
          "updatedAt": {
            "type": "integer"
          },
          "entries": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DiscussionEntry"
            }
          },
          "_links": {
            "$ref": "#/components/schemas/DiscussionLinks"
          }
        }
      },
      "DiscussionEntry": {
        "type": "object",
        "description": "Represents a single entry in a discussion. Fields with empty values (null, undefined, empty arrays, empty strings) are omitted from the response.\nThe fields `context`, `metadata`, and `thoughtSignature` are never sent to the client.\n",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the entry"
          },
          "role": {
            "type": "string",
            "enum": [
              "user",
              "model"
            ],
            "description": "Role of the entry author"
          },
          "content": {
            "type": "string",
            "description": "Text content of the entry. Omitted if empty."
          },
          "thoughts": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ThoughtEntry"
            },
            "description": "AI reasoning broken down into sections with titles and content. Only present for model entries when the AI produced thinking output."
          },
          "suggestedActions": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Suggested follow-up actions parsed from the AI response. Only present when the AI includes suggested actions."
          },
          "sessionId": {
            "type": "string",
            "description": "Session ID for tracking interactions within a single session. Omitted if not set."
          },
          "toolTaskIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Tool task IDs if this entry initiated tool calls. Omitted if empty."
          },
          "taskListIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "Task list IDs if this entry created task lists. Omitted if empty."
          },
          "timestamp": {
            "type": "integer",
            "description": "Unix timestamp (ms) when the entry was created"
          },
          "elapsedMillis": {
            "type": "integer",
            "description": "Time elapsed in milliseconds from start of processing until this entry was created"
          },
          "attachments": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/DiscussionEntryAttachment"
            },
            "description": "Attachments associated with the entry. The `data` field is stripped before storage. Omitted if empty."
          },
          "toolTasks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/ToolTask"
            },
            "description": "Resolved tool tasks associated with this entry (matched via toolTaskIds). Omitted if empty."
          },
          "taskLists": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/TaskList"
            },
            "description": "Resolved task lists associated with this entry (matched via taskListIds). Omitted if empty."
          },
          "_links": {
            "$ref": "#/components/schemas/EntryLinks"
          }
        }
      },
      "ThoughtEntry": {
        "type": "object",
        "properties": {
          "title": {
            "type": "string",
            "nullable": true,
            "description": "Title of the thought section"
          },
          "content": {
            "type": "string",
            "nullable": true,
            "description": "Content of the thought section"
          }
        }
      },
      "DiscussionLinks": {
        "type": "object",
        "properties": {
          "self": {
            "type": "string",
            "description": "Link to this discussion"
          },
          "urn:happeo:rel:continue": {
            "type": "string",
            "description": "Link to continue the discussion (POST entries)"
          },
          "urn:happeo:rel:delete": {
            "type": "string",
            "description": "Link to delete the discussion"
          },
          "urn:happeo:rel:cancel": {
            "type": "string",
            "description": "Link to cancel the discussion"
          }
        }
      },
      "EntryLinks": {
        "type": "object",
        "description": "Links for a discussion entry. Values are URL paths or \"urn:happeo:reason:no-op\" when the action is not available.\n- `self`: always set\n- `edit` / `delete`: set for user entries\n- `retry`: set for model entries\n- `feedback`: set for model entries (includes sessionId query param when available)\n",
        "properties": {
          "self": {
            "type": "string",
            "description": "Link to this entry"
          },
          "urn:happeo:rel:edit": {
            "type": "string",
            "description": "Link to edit this entry (user entries only, otherwise urn:happeo:reason:no-op)"
          },
          "urn:happeo:rel:retry": {
            "type": "string",
            "description": "Link to retry this entry (model entries only, otherwise urn:happeo:reason:no-op)"
          },
          "urn:happeo:rel:delete": {
            "type": "string",
            "description": "Link to delete this entry (user entries only, otherwise urn:happeo:reason:no-op)"
          },
          "urn:happeo:rel:feedback": {
            "type": "string",
            "description": "Link to submit feedback for this entry (model entries only, otherwise urn:happeo:reason:no-op)"
          }
        }
      },
      "StartDiscussionDTO": {
        "type": "object",
        "required": [
          "agentId"
        ],
        "properties": {
          "agentId": {
            "type": "string",
            "description": "The ID of the chat application",
            "example": "happeo-assistant"
          },
          "contextId": {
            "type": "string",
            "description": "Optional context identifier for the discussion",
            "example": "post-12345"
          }
        }
      },
      "DiscussionEntryAttachment": {
        "type": "object",
        "required": [
          "id",
          "title",
          "mimeType"
        ],
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the attachment",
            "example": "attachment-123"
          },
          "title": {
            "type": "string",
            "description": "Display title of the attachment",
            "example": "Project Requirements.pdf"
          },
          "mimeType": {
            "type": "string",
            "description": "MIME type of the attachment",
            "example": "application/pdf"
          },
          "metadata": {
            "type": "object",
            "additionalProperties": true,
            "description": "Optional metadata as key-value pairs"
          }
        }
      },
      "ToolTask": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the tool task"
          },
          "entryId": {
            "type": "string",
            "description": "ID of the entry that initiated this tool task"
          },
          "status": {
            "$ref": "#/components/schemas/ToolTaskStatus"
          },
          "name": {
            "type": "string",
            "description": "Name of the tool that was called"
          },
          "args": {
            "type": "object",
            "description": "Arguments passed to the tool"
          },
          "isToolCall": {
            "type": "boolean",
            "description": "Whether this is a tool call (true) or a frontend function (false)"
          },
          "response": {
            "type": "string",
            "description": "Stringified JSON response from the tool execution. Can be updated multiple times as the task progresses."
          },
          "sessionId": {
            "type": "string",
            "description": "Session ID for tracking interactions within a single session"
          },
          "_links": {
            "$ref": "#/components/schemas/ToolTaskLinks"
          }
        }
      },
      "ToolTaskStatus": {
        "type": "object",
        "properties": {
          "state": {
            "type": "string",
            "enum": [
              "submitted",
              "working",
              "input-required",
              "completed",
              "canceled",
              "failed"
            ],
            "description": "Current state of the tool task"
          },
          "message": {
            "type": "string",
            "description": "Human readable message providing details about the current status",
            "nullable": true
          },
          "timestamp": {
            "type": "integer",
            "description": "Timestamp when this status was set"
          }
        }
      },
      "ToolTaskLinks": {
        "type": "object",
        "properties": {
          "self": {
            "type": "string",
            "description": "Link to this tool task"
          },
          "urn:happeo:rel:update": {
            "type": "string",
            "description": "Link to update this tool task (includes sessionId query param when available)"
          },
          "urn:happeo:rel:continue": {
            "type": "string",
            "description": "Link to continue conversation with this tool task result (includes sessionId query param when available)"
          }
        }
      },
      "TaskList": {
        "type": "object",
        "description": "A task list represents a plan of sequential tasks created during a conversation.\nEach task can be executed by a tool and tracks its own status independently.\n",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the task list"
          },
          "entryId": {
            "type": "string",
            "description": "ID of the entry that created this task list"
          },
          "discussionId": {
            "type": "string",
            "description": "ID of the discussion this task list belongs to"
          },
          "title": {
            "type": "string",
            "description": "Human-readable title of the task list"
          },
          "tasks": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/PlanTask"
            },
            "description": "Ordered list of tasks in this plan"
          },
          "status": {
            "type": "string",
            "enum": [
              "active",
              "waiting_for_client",
              "interrupted",
              "completed",
              "failed",
              "partially_completed",
              "canceled"
            ],
            "description": "Overall status of the task list"
          },
          "currentTaskIndex": {
            "type": "integer",
            "nullable": true,
            "description": "Index of the currently executing task"
          },
          "currentTaskId": {
            "type": "string",
            "nullable": true,
            "description": "ID of the currently executing task"
          },
          "waitingOnToolTaskId": {
            "type": "string",
            "nullable": true,
            "description": "ID of the tool task the list is waiting on (if any)"
          },
          "startedAt": {
            "type": "integer",
            "nullable": true,
            "description": "Unix timestamp (ms) when execution started"
          },
          "finishedAt": {
            "type": "integer",
            "nullable": true,
            "description": "Unix timestamp (ms) when execution finished"
          },
          "lastError": {
            "type": "string",
            "nullable": true,
            "description": "Last error message if a task failed"
          },
          "sessionId": {
            "type": "string",
            "description": "Session ID for tracking interactions"
          },
          "createdAt": {
            "type": "integer",
            "description": "Unix timestamp (ms) when the task list was created"
          },
          "updatedAt": {
            "type": "integer",
            "description": "Unix timestamp (ms) when the task list was last updated"
          },
          "_links": {
            "$ref": "#/components/schemas/TaskListLinks"
          }
        }
      },
      "PlanTask": {
        "type": "object",
        "description": "A single task within a task list plan",
        "properties": {
          "id": {
            "type": "string",
            "description": "Unique identifier for the task"
          },
          "description": {
            "type": "string",
            "description": "Human-readable description of what this task does"
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "in_progress",
              "waiting_for_client",
              "completed",
              "failed",
              "interrupted",
              "skipped",
              "canceled"
            ],
            "description": "Current status of this task"
          },
          "toolName": {
            "type": "string",
            "description": "Name of the tool to execute for this task"
          },
          "toolArgs": {
            "type": "object",
            "description": "Arguments to pass to the tool"
          },
          "result": {
            "type": "string",
            "nullable": true,
            "description": "Result of the task execution"
          },
          "assistantEntryIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "IDs of assistant entries created during this task"
          },
          "toolTaskIds": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "IDs of tool tasks created for this task"
          },
          "failureReason": {
            "type": "string",
            "nullable": true,
            "description": "Reason for failure if the task failed"
          }
        }
      },
      "TaskListLinks": {
        "type": "object",
        "properties": {
          "self": {
            "type": "string",
            "description": "Link to this task list"
          }
        }
      }
    }
  },
  "paths": {
    "/chats": {
      "post": {
        "summary": "Start a new discussion or return existing one",
        "description": "Creates a new discussion with the specified agentId and optional contextId. If a discussion already exists with the same parameters, returns the existing discussion.",
        "tags": [
          "Chat"
        ],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/StartDiscussionDTO"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Existing or newly created discussion",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Discussion"
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid agentId or request body"
          },
          "401": {
            "description": "Unauthorized - invalid or missing authentication"
          },
          "404": {
            "description": "Chat app not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    }
  },
  "security": [
    {
      "ApiKeyAuth": []
    }
  ]
}
```