| Crates.io | iron_control_api |
| lib.rs | iron_control_api |
| version | 0.4.0 |
| created_at | 2025-12-16 17:52:07.330849+00 |
| updated_at | 2025-12-18 09:28:23.769203+00 |
| description | HTTP API for Iron Cage control plane |
| homepage | |
| repository | https://github.com/.../iron_runtime |
| max_upload_size | |
| id | 1988356 |
| size | 1,803,354 |
REST API and WebSocket endpoints for programmatic control of Iron Cage runtime and real-time dashboard communication.
[!IMPORTANT] Test Coverage: 379 tests (100% pass rate) - Protocol 014 (111 tests), Protocol 010 (39 tests), Protocol 012 (30 tests), Security (173 tests)
[dependencies]
iron_control_api = { version = "0.1", features = ["enabled"] }
default = ["enabled"]: Standard configuration
enabled: Full API functionality (depends on iron_types, iron_runtime_state, iron_token_manager, iron_telemetry, iron_cost)
use iron_control_api::routes;
use axum::{Router, routing::{get, post}};
// Create API router with endpoints
let app = Router::new()
// Token management
.route( "/api/v1/api-tokens", post( routes::tokens::create_token ) )
.route( "/api/v1/api-tokens/validate", post( routes::tokens::validate_token ) )
.route( "/api/v1/api-tokens", get( routes::tokens::list_tokens ) )
// Agent management
.route( "/api/v1/agents", post( routes::agents::create_agent ) )
.route( "/api/v1/agents", get( routes::agents::list_agents ) )
// Analytics
.route( "/api/v1/analytics/spending/total", get( routes::analytics::get_spending_total ) )
// Health check
.route( "/api/health", get( routes::health::health_check ) );
// Start server
let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await?;
axum::serve(listener, app).await?;

