How to Configure Vercel AI SDK Postgres Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up vercel ai sdk postgres credentials by making a read-only database role. Then you pass that login string into your app runtime. Many teams skip this step and reuse their main app database login. That shortcut gives AI tools full write and delete powers across every table. One bad prompt can change records or leak private rows. How to set up vercel ai sdk postgres credentials Start by creating a dedicated role in your database for AI tool calls. Do not share the login that runs your

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up vercel ai sdk postgres credentials by making a read-only database role. Then you pass that login string into your app runtime. Many teams skip this step and reuse their main app database login. That shortcut gives AI tools full write and delete powers across every table. One bad prompt can change records or leak private rows.

How to set up vercel ai sdk postgres credentials

Start by creating a dedicated role in your database for AI tool calls. Do not share the login that runs your web backend or schema migrations. In PostgreSQL, you can create a group role to manage read rules cleanly. You then grant your new AI login membership in that group role.

Next, lock down what this new role can do by default. In PostgreSQL, the special PUBLIC role gives rights to every user on the system. By default, PUBLIC allows database logins, temp tables, and function execution. Your database owner can revoke these default rights so the AI role starts empty.

If your database was upgraded from before version 15, check the public schema too. Older setups let every user create new objects inside the public schema. An admin fixes this by revoking create rights on the public schema from PUBLIC. In version 15 and newer, the default setup blocks this behavior by default.

Now grant read rights only on the exact data the model needs. The SELECT right lets a role read from a whole table or view. You can also grant SELECT on specific columns instead of the entire table. Column grants help you keep secret tokens or password hashes out of reach. Keep in mind that the SELECT right also allows copying table data out.

What native database roles solve and what they miss

Native roles and column grants stop an AI tool from dropping tables. They also stop the model from reading columns you did not allow. This setup decides who can log in and which objects they can touch. Every production team should set up these base rules first.

Ephemeral Credentials + AI Agent Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, static database logins cannot check what happens inside an allowed query. Once the app logs in, the database trusts every valid read statement. A model with read access to a customer table can still pull thousands of rows. Column grants are also all or nothing for each field you expose.

Suppose your support agent needs to look up orders by customer email. You must grant SELECT on the email and phone number columns. Now every query returns raw emails, phone numbers, card numbers, and national IDs. Native Postgres roles cannot rewrite matched fields in results while queries run. They also do not tie individual SQL statements back to a specific user prompt. Teams need runtime controls to mask sensitive values and inspect queries in flight.

Managing secret rotation for AI database logins

Storing static database passwords in app settings creates ongoing maintenance work for engineers. When a key leaks or an engineer leaves, you must rotate that password. Rotating a shared login means updating secrets across every deployed service at once. Using a separate role for AI tools makes rotation safer for your main app. Still, static keys live in memory and stay valid until someone changes them.

Check every Postgres query on the wire

Database roles and network rules decide who can open a session. They do not read what each SQL statement does after login. With hoop.dev, you run an open-source proxy, a sidecar for your Postgres. It runs beside your database and reads the Postgres wire protocol. Your apps and agents keep their login details and change only the host and port in the connection string their tool uses.

Before a query runs, hoop.dev guardrails check the statement by its effect, table, or pattern. They refuse bad deletes or drops with a real Postgres error. On the way back, hoop.dev data masking rewrites sensitive values in returned rows based on your rules. Every query and verdict goes to the audit trail. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and generates evidence for HIPAA, GDPR, and PCI DSS. See the code on GitHub.

Frequently asked questions

Should my AI tools share the main app database login?

No, you should never share the main app login with AI tool functions. Create a separate Postgres role that only has read access to needed columns. This prevents a bad model output from changing or deleting production records.

Can Postgres restrict an AI role to specific columns?

Yes, PostgreSQL lets you grant the SELECT privilege on specific columns of a table. The role will only be able to read the exact columns you list. Queries that ask for other columns in that table will fail right away.

Why can a new Postgres role execute functions without explicit grants?

PostgreSQL grants default rights to a special group called PUBLIC that includes all roles. By default, PUBLIC allows users to connect, make temp tables, and run functions. A database owner must revoke these default rights from PUBLIC to block them.

The query runs. The emails stay hidden.