Create database
Create a new database in PlanetScale and connect it to a project. PlanetScale bills the database from the moment it is created.
Unkey checks the project and the PlanetScale account first, so a request that cannot be connected creates nothing.
The new database is not ready at once. List the databases of the project to see when its availability is ready.
Important:
- The workspace must have exactly one PlanetScale account connected. With more than one you get a
412. - The database can be in any organization that the PlanetScale account can see.
integrations.planetscale.listOrganizationslists them. - A region that
integrations.planetscale.listRegionsdoes not list gets a400. - If the organization already has a database with this name, you get a
409. - If PlanetScale does not confirm the create, you get a
503. The database can exist. Check the organization in PlanetScale before you try again, so you are not billed twice. - If PlanetScale created the database but Unkey could not connect it, you get a
409with the typedatabase_created_not_connected. PlanetScale bills that database. Connect it withdatabases.connectDatabase, or delete it in PlanetScale.
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 create a database in any project)unkey:v1:<workspace_id>:projects/<project_id>/databases/*#write(to create a database in 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 created in PlanetScale and connected to the project.