REST API with streaming support and Grok integration based on Hono web framework.
Demonstrates capabilities:
src/
├── config/
│ ├── app.ts # App configuration
│ ├── grok.ts # Grok API setup
│ └── params.ts # Parameters
├── logic/
│ ├── agent/ # Triage agent
│ ├── completion/ # Grok completions
│ ├── enum/ # Enumerations
│ └── swarm/ # Root swarm
├── main/
│ └── hono.ts # Hono server
├── routes/
│ ├── stream.ts # Streaming endpoint
│ └── sync.ts # Synchronous endpoint
└── index.ts # Entry point
# Install dependencies
bun install
# Start server
bun run src/index.ts
Create a .env
file:
GROK_API_KEY=your_grok_api_key
API_PORT=3000
# POST /api/stream
curl -X POST http://localhost:3000/api/stream \
-H "Content-Type: application/json" \
-d '{"message": "Hello, what can you help me with?"}'
# POST /api/sync
curl -X POST http://localhost:3000/api/sync \
-H "Content-Type: application/json" \
-d '{"message": "Explain quantum physics"}'
const ws = new WebSocket('ws://localhost:3000/ws');
ws.send(JSON.stringify({message: "Hello via WebSocket"}));
data: {"chunk": "Hello", "done": false}
data: {"chunk": " there", "done": false}
data: {"chunk": "!", "done": true}
{
"message": "Hello there! How can I help you today?",
"timestamp": "2024-01-01T00:00:00Z",
"model": "grok-2-mini"
}
Ideal for:
# Docker deployment
docker build -t stream-api-chat .
docker run -p 3000:3000 stream-api-chat
# PM2 deployment
pm2 start src/index.ts --name "stream-api"