Skip to content

REST API ​

Open API documentation for SwanLab, covering OAuth2 authorization and self-hosted administration. If you plan to integrate SwanLab into a third-party application, this section will help.

Basics ​

API categoryBase URLAvailability
OAuth2 authorizationhttps://api.swanlab.cn/apiPublic Cloud only
Self-hosted administrationhttps://your-swanlab-domain.com/apiSelf-Hosted Commercial Edition only (not supported in Personal Edition, App ≥ 3.6.0)
  • Content type: application/json for requests and responses
  • Domain substitution: for self-hosted administration, replace your-swanlab-domain.com with your self-hosted SwanLab instance host domain

Authentication ​

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

⚠️ Warning

/self_hosted/* requests must include the ApiKey prefix (case-sensitive, followed by a single space and the key). A bare key is treated as no credentials and returns 401; a non-root user's key returns 403.

OAuth2 Authorization ​

For third-party applications integrated with SwanLab, using the public cloud at https://api.swanlab.cn/api:

Integration inquiry

OAuth2 authorization is available on Public Cloud only. To integrate, contact us at contact@swanlab.cn.

  • exchange app_id & app_secret for an Access Token;
  • while the token is valid, fetch the current user's profile or that user's API Key, which authorizes further calls to the open API.
EndpointWhat it doesDocs
POST /auth/oauth2/tokenExchange a code or refresh token for an Access TokenView
GET /auth/oauth2/user/infoFetch the current user's public profile with an Access TokenView
GET /auth/oauth2/user/api_keyFetch the user's latest API Key with an Access TokenView

Self-Hosted Administration ​

Account and collaboration operations for Self-Hosted Commercial Edition instances, called through your instance domain (https://your-swanlab-domain.com/api).

User Management ​

The first deployment creates the single root user (requires a License); afterwards, create users in bulk, reset passwords, deactivate/restore/delete users, and retrieve any user's latest API Key.

EndpointWhat it doesDocs
POST /self_hosted/rootCreate the single root user on first deployment (License required)View
POST /self_hosted/usersCreate users in bulkView
POST /self_hosted/user/passwordChange a password (the root user can change any user's)View
POST /self_hosted/user/pauseDeactivate a user and clear their API Key and sessionsView
POST /self_hosted/user/unpauseRestore a deactivated userView
POST /self_hosted/user/delSoft-delete a user and purge sessions and cacheView
GET /self_hosted/user/key/{username}Get a user's latest API Key, creating one when none existsView

Organization Management ​

Create organization spaces with a designated owner and adjust member roles.

EndpointWhat it doesDocs
POST /self_hosted/teamCreate an organization space with a designated ownerView
POST /self_hosted/team/memberInvite a member to an organization or change their roleView
POST /self_hosted/team/member/delRemove a member from an organizationView

Project Collaboration ​

Add project collaborators with read/write permissions.

EndpointWhat it doesDocs
POST /self_hosted/project/collaboratorInvite a project collaborator or change their permissionView
POST /self_hosted/project/collaborator/delRemove a project collaboratorView

SSO Binding ​

Administrators bind existing users to third-party accounts directly; unbinding and rebinding are supported, and leftovers under deactivated users or Providers can be cleaned up.

EndpointWhat it doesDocs
POST /self_hosted/sso/bindBind a user to a third-party account (duplicate returns 409)View
POST /self_hosted/sso/bind/delUnbind an account, including leftovers under a disabled ProviderView