Connect database
Connect a database that already exists in PlanetScale to a project.
Unkey reads the database from PlanetScale with the PlanetScale account of the workspace. Nothing changes in PlanetScale.
After this, connect an environment of the project to a branch of the database to give its deployments a database URL.
Important:
- The workspace must have exactly one PlanetScale account connected. With more than one you get a
412. - The databases can be in any organization that the PlanetScale account can see.
integrations.planetscale.listOrganizationslists them. - A database that is already connected to the project gets a
409.
The workspace must have the databases, connections and app_v2 flags. Without them you get a 403.
Required Permissions
Your root key must have one of the following permissions:
unkey:v1:<workspace_id>:projects/*/databases/*#write(to connect a database to any project)unkey:v1:<workspace_id>:projects/<project_id>/databases/*#write(to connect a database to one project)
Replace <workspace_id> with the authenticated workspace ID.
Authorizations
Unkey uses bearer tokens for authentication. Public integrations use root keys, while the dashboard proxy uses short-lived JWTs. To authenticate, include the token in the Authorization header of each request:
Root keys have specific permissions attached to them, controlling what operations they can perform. Resource permissions use Unkey Resource Names plus actions, like unkey:v1:ws_123:projects/*/keyspaces/*/keys/*#write.
Security best practices:
- Keep root keys secure and never expose them in client-side code
- Use different root keys for different environments
- Rotate keys periodically, especially after team member departures
- Create keys with minimal necessary permissions following least privilege principle
- Monitor key usage with audit logs.
Body
Response
The database is connected to the project.