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 Category | Base URL | Availability |
|---|---|---|
| OAuth2 Authorization | https://api.swanlab.cn/api | Public Cloud only |
| Self-Hosted Administration | https://your-swanlab-domain.com/api | Self-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.comwith the actual domain of your self-hosted SwanLab instance.
Authentication
| Endpoint | Authorization Header |
|---|---|
POST /auth/oauth2/token | Authorization: Basic base64(app_id:app_secret) |
GET /auth/oauth2/user/* | Authorization: Bearer <access_token> |
POST /self_hosted/root | No authentication required |
Other /self_hosted/* endpoints | Authorization: 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_idandapp_secretto exchange an authorization code or refresh token for anaccess_token. - Use a valid
access_tokento retrieve the authenticated user's public profile or obtain their latest API Key for subsequent OpenAPI calls.
| Endpoint | Description | Reference |
|---|---|---|
POST /auth/oauth2/token | Issue or refresh an access_token via authorization code / token | View |
GET /auth/oauth2/user/info | Retrieve the authenticated user's public profile | View |
GET /auth/oauth2/user/api_key | Retrieve the authenticated user's latest API Key | View |
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.
| Endpoint | Description | Reference |
|---|---|---|
POST /self_hosted/root | Initialize the single root user on first deployment (requires valid License) | View |
POST /self_hosted/users | Bulk create user accounts | View |
POST /self_hosted/user/password | Change a user's password (the root user can reset any user's password) | View |
POST /self_hosted/user/pause | Deactivate a user and revoke their API Keys and active sessions | View |
POST /self_hosted/user/unpause | Restore a deactivated user account | View |
POST /self_hosted/user/del | Soft-delete a user and purge associated sessions, cache, and SSO bindings | View |
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.
| Endpoint | Description | Reference |
|---|---|---|
POST /self_hosted/team | Create an organization workspace with a designated owner | View |
POST /self_hosted/team/member | Add an organization member or update their role | View |
POST /self_hosted/team/member/del | Remove a member from an organization | View |
Project Collaboration
Manage project collaborators and their read/write/admin permissions.
| Endpoint | Description | Reference |
|---|---|---|
POST /self_hosted/project/collaborator | Add a project collaborator or update their permission | View |
POST /self_hosted/project/collaborator/del | Remove a collaborator from a project | View |
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.
| Endpoint | Description | Reference |
|---|---|---|
POST /self_hosted/sso/bind | Bind a SwanLab user to a third-party SSO account (duplicate returns 409) | View |
POST /self_hosted/sso/bind/del | Unbind a third-party SSO account (supports cleaning up residual SSO bindings) | View |