Issue: #557 - Feature: ACP Rest API Date: 2026-01-29 Status: Approved
Create a Public API service that acts as the single entry point for all clients (Browser, SDK, MCP). This thin shim layer proxies requests to the existing Go backend while providing simplified DTOs and a versioned API.
┌─────────────────────────────────────────────────────────────────┐
│ Clients │
│ - Browser (via OAuth proxy) │
│ - SDK (direct with access key) │
│ - MCP (direct with access key) │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Public API (NEW) │
│ - Versioned endpoints (/v1/sessions, etc.) │
│ - Simplified JSON responses │
│ - Token validation & project extraction │
│ - Proxies to Go Backend │
└─────────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ Go Backend (internal only) │
│ - Full K8s/CRD operations │
│ - ClusterIP service (no external route) │
│ - Existing /api/projects/... endpoints │
└─────────────────────────────────────────────────────────────────┘
- Single entry point - All clients use the Public API
- Frontend simplified - Remove Next.js API routes, just static files + token forwarding middleware
- Backend internalized - Go backend becomes ClusterIP only, not exposed externally
- Thin shim - Public API is a lightweight proxy (~500 lines), not a full rewrite
| Client | Auth Method | Flow |
|---|---|---|
| Browser | OAuth Proxy | OAuth Proxy → Public API (token in header) |
| SDK | Access Key | Direct to Public API with Bearer token |
| MCP | Access Key | Direct to Public API with Bearer token |
- Browser: OAuth proxy sets
X-Forwarded-Access-Token, forwarded to Public API - SDK/MCP: Pass OpenShift token or access key as
Authorization: Bearer <token> - Project extraction: For SDK/MCP, extract project from ServiceAccount namespace in JWT
| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/sessions |
List sessions (requires X-Ambient-Project header or token-based project) |
| POST | /v1/sessions |
Create session |
| GET | /v1/sessions/{id} |
Get session details |
| DELETE | /v1/sessions/{id} |
Delete session |
// GET /v1/sessions/{id}
type SessionResponse struct {
ID string `json:"id"`
Status string `json:"status"` // "pending", "running", "completed", "failed"
Task string `json:"task"`
Model string `json:"model,omitempty"`
CreatedAt string `json:"createdAt"`
CompletedAt string `json:"completedAt,omitempty"`
Result string `json:"result,omitempty"`
Error string `json:"error,omitempty"`
}
// GET /v1/sessions
type SessionListResponse struct {
Items []SessionResponse `json:"items"`
Total int `json:"total"`
}
// POST /v1/sessions
type CreateSessionRequest struct {
Task string `json:"task" binding:"required"`
Model string `json:"model,omitempty"`
Repos []Repo `json:"repos,omitempty"`
}
type Repo struct {
URL string `json:"url" binding:"required"`
Branch string `json:"branch,omitempty"`
}components/public-api/
├── main.go # Entry point, server setup
├── handlers/
│ ├── sessions.go # /v1/sessions handlers
│ ├── middleware.go # Auth, project extraction
│ └── proxy.go # Backend proxy utilities
├── types/
│ └── dto.go # Simplified DTOs
├── Dockerfile
└── README.md
- Remove
src/app/api/**routes (proxy handlers) - Keep simple middleware for OAuth token forwarding
- Update API calls to use Public API URL
- Add
public-api-deployment.yaml - Add
public-api-service.yaml - Add
public-api-route.yaml(external) - Modify
backend-route.yaml→ remove from production (backend becomes internal) - Update frontend to point to Public API
- Create
components/public-api/structure - Implement
/v1/sessionsendpoints with backend proxy - Add auth middleware (token validation, project extraction)
- Add Dockerfile and deployment manifests
- Remove Next.js API route handlers
- Update frontend to call Public API directly
- Keep OAuth token forwarding middleware
- Remove
backend-route.yamlfrom production - Verify backend is only accessible via ClusterIP
- Update documentation
- Public API service is deployable (Dockerfile, manifests, CI/CD in place)
- Can list/create/get/delete sessions via
curlto Public API (verified via e2e tests) - Browser continues to work through Public API (Phase 2: Frontend migration)
- SDK/MCP can authenticate with access keys (Bearer token and X-Forwarded-Access-Token supported)
- Latency < 200ms for API requests (requires Prometheus metrics - Phase 3)
# Create access key (one-time, via UI or existing API)
# Then use it for all API calls:
export AMBIENT_API="https://api.ambient-code.example.com"
export AMBIENT_TOKEN="<access-key>"
export AMBIENT_PROJECT="my-project"
# List sessions
curl -H "Authorization: Bearer $AMBIENT_TOKEN" \
-H "X-Ambient-Project: $AMBIENT_PROJECT" \
"$AMBIENT_API/v1/sessions"
# Create session
curl -X POST \
-H "Authorization: Bearer $AMBIENT_TOKEN" \
-H "X-Ambient-Project: $AMBIENT_PROJECT" \
-H "Content-Type: application/json" \
-d '{"task": "Refactor login.py", "model": "claude-sonnet-4"}' \
"$AMBIENT_API/v1/sessions"