Skip to main content

API overview

:::info Implemented by cmd/api cmd/api serves every route below (internal/adapters/inbound/http), on HTTP_ADDR (default :8080). The contracts are apis/openapi.yaml and apis/asyncapi.yaml, pinned by ADR 0001 and ADR 0002. There is no route in the code that the spec does not list: the router registers exactly the six API routes plus /healthz and /readyz. See the Quickstart for real responses. :::

InterfaceSource of truthNotes
RESTapis/openapi.yaml (OpenAPI 3.0.3, version 1.0.0)The pages under REST are generated from the spec with npm run gen-api-docs; do not edit them by hand. Servers named in the spec: http://localhost:8080 (local) and http://localhost:8000/api/task-interleaving (kind cluster through Kong).
Eventsapis/asyncapi.yaml (AsyncAPI 2.6.0, version 1.0.0)Summarised on the event catalogue; every field on Domain events.
MCPADR 0007, internal/adapters/inbound/mcpcmd/mcp serves Streamable HTTP on /mcp (port 8090; through Kong /api/mcp/task-interleaving). Four read-only tools, no write tool: get_site_policy, list_hints (stationId, state, siteId), get_hint, get_station (position and active hint). No auth, by fleet decision.
A2AADR 0009, internal/adapters/inbound/a2acmd/a2a serves JSON-RPC 2.0 on / and /a2a (port 8093; through Kong /api/a2a/task-interleaving), the Agent Card at /.well-known/agent-card.json. Two read-only skills, no write skill: station_hint_status (stationId) and site_interleaving_overview (siteId, limit 1..20). Domain rejections are answered in the message envelope as RFC 7807 problems with the REST slugs, never as JSON-RPC errors. No auth, by fleet decision.

Endpoints​

TagEndpointOperation idSuccess
PolicyPUT /sites/{siteId}/policydeclareInterleavingPolicy200, the policy at its new version, ETag: "<version>"
PolicyGET /sites/{siteId}/policygetInterleavingPolicy200, the policy; 404 policy-not-found for an inert site
HintsGET /hintslistHints200 {items, nextCursor?}, newest first, filters stationId, siteId, state
HintsGET /hints/{hintId}getHint200, the hint with its candidates and outcome
StationsGET /stations/{stationId}getStation200, position, last completed task, Active hint; 404 station-not-found
RecommendationsPOST /recommendationsrecommendTasks200, ranked candidates, possibly empty; read-only simulation
ReportsGET /reports/hint-adoption, GET /reports/freshnessgetHintAdoption, getReportsFreshness200, served by cmd/ti-reports (port 8092; through Kong /api/task-interleaving/reports, prefix rewritten to /reports, konghq.com/regex-priority: "10" so it outranks the /api/task-interleaving api route — in the chart since this PR; live on k3s after the next release, chart pin and apply, see Integration) from the analytical database; see ADR 0008
HealthGET /healthz, GET /readyzhealthz, readyz200 / 200, or 503 once shutdown has started (the spec also says "while starting"; the listener only opens after boot, see Runbook)

Conventions in the contract​

  • Policy versioning. A policy carries version (1 at declaration, +1 per accepted change) and a strong ETag equal to the quoted version. The first declaration sends no If-Match; a replacement must send the current one, and a stale or missing value is 412 version-mismatch. A write that loses a race at the database is 409 concurrent-modification. Declaring identical values again still advances the version.
  • Paging. GET /hints takes limit (1 to 500, default 100) and the opaque cursor (the previous page's nextCursor). No nextCursor marks the last page. Each may be sent once: an empty or repeated limit is 400 invalid-limit, a repeated cursor is 400 invalid-cursor, and a query parameter the operation does not declare is 400 unknown-query-parameter.
  • Idempotency-Key. Documented on POST /recommendations and implemented by internal/adapters/inbound/http/idempotency.go. It is required on every deployment, since Postgres is the only runtime (400 idempotency-key-required when absent, 400 idempotency-key-invalid when it is not 1 to 128 printable ASCII characters); the same key with a different method, path or body is 409 idempotency-key-reused; an equal request replays the stored answer with the response header Idempotency-Replayed: true (a first execution never carries it) when that answer was a success or a refusal that is final for the request (the 400s), for 24 hours after it was stored (an older answer is not replayed: the key is a new request again). A refusal that depends on state that can change (422 policy-not-declared, origin-unknown, station-position-unknown) and every 5xx are not stored: the key is released and the same request under the same key executes again. A copy sent while the first request is still in flight replays the first request's stored answer instead of answering a refusal of its own (ADR 0013).
  • Errors are RFC 7807 application/problem+json with type = https://errors.task-interleaving.warehouse-systems.dev/<slug>. The slugs in the spec: malformed-request, invalid-site-id, invalid-station-id, invalid-hint-id, invalid-policy, invalid-task-type, invalid-cursor, invalid-limit, unknown-query-parameter, invalid-state, idempotency-key-required, idempotency-key-invalid, idempotency-key-reused, policy-not-declared, origin-unknown, station-position-unknown, policy-not-found, hint-not-found, station-not-found, version-mismatch, concurrent-modification and internal-error. The errors that map to these slugs are listed on Use cases and, with remedies, on Troubleshooting.
  • Auth: none. The fleet reverted REST and MCP auth on 2026-09-11, and TestNoAuthMiddlewareReintroduced fails CI if auth middleware returns under internal/adapters/inbound.
  • Advisory by contract. Nothing in this API assigns work to a worker; fulfillment-execution keeps claimNext as its only claim path (ADR 0001).