---
title: "Connect AI Agents to Your Database — Read-Only API"
description: "Connect any AI agent to your database with a read-only API. Natural language or SQL. Works with LangChain, Claude, CrewAI, GPT. Scoped keys, every query audited."
canonical: "https://www.aifordatabase.com/agents/"
---

# Connect my AI agent to any database

AI Agent Database Access



Read-only access. Natural language or SQL. Scoped API keys. Works with LangChain, CrewAI, Claude, GPT.

[Get my API key](https://app.aifordatabase.com/signup)[View API docs](https://www.aifordatabase.com/docs/)

## Why not just connect directly?

### Raw Database MCP

*   Agent gets column names only
*   Guesses what metrics mean
*   Can DROP TABLE
*   No usage tracking
*   No shared state

### AI for Database

*   Schema + business context
*   Canonical metric definitions
*   Read-only guardrailed
*   Every query audited
*   Cross-agent shared state

## How it works

01

### Discover

List sanitized connections, health state, and cached database schemas.

02

### Validate

Run read-only SQL and inspect structured columns, rows, count, and timing.

03

### Draft

Create a paused workflow with an encrypted, destination-bound credential.

04

### Preview

Execute draft queries without contacting the action destination.

05

### Test

Explicitly confirm one live action and inspect sanitized delivery attempts.

06

### Publish

Activate an immutable version and inspect every scheduled production run.

## What agents build with this

#### Autonomous Reporting

Agent pulls metrics on a schedule, posts to Slack

API`POST /api/v1/chat`

#### Smart Customer Support

Agent checks order status before responding to tickets

API`POST /api/v1/connections/{id}/query`

#### Anomaly Detection

Workflow detects failures, webhooks your agent

API`POST /api/v1/workflows`

#### Investor Updates

Agent builds dashboards with 12 months of data

API`POST /api/v1/dashboards`

#### Cross-Database Analysis

Query Postgres + MySQL in one conversation

API`POST /api/v1/chat`

#### Data Pipeline Monitoring

Freshness checks + schema drift alerts

API`POST /api/v1/workflows`

#### Lifecycle Automation

Query eligible users on a schedule and send authenticated webhook events

API`POST /api/v1/workflows`

## Built for agents, not humans in a browser

### Smart Connections

When you connect a database, we introspect every table, column, and relationship. Your agent gets a structured schema summary without needing to run discovery queries.

```
GET /api/v1/connections/{id}/schema

{
  "tables": [
    {
      "name": "orders",
      "columns": ["id", "customer_id", "total", "status"],
      "relationships": ["customers.id -> orders.customer_id"],
      "description": "All customer orders with payment status"
    }
  ]
}
```

### Semantic Layer

Define what "revenue" means once. Every agent that queries your database uses the same definition. No more conflicting metrics across tools.

```
// Metric definition stored in AI for Database
{
  "metric": "revenue",
  "sql": "SUM(orders.total) WHERE orders.status = 'paid'",
  "description": "Total paid order revenue, excluding refunds"
}

// Agent asks: "What is revenue this quarter?"
// AI for Database applies the canonical definition automatically
```

### Saved Queries

Create reusable query templates with parameters. Your agent calls them by name instead of generating SQL from scratch every time.

```
POST /api/v1/chat
{
  "message": "Run saved query: top_customers",
  "parameters": { "limit": 10, "period": "last_30_days" }
}

// Returns structured JSON, not raw SQL
{
  "data": {
    "rows": [...],
    "columns": ["customer_name", "total_revenue", "order_count"]
  }
}
```

### Query Approval

Set rules for which queries run automatically and which need human approval. Critical for production agents that touch sensitive data.

```
// Approval policy configuration
{
  "auto_approve": [
    "SELECT on public.*",
    "Saved queries tagged 'safe'"
  ],
  "require_approval": [
    "Queries touching PII columns",
    "Cross-database joins",
    "Queries estimated > 10s execution"
  ]
}
```

## Drop-in integration

```
curl -X POST https://app.aifordatabase.com/api/v1/chat \
  -H "Authorization: Bearer afd_your_key" \
  -H "Content-Type: application/json" \
  -d '{
    "message": "Top 10 customers by revenue",
    "connectionId": "conn_abc123"
  }'
```

## Works with everything

Frameworks & Platforms

Claude via RESTOpenAI ActionsLangChainCrewAIVercel AI SDKAutoGen

Databases

PostgreSQLMySQLMongoDBSQL ServerSQLite

## Pricing

### Free

Prototype my agent

$0forever

*   Free AI models
*   3 workflows
*   60 req/min
*   Community support

[Start free](https://app.aifordatabase.com/signup)

### Pro

Production agents

$10/mo

*   All premium models
*   Unlimited workflows
*   300 req/min
*   Priority support

[Get Pro](https://app.aifordatabase.com/signup)

### Enterprise

Custom deployment and SLA

Custom

*   Self-hosted option
*   SSO & audit logs
*   Custom rate limits
*   Dedicated support

[Contact us](https://www.aifordatabase.com/contact/)

## Give my agent a database in 5 minutes

Sign upAdd connectionGet API keyAgent is live

[Start free](https://app.aifordatabase.com/signup)

Source: https://www.aifordatabase.com/agents/
