FastAPI backend with a static chat UI that streams replies from Coze.
- Python 3.10+
- pip
- Internet access to reach the configured Coze endpoint
- Create and activate a virtual environment
python -m venv .venv
.\.venv\Scripts\activate
- Install backend dependencies
pip install -r backend/requirements.txt
- Copy
backend/.env.exampletobackend/.envand set values - Required variables:
COZE_ENDPOINTCOZE_TOKENCOZE_PROJECT_ID
- Keep tokens private; do not commit
.env
- Activate the virtual environment
- Start the API server
uvicorn backend.app:app --reload --port 8000
- Open
http://127.0.0.1:8000/for the chat UI
- Plain reply
curl -X POST http://127.0.0.1:8000/api/chat \
-H "Content-Type: application/json" \
-d "{\"text\":\"hello\"}"
- Streaming (Server-Sent Events)
curl -N -X POST http://127.0.0.1:8000/api/chat/stream \
-H "Content-Type: application/json" \
-H "Accept: text/event-stream" \
-d "{\"text\":\"hello\"}"
- If
.envis missing or incomplete, the server returns a mock echo response instead of calling Coze. - Static client lives at
backend/static/index.htmland is served at/.