pawan-api
HTTP API server for Pawan — Axum + SSE streaming for real-time agent interactions.
Overview
pawan-api provides a RESTful HTTP API and Server-Sent Events (SSE) streaming interface for the Pawan coding agent. It enables web applications and other services to interact with Pawan's AI-powered coding capabilities through standard HTTP protocols.
Features
- RESTful API — Standard HTTP endpoints for agent interactions
- SSE Streaming — Real-time streaming of agent responses and tool calls
- Session Management — Create, list, retrieve, and delete conversation sessions
- Multi-Agent Support — Manage multiple agent instances concurrently
- Health Monitoring — Built-in health check and status endpoints
- Model Discovery — List available models and their configurations
- CORS Support — Cross-origin resource sharing for web applications
- Aegis Integration — Peer discovery via Aegis network configuration
Installation
Install from crates.io:
# Or build from source
&&
The source-built binary will be available at target/release/pawan-api.
Usage
Starting the Server
# Start with default configuration
# Start with custom workspace
# Start with custom config
The server starts on port 3300 by default.
Configuration
The server reads configuration from pawan.toml in the workspace directory:
= "nvidia"
= "qwen/qwen3.5-122b-a10b"
= 0.6
= 4096
API Endpoints
Health Check
GET /health
Response:
List Agents
GET /agents
Response:
List Models
GET /models
Response:
Chat (Non-Streaming)
POST /chat
Content-Type: application/json
{
"session_id": "optional-session-id",
"message": "Fix the failing test in src/lib.rs",
"model": "optional-model-override"
}
Response:
Chat (Streaming)
POST /chat/stream
Content-Type: application/json
{
"session_id": "optional-session-id",
"message": "Explain how the agent loop works",
"model": "optional-model-override"
}
Response: Server-Sent Events stream
event: token
data: {"content": "The"}
event: token
data: {"content": " agent"}
event: tool_start
data: {"name": "read"}
event: tool_complete
data: {"name": "read", "success": true, "duration_ms": 42, "result_preview": "..."}
event: done
data: {"session_id": "abc-123", "content": "The agent loop works by...", "iterations": 2, "tool_calls": 3}
Session Management
List Sessions
GET /sessions
Response:
Get Session
GET /sessions/{id}
Response:
Create Session
POST /sessions
Response:
Delete Session
DELETE /sessions/{id}
Response: 204 No Content
SSE Event Types
token
Emitted for each token in the agent's response.
tool_start
Emitted when a tool execution begins.
tool_complete
Emitted when a tool execution completes.
done
Emitted when the agent completes the request.
error
Emitted when an error occurs.
Client Examples
cURL
# Health check
# List models
# Chat (non-streaming)
# Chat (streaming)
# List sessions
JavaScript (Fetch API)
// Non-streaming chat
const response = await ;
const data = await response.;
console.log;
// Streaming chat
const eventSource = ;
eventSource.;
eventSource.;
Python
# Non-streaming
=
# Streaming
=
=
break
Architecture
Application State
The server maintains shared state across all HTTP handlers:
Session Management
- Sessions are stored in
~/.pawan/sessions/ - Each session has a unique UUID
- Sessions persist across server restarts
- Automatic session resumption via
session_id
Agent Lifecycle
- Creation: Agent created on first request with new
session_id - Execution: Agent processes message with tool calling
- Callbacks: Token, tool start, and tool completion events streamed
- Persistence: Session saved automatically after completion
- Archival: Optional archival to Eruka memory system
CORS Configuration
The server includes CORS support for web applications:
let cors = new
.allow_origin
.allow_methods
.allow_headers;
Aegis Integration
The server can discover peer agents via Aegis network configuration:
# ~/.config/aegis/aegis-net.toml
[]
= "192.168.1.100"
= ["production"]
[]
= "192.168.1.101"
= ["development"]
Access via /agents endpoint.
Error Handling
The server returns appropriate HTTP status codes:
200 OK— Successful request204 No Content— Successful deletion400 Bad Request— Invalid request body404 Not Found— Session not found500 Internal Server Error— Agent execution error
Error responses include descriptive messages:
Development
Running in Development
# With custom workspace
Testing
# Run web server tests
# Run with logging
RUST_LOG=debug
Performance Considerations
- Concurrent Sessions: Multiple sessions handled via
RwLock<HashMap> - Streaming: SSE provides low-latency real-time updates
- Memory: Sessions persisted to disk, not kept in memory
- Scalability: Stateless design allows horizontal scaling
Security
- CORS: Configurable for production deployments
- Input Validation: All requests validated before processing
- File Access: Agent respects workspace boundaries
- No Authentication: Currently designed for trusted environments
License
MIT
See Also
- Pawan — Main CLI coding agent
- pawan-core — Core library
- Axum — Web framework
- SSE — Server-Sent Events