Managed Database API
This API allows managing your tenant's dedicated SQLite database. Each tenant has exactly one managed database that can be provisioned, accessed via tokens, suspended, and activated.
The TenantDatabase Object
The TenantDatabase object represents your managed database.
Attributes
| Attribute | Description | Type |
|---|---|---|
| id | Unique identifier of the database | String |
| hostname | Database hostname for connections | String |
| status | Current status of the database | String |
| statusMessage | Additional status information | String (nullable) |
| connectionUrl | Full libsql:// connection URL | String |
| tokenExpiresAt | When the last generated token expires | String (ISO 8601) |
| createdAt | Database creation timestamp | String (ISO 8601) |
| updatedAt | Last update timestamp | String (ISO 8601) |
Status Values
| Status | Description |
|---|---|
| active | Database is operational and accepting connections |
| pending | Database is being provisioned |
| suspended | Database is temporarily disabled |
| error | Database encountered an error during provisioning |
Available Operations
Create Database
Creates and provisions a new managed database for your tenant. Each tenant can only have one database.
Request Headers
| Header | Description | Required |
|---|---|---|
| Authorization | Bearer token for authentication | Yes |
Successful Response (201 Created)
Returns the database details with an initial access token.
Response (200 OK)
If a database already exists for the tenant, returns the existing database without a token.
Get Database
Retrieves information about your tenant's managed database.
Request Headers
| Header | Description | Required |
|---|---|---|
| Authorization | Bearer token for authentication | Yes |
Successful Response (200 OK)
Returns the TenantDatabase object.
Error Response (404 Not Found)
Generate Access Token
Generates a new short-lived access token for connecting to your database.
Request Headers
| Header | Description | Required |
|---|---|---|
| Authorization | Bearer token for authentication | Yes |
Input Parameters
| Parameter | Description | Type | Required | Default |
|---|---|---|---|---|
| expiration | Token lifetime (e.g., 30m, 1h, 12h, 24h) | String | No | 1h |
| authorization | Access level: full-access or read-only | String | No | full-access |
Request Example
Successful Response (201 Created)
Validation Rules
- expiration: Must be in format like
30m,1h,24h. Maximum is 24 hours. Non-expiring tokens are not allowed. - authorization: Must be either
full-accessorread-only.
Suspend Database
Temporarily suspends the database, preventing all access.
Request Headers
| Header | Description | Required |
|---|---|---|
| Authorization | Bearer token for authentication | Yes |
Input Parameters
| Parameter | Description | Type | Required |
|---|---|---|---|
| reason | Reason for suspension | String | No |
Request Example
Successful Response (200 OK)
Returns the updated TenantDatabase object with status: "suspended".
Error Response (400 Bad Request)
Returned if the database is not in active state.
Activate Database
Reactivates a suspended or error-state database.
Request Headers
| Header | Description | Required |
|---|---|---|
| Authorization | Bearer token for authentication | Yes |
Successful Response (200 OK)
Returns the updated TenantDatabase object with status: "active".
Error Response (400 Bad Request)
Returned if the database is not in suspended or error state.
Connecting to Your Database
Once you have a token, use the connectionUrl to connect:
HTTP API (Turso Pipeline API)
libSQL Client (TypeScript)
Error Handling
The API may return the following error codes:
| Code | Description |
|---|---|
| 400 | Bad Request - Invalid parameters or invalid state transition |
| 401 | Unauthorized - Missing or invalid authentication |
| 403 | Forbidden - Insufficient permissions |
| 404 | Not Found - No database exists for tenant |
| 409 | Conflict - Database already exists or limit exceeded |
| 503 | Service Unavailable - Turso API temporarily unavailable |
Error SubCodes
Some errors include an errorSubCode in the details for more specific handling:
| SubCode | Description |
|---|---|
| TENANT_DATABASE_LIMIT_EXCEEDED | Tenant already has a database (one per tenant) |
| DATABASE_ALREADY_EXISTS_IN_TURSO | Database already exists in Turso |