Files
Krow-workspace/docs/MILESTONES/M4/planning/m4-api-catalog.md
2026-02-24 11:42:39 -05:00

3.4 KiB

M4 API Catalog (Core Only)

Status: Active
Date: 2026-02-24
Owner: Technical Lead
Environment: dev

Frontend source of truth

Use this file and docs/MILESTONES/M4/planning/m4-core-api-frontend-guide.md for core endpoint consumption.

Verification pipeline design (attire, government ID, certification):

  • docs/MILESTONES/M4/planning/m4-verification-architecture-contract.md

1) Scope and purpose

This catalog defines the currently implemented core backend contract for M4.

2) Global API rules

  1. Route group in scope: /core/*.
  2. Compatibility aliases in scope:
  • POST /uploadFile -> POST /core/upload-file
  • POST /createSignedUrl -> POST /core/create-signed-url
  • POST /invokeLLM -> POST /core/invoke-llm
  1. Auth model:
  • GET /health is public in dev
  • all other routes require Authorization: Bearer <firebase-id-token>
  1. Standard error envelope:
{
  "code": "STRING_CODE",
  "message": "Human readable message",
  "details": {},
  "requestId": "optional-request-id"
}
  1. Response header:
  • X-Request-Id

3) Core routes

3.1 Upload file

  1. Method and route: POST /core/upload-file
  2. Request format: multipart/form-data
  3. Fields:
  • file (required)
  • visibility (public or private, optional)
  • category (optional)
  1. Accepted types:
  • application/pdf
  • image/jpeg
  • image/jpg
  • image/png
  1. Max size: 10 MB (default)
  2. Behavior: real upload to Cloud Storage.
  3. Success 200:
{
  "fileUri": "gs://krow-workforce-dev-private/uploads/<uid>/...",
  "contentType": "application/pdf",
  "size": 12345,
  "bucket": "krow-workforce-dev-private",
  "path": "uploads/<uid>/...",
  "requestId": "uuid"
}
  1. Errors:
  • UNAUTHENTICATED
  • INVALID_FILE_TYPE
  • FILE_TOO_LARGE

3.2 Create signed URL

  1. Method and route: POST /core/create-signed-url
  2. Request:
{
  "fileUri": "gs://krow-workforce-dev-private/uploads/<uid>/file.pdf",
  "expiresInSeconds": 300
}
  1. Security checks:
  • bucket must be allowed
  • path must be owned by caller (uploads/<caller_uid>/...)
  • object must exist
  • expiresInSeconds <= 900
  1. Success 200:
{
  "signedUrl": "https://storage.googleapis.com/...",
  "expiresAt": "2026-02-24T15:22:28.105Z",
  "requestId": "uuid"
}
  1. Errors:
  • VALIDATION_ERROR
  • FORBIDDEN
  • NOT_FOUND

3.3 Invoke model

  1. Method and route: POST /core/invoke-llm
  2. Request:
{
  "prompt": "...",
  "responseJsonSchema": {},
  "fileUrls": []
}
  1. Behavior:
  • real Vertex AI call
  • model default: gemini-2.0-flash-001
  • timeout default: 20 seconds
  1. Rate limit:
  • 20 requests/minute per user (default)
  • when exceeded: 429 RATE_LIMITED and Retry-After header
  1. Success 200:
{
  "result": {},
  "model": "gemini-2.0-flash-001",
  "latencyMs": 367,
  "requestId": "uuid"
}
  1. Errors:
  • UNAUTHENTICATED
  • VALIDATION_ERROR
  • MODEL_TIMEOUT
  • MODEL_FAILED
  • RATE_LIMITED

3.4 Health

  1. Method and route: GET /health
  2. Success 200:
{
  "ok": true,
  "service": "krow-core-api",
  "version": "dev",
  "requestId": "uuid"
}

4) Locked defaults

  1. Validation library: zod.
  2. Validation schema location: backend/core-api/src/contracts/.
  3. Buckets:
  • krow-workforce-dev-public
  • krow-workforce-dev-private
  1. Model provider: Vertex AI Gemini.
  2. Max signed URL expiry: 900 seconds.
  3. LLM timeout: 20000 ms.
  4. LLM rate limit: 20 requests/minute/user.