The AI Logistics Optimization API provides AI-powered route optimization and fleet management for instant delivery operations with two service types:
- BARQ: 1-hour delivery within 5km radius
- BULLET: 2-4 hour delivery city-wide
The system uses 18+ specialized AI agents working together to optimize operations in real-time.
Current Version: v1
- All requests and responses use JSON format
- Timestamps are in ISO 8601 format
- Coordinates use WGS84 (latitude, longitude)
The API uses JWT (JSON Web Token) based authentication with role-based access control (RBAC). All protected endpoints require a valid Bearer token in the Authorization header.
Supported Roles:
super_admin- Full system accessadmin- Administrative operationsmanager- Fleet and order managementdispatcher- Order assignment and trackingdriver- Driver-specific operationscustomer- Customer-facing operationsexternal_service- Third-party integrations
POST /api/v1/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}Response:
{
"success": true,
"data": {
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"expiresIn": "24h",
"user": {
"id": "uuid",
"email": "user@example.com",
"role": "dispatcher",
"permissions": ["orders.create", "orders.read"]
}
}
}Include the token in the Authorization header:
Authorization: Bearer YOUR_JWT_TOKENFor external services, use API key authentication:
X-API-Key: YOUR_API_KEY- Development:
http://localhost:3003 - WebSocket:
ws://localhost:8081 - Frontend Dashboard:
http://localhost:3001 - Demo Dashboard:
http://localhost:3001/demo
- General API: 100 requests per 15 minutes
- Authentication: 5 requests per 15 minutes
- Order Creation: 10 requests per minute
- API Key: 1000 requests per minute
Rate limit headers:
X-RateLimit-Limit: Maximum requests allowedX-RateLimit-Remaining: Requests remainingX-RateLimit-Reset: Reset time (Unix timestamp)
{
"success": false,
"status": "error",
"message": "Error description",
"errors": [
{
"field": "email",
"message": "Invalid email format"
}
],
"timestamp": "2024-11-04T12:00:00.000Z"
}200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found409- Conflict429- Too Many Requests500- Internal Server Error502- Bad Gateway503- Service Unavailable
GET /health
Response:
{
"status": "healthy",
"timestamp": "2024-11-04T12:00:00.000Z"
}GET /health/detailed
Response:
{
"status": "healthy",
"uptime": 3600,
"version": "1.0.0",
"checks": {
"database": { "healthy": true },
"redis": { "healthy": true },
"agents": { "healthy": true, "count": 18 }
}
}POST /api/v1/optimize
Content-Type: application/json
{
"pickups": [
{
"id": "pickup1",
"name": "Restaurant A",
"address": "123 Main St",
"coordinates": { "lat": 24.7136, "lng": 46.6753 }
}
],
"deliveries": [
{
"id": "delivery1",
"name": "Customer 1",
"address": "456 King Fahd Rd",
"coordinates": { "lat": 24.7236, "lng": 46.6853 }
}
],
"constraints": {
"maxDistance": 50,
"maxTime": 120
}
}Response:
{
"success": true,
"data": {
"requestId": "uuid",
"routes": [...],
"totalDistance": 25.5,
"totalTime": 45,
"optimizedSequence": [...]
}
}GET /api/v1/optimize/{requestId}GET /api/v1/optimize/status/{requestId}GET /api/v1/optimize/history?limit=10&page=1DELETE /api/v1/optimize/db/clearGET /api/v1/agents/status
Response:
{
"success": true,
"systemStatus": {
"initialized": true,
"uptime": 3600,
"agents": [...],
"health": {
"healthy": 18,
"unhealthy": 0
}
}
}GET /api/v1/agents/health
Response:
{
"success": true,
"summary": {
"totalAgents": 18,
"healthyAgents": 18,
"unhealthyAgents": 0
},
"agents": {
"masterOrchestrator": true,
"orderAssignment": true,
...
}
}POST /api/v1/agents/initializePOST /api/v1/agents/shutdownGET /api/v1/agents/fleet/status
Response:
{
"success": true,
"data": {
"totalDrivers": 50,
"available": 20,
"busy": 25,
"offline": 5,
"utilization": 0.75
}
}POST /api/v1/agents/fleet/rebalance
Response:
{
"success": true,
"data": {
"rebalancingActions": [...],
"affectedDrivers": 10
}
}GET /api/v1/agents/sla/monitor
Response:
{
"success": true,
"data": {
"compliance": 0.95,
"atRiskOrders": [...],
"criticalOrders": [...]
}
}POST /api/v1/agents/order/assign
Content-Type: application/json
{
"order": {
"id": "ORDER-123",
"serviceType": "BARQ",
"pickup": {
"coordinates": { "lat": 24.7136, "lng": 46.6753 }
},
"delivery": {
"coordinates": { "lat": 24.7236, "lng": 46.6853 }
}
}
}
Response:
{
"success": true,
"data": {
"assignedDriver": "DRV-456",
"estimatedTime": 45,
"confidence": 0.92
}
}POST /api/v1/agents/batch/optimize
Content-Type: application/json
{
"orders": [
{ "id": "ORDER-1", ... },
{ "id": "ORDER-2", ... }
],
"serviceType": "BULLET"
}
Response:
{
"success": true,
"data": {
"batches": [...],
"savings": {
"distance": 12.5,
"time": 25
}
}
}GET /api/v1/agents/demand/forecast?horizon=60
Response:
{
"success": true,
"data": {
"forecasts": [
{
"horizon": 30,
"predictedOrders": 25,
"confidence": 0.85
}
]
}
}GET /api/v1/agents/geo/intelligence
Response:
{
"success": true,
"data": {
"hotspots": [...],
"zones": [...],
"recommendations": [...]
}
}GET /api/v1/agents/traffic/patterns
Response:
{
"success": true,
"data": {
"currentConditions": {...},
"predictions": [...],
"congestionZones": [...]
}
}GET /api/v1/agents/performance/analytics
Response:
{
"success": true,
"data": {
"kpis": {...},
"trends": [...],
"insights": [...]
}
}POST /api/v1/agents/emergency/escalate
Content-Type: application/json
{
"type": "SLA_CRITICAL",
"level": "L2",
"context": {
"orderId": "ORDER-123",
"description": "Customer urgent request"
}
}
Response:
{
"success": true,
"data": {
"escalationId": "ESC-789",
"actions": [...],
"notifiedParties": [...]
}
}POST /api/v1/agents/recovery/initiate
Content-Type: application/json
{
"orderId": "ORDER-123",
"reason": "Driver unavailable"
}
Response:
{
"success": true,
"data": {
"recoveryPlan": {...},
"reassignedDriver": "DRV-789"
}
}POST /api/v1/agents/orchestrate
Content-Type: application/json
{
"event": {
"type": "NEW_ORDER_BATCH",
"data": {
"orders": [...],
"priority": "high"
}
}
}
Response:
{
"success": true,
"data": {
"orchestrationId": "ORCH-123",
"agentsInvolved": [...],
"result": {...}
}
}Note: The following endpoints (Orders, Drivers, Analytics) are planned for future releases and are not yet implemented. The system currently focuses on route optimization and AI agent operations.
Connect to WebSocket server for real-time updates:
const ws = new WebSocket('wss://ws.barq-logistics.com');
// Subscribe to events
ws.send(JSON.stringify({
type: 'subscribe',
events: ['orders', 'drivers', 'alerts']
}));orderCreated- New order createdorderAssigned- Order assigned to driverorderPickedUp- Order picked uporderDelivered- Order deliveredorderFailed- Order delivery failed
driverOnline- Driver came onlinedriverOffline- Driver went offlinedriverLocationUpdate- Driver location changed
slaWarning- SLA breach warningemergencyAlert- Emergency situationsystemAlert- System-level alert
{
"type": "orderCreated",
"data": {
"orderId": "uuid",
"orderNumber": "ORD-123",
"serviceType": "BARQ",
"status": "pending"
},
"timestamp": "2024-11-04T12:00:00.000Z"
}const BarqAPI = require('@barq/logistics-sdk');
const client = new BarqAPI({
apiKey: 'YOUR_API_KEY',
environment: 'production'
});
// Create order
const order = await client.orders.create({
serviceType: 'BARQ',
pickup: { /* ... */ },
dropoff: { /* ... */ }
});
// Track order
const status = await client.orders.track(order.orderNumber);from barq_logistics import BarqClient
client = BarqClient(api_key='YOUR_API_KEY')
# Create order
order = client.orders.create(
service_type='BARQ',
pickup={...},
dropoff={...}
)
# Get analytics
metrics = client.analytics.dashboard(
start_date='2024-11-01',
end_date='2024-11-04'
)Download our Postman collection for easy API testing: Download Postman Collection
- Email: api-support@barq-logistics.com
- Documentation: https://docs.barq-logistics.com
- Status Page: https://status.barq-logistics.com
- Developer Portal: https://developers.barq-logistics.com
- Initial API release
- BARQ and BULLET service types
- Real-time tracking via WebSocket
- Multi-agent AI optimization
- JWT authentication
- Comprehensive analytics
Copyright © 2024 BARQ Logistics. All rights reserved.