Skip to content

Gateway API

The gateway worker (worker-gateway) is the single entry point for all API requests. It handles session verification, request routing, and header injection for downstream workers.

Base URL

http://localhost:8787 (development)
https://api.example.com (production)

Authentication

Most endpoints require a valid Better Auth session cookie (better-auth.session_token). The gateway verifies the session by calling worker-auth internally and injects user context headers before proxying.

Injected Headers

When a session is valid, the gateway adds these headers to downstream requests:

HeaderDescription
X-User-IdAuthenticated user’s ID
X-User-RoleUser role (user or admin)
X-App-KeyApplication key for multi-tenant isolation

Route Map

Public Routes (no session required)

MethodPathUpstreamDescription
*/auth/*worker-authBetter Auth endpoints (sign-up, sign-in, etc.)
POST/payment/webhook/*worker-billingPayment provider webhooks

Authenticated Routes

MethodPathUpstreamDescription
*/credits/*worker-billingCredit balance and transactions
*/checkin /checkin/*worker-billingDaily check-in
*/orders /orders/*worker-billingOrder history
*/subscription/*worker-billingSubscription management
*/payment/*worker-billingPayment session creation
*/tickets /tickets/*worker-supportSupport tickets
*/keys /keys/*worker-aiAPI key management
*/user/*worker-authUser profile
*/content/*worker-contentPublic content

Admin Routes (requires admin role)

MethodPathUpstreamDescription
*/admin/billing/*worker-billingBilling administration
*/admin/credits/*worker-billingCredit administration
*/admin/checkin/*worker-billingCheck-in configuration
*/admin/ai/*worker-aiAI provider/model management
*/admin/posts /admin/posts/*worker-contentBlog post management
*/admin/banners /admin/banners/*worker-contentBanner management
*/admin/friend-links /admin/friend-links/*worker-contentFriend link management
*/admin/*worker-adminOther admin operations

Error Responses

All API responses use a consistent format:

Success

{
"ok": true,
"data": { ... }
}

Error

{
"ok": false,
"error": {
"code": "UNAUTHORIZED",
"message": "Invalid or expired session"
}
}

Common Error Codes

CodeHTTP StatusDescription
UNAUTHORIZED401Missing or invalid session
FORBIDDEN403Insufficient permissions
NOT_FOUND404Resource not found
VALIDATION_ERROR400Request body failed schema validation
INTERNAL_ERROR500Unexpected server error