Skip to content

REST API ​

SwanLab OpenAPI reference covering Public Cloud OAuth2 authorization and self-hosted instance administration. Use these endpoints to integrate SwanLab into third-party applications or internal enterprise workflows.

Overview ​

API CategoryBase URLAvailability
OAuth2 Authorizationhttps://api.swanlab.cn/apiPublic Cloud only
Self-Hosted Administrationhttps://your-swanlab-domain.com/apiSelf-Hosted Commercial Edition only (not available in Personal Edition; App ≥ 3.6.0)
  • Content-Type: Both request and response payloads use application/json.
  • Base URL substitution: For self-hosted administration endpoints, replace your-swanlab-domain.com with the actual domain of your self-hosted SwanLab instance.

Authentication ​

EndpointAuthorization Header
POST /auth/oauth2/tokenAuthorization: Basic base64(app_id:app_secret)
GET /auth/oauth2/user/*Authorization: Bearer <access_token>
POST /self_hosted/rootNo authentication required
Other /self_hosted/* endpointsAuthorization: ApiKey <root user's API Key>

⚠️ Important

Requests to /self_hosted/* endpoints must include the case-sensitive ApiKey prefix followed by a single space and the key. Passing a bare key without the prefix is treated as unauthenticated and returns 401 Unauthorized; using a non-root user's API Key returns 403 Forbidden.

OAuth2 Authorization ​

Designed for third-party applications integrating with SwanLab Public Cloud (https://api.swanlab.cn/api):

Integration Inquiry

OAuth2 authorization is available on SwanLab Public Cloud only. To register an OAuth application, please contact us at contact@swanlab.cn.

  • Authenticate with app_id and app_secret to exchange an authorization code or refresh token for an access_token.
  • Use a valid access_token to retrieve the authenticated user's public profile or obtain their latest API Key for subsequent OpenAPI calls.
EndpointDescriptionReference
POST /auth/oauth2/tokenIssue or refresh an access_token via authorization code / tokenView
GET /auth/oauth2/user/infoRetrieve the authenticated user's public profileView
GET /auth/oauth2/user/api_keyRetrieve the authenticated user's latest API KeyView

Self-Hosted Administration ​

Account lifecycle and access control APIs for Self-Hosted Commercial Edition instances, invoked via your instance domain (https://your-swanlab-domain.com/api).

User Management ​

Initialize the single root administrator (root) on first deployment using a commercial license, then provision users in bulk, reset passwords, deactivate/restore/delete accounts, and retrieve any active user's latest API Key.

EndpointDescriptionReference
POST /self_hosted/rootInitialize the single root user on first deployment (requires valid License)View
POST /self_hosted/usersBulk create user accountsView
POST /self_hosted/user/passwordChange a user's password (the root user can reset any user's password)View
POST /self_hosted/user/pauseDeactivate a user and revoke their API Keys and active sessionsView
POST /self_hosted/user/unpauseRestore a deactivated user accountView
POST /self_hosted/user/delSoft-delete a user and purge associated sessions, cache, and SSO bindingsView
GET /self_hosted/user/key/{username}Retrieve a user's latest API Key (automatically generates one if none exists)View

Organization Management ​

Create organization workspaces with a designated owner and manage organization memberships and roles.

EndpointDescriptionReference
POST /self_hosted/teamCreate an organization workspace with a designated ownerView
POST /self_hosted/team/memberAdd an organization member or update their roleView
POST /self_hosted/team/member/delRemove a member from an organizationView

Project Collaboration ​

Manage project collaborators and their read/write/admin permissions.

EndpointDescriptionReference
POST /self_hosted/project/collaboratorAdd a project collaborator or update their permissionView
POST /self_hosted/project/collaborator/delRemove a collaborator from a projectView

SSO Binding ​

Administrators can directly bind existing SwanLab users to external SSO accounts without requiring user interaction. Unbinding and rebinding are supported, including cleaning up residual bindings under disabled providers or deactivated users.

EndpointDescriptionReference
POST /self_hosted/sso/bindBind a SwanLab user to a third-party SSO account (duplicate returns 409)View
POST /self_hosted/sso/bind/delUnbind a third-party SSO account (supports cleaning up residual SSO bindings)View