Skip to Content

API Reference

Sitepins exposes two distinct API surfaces:

  1. Express REST Backend (api/): Mounted on /api/v1 (plus unversioned health checks). Handles database operations, authentication, permissions, and media storage.
  2. Next.js Route Handlers (app/src/app/api/): Server-side routes for Git provider code exchanges, AI processing, sandbox lifecycle orchestration, and project previews.

1. Express Backend Endpoints (/api/v1)

Unversioned System Endpoints

MethodEndpointDescription
GET/healthzLiveness & readiness probe. Returns { status: "ok", uptime: <seconds> }.
GET/Returns Welcome to Sitepins API.

Authentication (/api/v1/auth/*)

Powered by Better Auth:

  • POST /api/v1/auth/sign-up/email: Register with email and password (triggers verification OTP).
  • POST /api/v1/auth/sign-in/email: Sign in with email and password.
  • GET /api/v1/auth/callback/github: GitHub OAuth login callback.
  • GET /api/v1/auth/callback/google: Google OAuth login callback.
  • POST /api/v1/auth/verify-email: Confirm email address using 6-digit OTP.
  • POST /api/v1/auth/forget-password: Request password reset email.
  • POST /api/v1/auth/reset-password: Submit new password using reset token.
  • GET /api/v1/auth/get-session: Retrieve current user session.
  • POST /api/v1/auth/sign-out: Invalidate session and clear HTTP cookie.

User Management (/api/v1/user)

MethodEndpointAuth GuardDescription
GET/:idverifyAuthRetrieve user profile by ID.
PATCH/set-passwordverifyAuthUpdate user password.
PATCH/update-country/:idverifyAuthUpdate user’s country of residence.
DELETE/delete/:idverifyAuthPermanently delete user account and cascade cleanups.

Organization Management (/api/v1/organization)

MethodEndpointRequired PermissionDescription
GET/userverifyAuthList all organizations the user belongs to.
GET/:org_idorg:VIEW_PROJECTSRetrieve organization details and members.
POST/verifyAuthCreate a new organization.
POST/ensure-defaultverifyAuthCreate or return the user’s default fallback organization.
PATCH/member/:org_idorg:MANAGE_MEMBERSInvite a new member by email.
PATCH/update-role/:org_idorg:MANAGE_MEMBERSUpdate member role (admin, editor).
PATCH/remove-member/:org_idorg:MANAGE_MEMBERSRemove a member from the organization.
PATCH/leave/:org_idorg:VIEW_MEMBERSLeave an organization (members and admins; owners excluded).
PATCH/status/:org_idorg:MANAGE_ORGUpdate organization status (active, archived).
PATCH/:org_idorg:MANAGE_ORGUpdate organization name, thumbnail, or settings.
DELETE/:org_idorg:DELETE_ORGDelete organization and its projects.

User Preferences (/api/v1/user-preference)

MethodEndpointDescription
GET/:idRetrieve user preferences (theme, language, timezone, Git co-authoring).
PATCH/theme/:idUpdate color theme preference (light, dark, system).
PATCH/language/:idUpdate interface language (15 supported locales).
PATCH/timezone/:idUpdate local timezone setting.
PATCH/impersonate/:idUpdate Git co-authoring attribution (personal vs bot).
PATCH/:idUpdate combined preference attributes.

Project Management (/api/v1/project)

MethodEndpointRequired RoleDescription
GET/:projectIdowner, admin, editorGet project metadata and settings.
GET/orgs/:orgIdowner, admin, editorList all active projects in an organization.
GET/user/:userIdverifyAuthList all projects across organizations owned by the user.
POST/createowner, adminConnect a new repository as a project.
PATCH/:projectIdowner, adminUpdate project configuration (framework, paths).
PATCH/visibility/:projectIdowner, adminToggle public/private project visibility.
PATCH/status/:projectIdowner, adminUpdate project status (active, archived).
PATCH/generator/:projectIdowner, adminUpdate static site generator setting.
PATCH/git/:projectIdowner, adminUpdate connected Git repository and working branch.
PATCH/move/:orgId/:projectIdorg:DELETE_ORGMove project to another organization.
DELETE/:projectIdorg:MANAGE_PROJECTSDelete a project.

Live Preview Sandboxes (/api/v1/project-preview)

MethodEndpointAuth GuardDescription
GET/:project_idmemberOfOrgRetrieve active preview sandbox session metadata.
PUT/:project_idmemberOfOrgUpsert sandbox session state and URLs.
DELETE/:project_idmemberOfOrgTeardown recorded preview sandbox session.

Git Provider Credentials (/api/v1/git-provider)

MethodEndpointAuth GuardDescription
POST/createverifyAuthSave connected Git provider token.
POST/rotateverifyAuthPersist rotated OAuth tokens.
GET/:userIdverifyAuthList connected Git providers for the user.

Content & Activity Feeds

MethodEndpointDescription
GET/api/v1/project-content/:project_idReturns the indexed file tree of the project.
GET/api/v1/project-content/:project_id/file?file=<path>Reads indexed file metadata.
GET/api/v1/project-log/:project_idRetrieves recent file changes and Git activity.
POST/api/v1/project-log/:project_idRecords a file change event (create, update, delete).

Media Uploads (/api/v1/bucket)

MethodEndpointDescription
POST/api/v1/bucket/uploadMultipart file upload to S3 for avatars and project covers.
DELETE/api/v1/bucket/delete/:keyDelete asset by storage key.

2. Next.js Route Handlers (app/api/)

These endpoints execute in the Next.js Node.js runtime and handle external API keys and long-running operations.

Git Provider OAuth & Token Refresh

MethodEndpointDescription
POST/api/auth/githubExchanges the installation code for GitHub App access tokens.
POST/api/auth/github/refreshRotates an expiring GitHub App installation token.
POST/api/auth/gitlabExchanges the authorization code for a GitLab OAuth token.
POST/api/auth/gitlab/refreshRotates GitLab OAuth access tokens.

AI Features (Streaming & BYOK)

MethodEndpointDescription
POST/api/ai/commandStreaming text generation/rewrite assistant for Plate rich-text editor.
POST/api/ai/copilotReal-time inline ghost-text completions (≀50 tokens).
POST/api/ai/chatConversational assistant with project-wide context.
POST/api/ai/code-editAutomated code refactoring and modifications with diff output.
POST/api/ai/code-explainExplains code selections and templates.
POST/api/ai/commitGenerates semantic Git commit messages from staged diffs.
POST/api/ai/metadataAutomated SEO metadata and description extraction.
POST/api/ai/seo-fixAutomated SEO issue remediation.

Live Preview Sandbox Control

MethodEndpointDescription
POST/api/sandbox/createInitializes or connects to a Vercel Sandbox microVM (maxDuration = 600s).
POST/api/sandbox/heartbeatExtends the sandbox timeout by 5 minutes during active sessions.
POST/api/sandbox/stopTerminates and deallocates the preview sandbox.

Standard Response Envelopes

Success Envelope

All Express responses return a consistent JSON wrapper:

{ "statusCode": 200, "success": true, "message": "Operation completed successfully", "result": { "project_id": "proj_abc123", "name": "My Blog" } }

Error Envelope

{ "message": "Validation failed", "errorMessage": [ { "path": "email", "message": "Invalid email format" } ] }
Last updated on