---
title: "Create a database (optionally attaching DATABASE_URL to a project)"
method: POST
path: "/databases"
tags: ["Databases"]
---

# Create a database (optionally attaching DATABASE_URL to a project)

`POST /databases`

## Request

- Base URL: `https://hostingsurge.com/api/v1`
- URL: `https://hostingsurge.com/api/v1/databases`
- Auth: one of:
  - HTTP bearer
  - API key in cookie `__Host-hs_session`

## Query parameters

- `orgId` string: Organization id (required when you belong to several)

## Request body

- object
  - `name` string, required
  - `engine` 'postgresql' | 'mysql' | 'mariadb' | 'redis' | 'mongodb', required
  - `projectId` string, uuid: connect the new database to this project: its connection string becomes a secret variable (DATABASE_URL; MongoDB: MONGODB_URI and DATABASE_URL; Redis: REDIS_URL), each only where the project has no variable of that name yet
  - `envKey` string: with projectId: the name of the connection string variable instead (like attach)
  - `conventions` boolean: with projectId: also every name the usual frameworks read, like attach and Vercel's integrations; a name of your own (envKey) puts them under its prefix. Names that exist already are a 409 before anything is created, unless overwrite
  - `overwrite` boolean: with projectId and envKey or conventions: replace variables of the same names
  - `isPublic` boolean
  - `backups` boolean: daily backups at 03:00 UTC, kept 30 days (change or remove them under /databases/{id}/backups). false creates the database without a backup schedule: nothing is backed up. Ignored for Redis (no scheduled backups).

## Response `201`

Created

- object
  - `id` string, uuid, required
  - `organizationId` string, uuid, required
  - `projectId` string, uuid, nullable, required
  - `name` string, required
  - `engine` 'postgresql' | 'mysql' | 'mariadb' | 'redis' | 'mongodb', required
  - `version` string, nullable, required
  - `status` 'provisioning' | 'running' | 'stopped' | 'error' | 'deleting', required
  - `isPublic` boolean, required
  - `internalHost` string, nullable, required: reachable from the organization's projects
  - `port` integer, nullable, required
  - `publicHost` string, nullable, required
  - `publicPort` integer, nullable, required
  - `databaseName` string, nullable, required
  - `username` string, nullable, required
  - `password` string, nullable, required: only with databases:reveal and ?reveal=true
  - `connectionUrl` string, nullable, required: masked unless revealed
  - `backupScheduled` boolean: false: the database has no backup schedule, so nothing is backed up (absent for Redis, which has no scheduled backups). PUT /databases/{id}/backups {"frequency": "0 3 * * *", "retentionDays": 30} turns on daily backups.
  - `resources` object, required: CPU and memory limits of the database container; change them with POST /databases/{id}/resources (restarts it)
    - `cpus` number, required
    - `memoryMb` integer, required
  - `createdAt` string, required: ISO-8601 timestamp

## Other responses

- `400`: Invalid request (code invalid_request)
- `401`: Missing or invalid session/token (code unauthorized)
- `402`: Plan limit reached
- `403`: Authenticated but not permitted (code forbidden)
- `404`: Not found or not visible to the caller (code not_found)
- `409`: Conflicting state (code conflict)
- `429`: Too many requests (code rate_limited); see Retry-After
- `503`: Hosting engine unavailable (code provider_unavailable)

---

[API](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api.md) · [All operations](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/llms.txt) · [OpenAPI document](https://skmtc.dev/hostingsurge/apis/hostingsurge-platform-api/revisions/4d08337cdff1?raw)
