---
docId: doc_09f45095c6184592830e2e90e1571a14
title: Connect a database
description: "Save a database connection and create its four tools."
api:
  group: herramientas/bases-de-datos
  auth: bearer
  operations:
    - operationId: createDatabase
      method: POST
      path: /v1/tools/databases
      postmanName: Connect a database
---

<script>
  import { Ways, Note } from '$lib/components';
</script>

# Connect a database

Create an `enabled` connection and add its four tools to the [catalog](/api-reference/tools/list). The connection is not tested yet: [test it](/api-reference/databases/test) before assigning it to an agent.

## Example

<Ways tabs="api,sdk">
<Ways.Way name="api">

```bash
curl https://api.platic.ai/v1/tools/databases \
  -H "Authorization: Bearer $PLATIC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "store",
    "engine": "postgres",
    "host": "db.example.com",
    "database": "store",
    "user": "readonly",
    "password": "your-db-password"
  }'
```

</Ways.Way>
<Ways.Way name="sdk">

```ts
await platic.tools.databases.create({ name: "store", engine: "postgres", host: "db.example.com", database: "store", user: "readonly", password: "your-db-password" });
```

</Ways.Way>
</Ways>

## Request body

| Field | Type | Description | Required |
|-------|------|-------------|----------|
| `name` | string | Lowercase letters, digits, and `_`, up to 32; starts with a letter or digit. Tools are named `db_<name>_<tool>` | ✓ |
| `description` | string | What is in the database, up to 500 characters. The agent reads it in its tools to know when to query it | — |
| `engine` | string | `postgres` or `mysql` | Without `connectionString` |
| `host` | string | The public host of the database. On Supabase, the one from the **Session pooler** | Without `connectionString` |
| `port` | number | Defaults to 5432 on PostgreSQL and 3306 on MySQL | — |
| `database` | string | The name of the database on the server | Without `connectionString` |
| `user` | string | The user. Use a read-only one | Without `connectionString` |
| `ssl` | string | `require` (default: encrypts without checking the certificate), `verify` (also checks it), or `disable` | — |
| `connectionString` | string | `postgres://…` or `mysql://…`. Fields you send along with it win | — |
| `password` | string | Up to 4,096 characters. It is stored as a secret and never comes back out | — |
| `passwordSecretId` | string | A [secret](/api-reference/secrets/list) that already has the password, instead of `password` | — |
| `hiddenTables` | string[] | Tables the agent does not see, as `table` or `schema.table`. Up to 500 | — |
| `hiddenColumns` | string[] | Columns the agent does not see, as `table.column` or `schema.table.column`. Up to 500 | — |
| `pageSize` | number | Rows per page, from 1 to 200. Defaults to 50 | — |
| `timeoutSeconds` | number | Time limit of each query, from 1 to 30. Defaults to 5 | — |

With the connection details:

```json
{
  "name": "store",
  "description": "Orders, customers, and inventory of the online store.",
  "engine": "postgres",
  "host": "db.example.com",
  "database": "store",
  "user": "readonly",
  "password": "<password>",
  "hiddenColumns": ["customers.phone"]
}
```

Or with a connection string, which fills in the engine, host, port, database, user, password, and SSL:

```json
{
  "name": "store",
  "connectionString": "postgres://readonly:<password>@db.example.com:5432/store?sslmode=require"
}
```

## Response

`201 Created`. `data` has the connection, with the fields in [get a database](/api-reference/databases/get#response-fields).

```json
{
  "status": "success",
  "message": "Connection created",
  "data": {
    "id": "Xb2mQe7LtR9sKd4fHw1N",
    "name": "store",
    "description": "Orders, customers, and inventory of the online store.",
    "engine": "postgres",
    "host": "db.example.com",
    "port": 5432,
    "database": "store",
    "user": "readonly",
    "ssl": "require",
    "status": "enabled",
    "hiddenTables": [],
    "hiddenColumns": ["customers.phone"],
    "pageSize": 50,
    "timeoutSeconds": 5,
    "password": { "state": "authorized", "secretId": "7e4a1c9b3d5f7a0c2e4b6d8f0a1c3e5b7d9f1a3c5e7b9d0f2a4c6e8b0d2f4a6c", "secretName": "Password of the store database" },
    "tools": [
      { "id": "Xb2mQe7LtR9sKd4fHw1N_list_tables", "name": "db_store_list_tables", "tool": "list_tables" },
      { "id": "Xb2mQe7LtR9sKd4fHw1N_describe_table", "name": "db_store_describe_table", "tool": "describe_table" },
      { "id": "Xb2mQe7LtR9sKd4fHw1N_query", "name": "db_store_query", "tool": "query" },
      { "id": "Xb2mQe7LtR9sKd4fHw1N_next_page", "name": "db_store_next_page", "tool": "next_page" }
    ],
    "lastTest": null,
    "createdAt": "2026-11-14T16:00:00.000Z",
    "updatedAt": "2026-11-14T16:00:00.000Z",
    "nextStep": "Test the connection with POST /v1/tools/databases/Xb2mQe7LtR9sKd4fHw1N/test."
  }
}
```

<Note type="important">

If the connection is saved but the password is not, the response is still `201`: `message` is `Connection saved, but its password was not: see passwordError` and `data.passwordError` has `{ code, message }`. Do not create it again: send the password with [update a database](/api-reference/databases/update).

</Note>

## Errors

| Status | `details.code` | When it happens |
|--------|----------------|-----------------|
| `400` | `INVALID_REQUEST` | The body fails validation: a field is missing, a value is not accepted, or there is an unknown field. `details.issues` says which, without repeating the password |
| `400` | `INVALID_NAME` | `name` does not have the format |
| `400` | `INVALID_CONFIG` | A value does not work, for example a local or private-network host. `details.data.field` says which |
| `400` | `INVALID_CONNECTION_STRING` | The connection string cannot be read or does not start with `postgres://` or `mysql://` |
| `403` | `FORBIDDEN` or `INSUFFICIENT_SCOPE` | The person behind the token does not have access to Integrations, or the token does not have write permission |
| `409` | `NAME_TAKEN` | There is already a connection or a tool with that name |
| `409` | `LIMIT_REACHED` | The workspace already has 20 connections |

## Notes

- Creating does not connect to the database: a wrong value shows up when you [test it](/api-reference/databases/test).
- This call is not retried on its own. If the response is lost, [list the connections](/api-reference/databases/list) before creating it again: a second attempt with the same name answers `NAME_TAKEN`.
- Do not log or display the password after sending it. If an AI assistant connects the database for you, the password goes through that conversation: to avoid it, type it in Platica, under **Integrations → Functions → Database**.