Visual Guide:
See root readme for detailed architecture explanation.
Pilot/Demo Mode (Current):
Production Mode (Post-Pilot):
Health Check:
GET /api/health - Server health statusAuthentication (Protocol 014):
POST /api/v1/auth/login - User authenticationPOST /api/v1/auth/refresh - Refresh JWT tokenPOST /api/v1/auth/logout - User logoutPOST /api/v1/auth/validate - Validate JWT tokenUser Management:
POST /api/v1/users - Create userGET /api/v1/users - List usersGET /api/v1/users/:id - Get user detailsDELETE /api/v1/users/:id - Delete userPUT /api/v1/users/:id/suspend - Suspend userPUT /api/v1/users/:id/activate - Activate userPUT /api/v1/users/:id/role - Change user rolePOST /api/v1/users/:id/reset-password - Reset passwordAPI Token Management (Protocol 014):
POST /api/v1/api-tokens - Create new API tokenPOST /api/v1/api-tokens/validate - Validate API token (public endpoint)GET /api/v1/api-tokens - List all tokens (requires auth)GET /api/v1/api-tokens/:id - Get token detailsPOST /api/v1/api-tokens/:id/rotate - Rotate token secretDELETE /api/v1/api-tokens/:id - Revoke tokenPUT /api/v1/api-tokens/:id - Update token metadataAgent Management (Protocol 010):
POST /api/v1/agents - Create agentGET /api/v1/agents - List agentsGET /api/v1/agents/:id - Get agent detailsPUT /api/v1/agents/:id - Update agentDELETE /api/v1/agents/:id - Delete agentGET /api/v1/agents/:id/tokens - Get agent tokensProvider Key Management:
POST /api/v1/providers - Create provider keyGET /api/v1/providers - List provider keysGET /api/v1/providers/:id - Get provider keyPUT /api/v1/providers/:id - Update provider keyDELETE /api/v1/providers/:id - Delete provider keyPOST /api/v1/projects/:project_id/provider - Assign provider to projectDELETE /api/v1/projects/:project_id/provider - Unassign provider from projectKey Fetch (API Token Auth):
GET /api/v1/keys - Fetch provider key by API tokenUsage Analytics (FR-8):
GET /api/v1/usage/aggregate - Get aggregate usage metricsGET /api/v1/usage/by-project/:project_id - Get usage by projectGET /api/v1/usage/by-provider/:provider - Get usage by providerBudget Limits (FR-9):
POST /api/v1/limits - Create budget limitGET /api/v1/limits - List all limitsGET /api/v1/limits/:id - Get limit detailsPUT /api/v1/limits/:id - Update limitDELETE /api/v1/limits/:id - Delete limitRequest Traces (FR-10):
GET /api/v1/traces - List request tracesGET /api/v1/traces/:id - Get trace detailsBudget Control (Protocol 005 & 012):
POST /api/v1/budget/handshake - Agent budget handshakePOST /api/v1/budget/report - Report usagePOST /api/v1/budget/refresh - Refresh budgetPOST /api/v1/budget/requests - Create budget requestGET /api/v1/budget/requests - List budget requestsGET /api/v1/budget/requests/:id - Get budget requestPATCH /api/v1/budget/requests/:id/approve - Approve requestPATCH /api/v1/budget/requests/:id/reject - Reject requestAnalytics (Protocol 012):
POST /api/v1/analytics/events - Post analytics eventGET /api/v1/analytics/spending/total - Total spendingGET /api/v1/analytics/spending/by-agent - Spending by agentGET /api/v1/analytics/spending/by-provider - Spending by providerGET /api/v1/analytics/spending/avg-per-request - Average spendingGET /api/v1/analytics/budget/status - Budget statusGET /api/v1/analytics/usage/requests - Usage requestsGET /api/v1/analytics/usage/tokens/by-agent - Token usage by agentGET /api/v1/analytics/usage/models - Model usageTest Coverage: 379 tests (100% pass rate)
Run tests:
# Level 1: Unit + integration tests
w3 .test l::1
# Level 3: Tests + doc tests + clippy
w3 .test l::3
Manual testing: See tests/manual/readme.md for comprehensive test procedures
Defense-in-Depth Architecture:
Protections:
Specification: spec.md - Complete API specification with all 10 Functional Requirements
Test Documentation: tests/readme.md - Test organization and coverage summary
Manual Tests: tests/manual/readme.md - Manual testing procedures for FR-7/8/9/10
Version: 0.5 (2025-12-12) Implementation: ✅ COMPLETE (Protocol 014 Tokens + Protocol 010 Agents + Protocol 012 Analytics + Phases 1-5 QA) Test Coverage: 379 tests (100% pass rate, 0 clippy warnings, 0 regressions)
Completed Phases:
Next Steps: Complete Phase 3 enhancements (templates, batch ops, search/filtering), Phase 5 QA completion (performance testing, documentation)
# From workspace root
docker build -f module/iron_control_api/Dockerfile -t iron-backend:latest .
# Check image size
docker images iron-backend:latest
# Expected: ~50-60MB compressed
docker run -d \
-p 3000:3000 \
-e DATABASE_URL="postgresql://iron_user:password@postgres:5432/iron_tokens" \
-e JWT_SECRET="your-secret-min-32-chars" \
-e IRON_DEPLOYMENT_MODE="production" \
-e RUST_LOG=info \
--name iron-backend \
iron-backend:latest
See ../../docker-compose.yml for full stack deployment (PostgreSQL + Backend + Frontend).
# Start all services
docker compose up -d
# View backend logs
docker compose logs -f backend
# Check backend status
docker compose ps backend
curl http://localhost:3000/api/health
# Expected response:
# {"status":"healthy","database":"connected"}
| Variable | Required | Default | Description |
|---|---|---|---|
DATABASE_URL |
Yes | - | PostgreSQL or SQLite connection string |
JWT_SECRET |
Yes | dev-secret-change-in-production |
JWT signing key (32+ chars) |
IRON_DEPLOYMENT_MODE |
No | auto-detect | production, development, or pilot |
RUST_LOG |
No | info |
Log level (error, warn, info, debug, trace) |
IRON_SECRETS_MASTER_KEY |
No | - | AES-256-GCM key for provider key encryption (base64, 32 bytes) |
Issue: Container exits immediately
Solution: Check DATABASE_URL is valid and database is accessible. Run docker logs iron-backend to see startup errors.
Issue: Health check fails
Solution: Ensure database migrations have run. Check database connectivity with docker exec iron-backend curl localhost:3000/api/health.
Issue: Permission denied errors Solution: Container runs as non-root user (UID 1000). Ensure any mounted volumes have correct permissions.
The Dockerfile uses multi-stage builds for security and efficiency:
Stage 1 (Builder): rust:1.75-slim-bookworm
/app/target/release/iron_control_api_serverStage 2 (Runtime): debian:bookworm-slim
Responsibilities: Provides REST API and WebSocket endpoints for programmatic control of Iron Cage runtime (agent lifecycle, monitoring, metrics) and real-time dashboard communication. Enables external tools, CI/CD pipelines, and web dashboards to start agents, monitor execution, and receive live updates via standardized HTTP/WebSocket interfaces. Supports Pilot Mode (localhost, shared iron_runtime_state) and Production Mode (distributed, PostgreSQL + Redis). Requires Rust 1.75+, all platforms supported, integrates with iron_runtime for orchestration and iron_runtime_state for persistence.
In Scope:
Out of Scope:
| File | Responsibility |
|---|---|
| lib.rs | REST API and WebSocket server for Iron Runtime dashboard. |
| error.rs | Custom error types and JSON error responses for API |
| ic_token.rs | ic token claims implementation |
| ip_token.rs | IP Token (Iron Provider Token) encryption |
| jwt_auth.rs | JWT authentication middleware |
| rbac.rs | RBAC (Role-Based Access Control) module |
| token_auth.rs | API Token authentication middleware |
| user_auth.rs | User authentication and password verification |
| bin/ | REST API server binary for Iron Control API |
| middleware/ | Middleware modules for Iron Control API |
| routes/ | REST API route handlers |
Notes: