Skip to content
Back to Docs

API Reference

Backend SSE streaming API documentation

Overview

The DeepDiagram backend is built on FastAPI and provides an SSE (Server-Sent Events) streaming interface. The frontend sends messages via POST requests, and the backend returns AI-generated results as an SSE event stream.

Base URL: http://localhost:8000

Endpoint List

MethodPathDescription
POST/api/chat/completionsSend a message and receive SSE streaming response
GET/api/sessionsList all sessions
GET/api/sessions/:session_idGet message history for a session
DELETE/api/sessions/:session_idDelete a session
POST/api/test-modelTest model connection

Chat Endpoint

POST /api/chat/completions

Send a message to the AI and receive a streaming response.

Request Body

{
  "session_id": null,
  "prompt": "Draw a microservices architecture diagram",
  "images": [],
  "files": [],
  "history": [],
  "context": {},
  "parent_id": null,
  "is_retry": false,
  "concurrency": 3,
  "model_id": null,
  "api_key": null,
  "base_url": null,
  "agent_id": null
}

Parameters

ParameterTypeRequiredDescription
session_idint | nullNoSession ID. null creates a new session
promptstringYesUser message content
imagesstring[]NoBase64-encoded image list
filesobject[]NoUploaded files: {"name": "file.xlsx", "data": "base64..."}
historyobject[]NoConversation history
contextobjectNoAdditional context
parent_idint | nullNoParent message ID for branching
is_retrybooleanNoWhether to retry the last response
concurrencyintNoDocument parsing concurrency, default 3
model_idstring | nullNoOverride default model
api_keystring | nullNoOverride default API key
base_urlstring | nullNoOverride default base URL
agent_idstring | nullNoForce a specific agent

SSE Response Events

The backend returns various event types via SSE:

Session Management

EventDataDescription
session_created{"session_id": 1}New session created
message_created{"id": 1, "role": "user", "turn_index": 0}User message saved

Document Parsing

EventDataDescription
doc_analysis_start{"session_id": 1}Started parsing uploaded document
doc_analysis_chunk{"content": "...", "index": 0, "status": "running"}Document parsing progress
doc_analysis_end{"content": "...", "session_id": 1}Document parsing complete

Agent Routing

EventDataDescription
agent_selected{"agent": "drawio", "session_id": 1}AI-selected agent

AI Generation

EventDataDescription
design_concept_start{"session_id": 1}Design concept stream started
design_concept{"content": "...", "session_id": 1}Design concept content (streaming)
design_concept_end{"session_id": 1}Design concept stream ended
tool_start{"tool": "drawio", "input": {}, "session_id": 1}Diagram code generation started
tool_code{"content": "...", "session_id": 1}Diagram code (incremental streaming)
tool_end{"output": "...", "session_id": 1}Complete diagram code
thought{"content": "...", "session_id": 1}General agent text response (streaming)

Agent Types

The system includes 7 specialized agents. The AI router automatically selects the best agent based on user intent:

Agent IDNameOutput Format
mindmapMind MapMarkdown (# hierarchy)
flowchartFlowchartReact Flow JSON
chartsData ChartsECharts config JSON
drawioArchitecture DiagrammxGraph XML
mermaidMermaid DiagramMermaid syntax
infographicInfographicAntV DSL
generalGeneral ChatPlain text

Specifying an Agent

You can explicitly specify an agent using the @ prefix in your message:

@mindmap Organize the TypeScript type system
@charts Create a pie chart with data: A: 30%, B: 45%, C: 25%
@mermaid Draw a user login sequence diagram
@drawio Design a cloud-native microservices architecture

Output Format Examples

Mind Map (Markdown)

# React Core Concepts
## Components
### Function Components
### Class Components
## Hooks
### useState
### useEffect
### useContext
## State Management
### Context API
### Redux
### Zustand

Data Chart (ECharts JSON)

{
  "title": { "text": "Quarterly Sales" },
  "xAxis": { "data": ["Q1", "Q2", "Q3", "Q4"] },
  "yAxis": {},
  "series": [{ "type": "bar", "data": [120, 200, 150, 300] }]
}

Architecture Diagram (mxGraph XML)

<mxfile>
  <diagram>
    <mxGraphModel>
      <root>
        <mxCell id="0"/>
        <mxCell id="1" parent="0"/>
        <mxCell id="2" value="Web Server" style="rounded=1;" vertex="1" parent="1">
          <mxGeometry x="200" y="100" width="120" height="60" as="geometry"/>
        </mxCell>
      </root>
    </mxGraphModel>
  </diagram>
</mxfile>

Mermaid Diagram

graph TD
    A[User Request] --> B{Router}
    B -->|API| C[Backend Service]
    B -->|Static| D[CDN]
    C --> E[Database]

File Upload

The following file formats are supported for upload and automatic parsing:

FormatLibraryDescription
PDFPyMuPDFText content extraction
DOCXpython-docxParagraphs and tables extraction
XLSXpandas + openpyxlData sheet parsing
PPTXpython-pptxSlide content extraction
TXT / MDBuilt-inPlain text reading

Files are transmitted as Base64 in the files field. The AI automatically parses file content and uses it for chart generation.

Session Management Endpoints

GET /api/sessions

List all sessions.

Response example:

[
  {
    "id": 1,
    "title": "Microservices Architecture",
    "created_at": "2026-01-29T10:00:00Z",
    "updated_at": "2026-01-29T10:05:00Z"
  }
]

GET /api/sessions/:session_id

Get message history for a specific session.

Response example:

{
  "session": { "id": 1, "title": "Microservices Architecture" },
  "messages": [
    {
      "id": 1,
      "role": "user",
      "content": "Draw a microservices architecture diagram",
      "agent": null,
      "turn_index": 0
    },
    {
      "id": 2,
      "role": "assistant",
      "content": "...",
      "agent": "drawio",
      "turn_index": 0
    }
  ]
}

DELETE /api/sessions/:session_id

Delete a session and all its messages.

Response: {"status": "success"}

POST /api/test-model

Test if a model configuration is valid.

Request body:

{
  "model_id": "gpt-4o",
  "api_key": "sk-xxx",
  "base_url": "https://api.openai.com"
}

Response example:

{
  "success": true,
  "message": "Model connection successful",
  "response": "OK"
}

Error Handling

The following error events may appear in the SSE stream:

EventDescription
status{"content": "error message"} — Processing status or error info

Common error causes:

  • Invalid API key or insufficient quota
  • Model does not support the requested feature
  • Unsupported or corrupted file format