# SQL Formatter API
> Format, beautify and minify SQL across 15+ dialects. Pass a query and get it pretty-printed with consistent indentation and keyword casing — for PostgreSQL, MySQL, MariaDB, SQLite, SQL Server (T-SQL), Oracle (PL/SQL), BigQuery, Snowflake, Redshift, Spark, Trino, DuckDB, ClickHouse, DB2, Hive and standard SQL. Control the indent width and whether keywords are upper-cased, lower-cased or left as-is. A minify endpoint collapses a query to a single line (stripping comments while preserving string literals), and a dialects endpoint lists everything supported. Pure local processing — no key, no third-party service, instant. Live. 4 endpoints. Built for SQL editors and IDEs, query loggers, migration tooling, documentation and code review.

## Authentication
All requests require your oanor API key in the `x-oanor-key` header. Get one at https://www.oanor.com/developer/keys.

```bash
curl -H "x-oanor-key: oanor_live_…" "https://api.oanor.com/sqlformat-api/..."
```

## Pricing
- **Free** (Free) — 1,460 calls/Mo, 2 req/s
- **Starter** ($6/Mo) — 26,000 calls/Mo, 8 req/s
- **Pro** ($26/Mo) — 178,000 calls/Mo, 20 req/s
- **Mega** ($62/Mo) — 910,000 calls/Mo, 50 req/s

## Endpoints

### SQL

#### `GET /v1/format` — Format / beautify SQL

**Parameters:**
- `sql` (query, required, string) — SQL query Example: `select id,name from users where age>18 order by name`
- `dialect` (query, optional, string) — postgresql|mysql|sqlite|tsql|bigquery|... Example: `postgresql`
- `keyword_case` (query, optional, string) — upper|lower|preserve
- `tab_width` (query, optional, string) — Indent width

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/sqlformat-api/v1/format?sql=select+id%2Cname+from+users+where+age%3E18+order+by+name&dialect=postgresql"
```

**Response:**
```json
{
    "data": {
        "dialect": "postgresql",
        "formatted": "select\n  id,\n  name\nfrom\n  users\nwhere\n  age > 18\norder by\n  name"
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:58.246Z",
        "request_id": "32aad6d0-278e-4545-8d7a-ee2cdcec31d5"
    },
    "status": "ok",
    "message": "Format SQL",
    "success": true
}
```

#### `GET /v1/minify` — Minify SQL

**Parameters:**
- `sql` (query, required, string) — SQL query Example: `select id, name from users -- c\nwhere age > 18`

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/sqlformat-api/v1/minify?sql=select+id%2C+name+from+users+--+c%5Cnwhere+age+%3E+18"
```

**Response:**
```json
{
    "data": {
        "minified": "select id, name from users"
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:58.353Z",
        "request_id": "f1d5d167-12c5-42be-8d11-94c73cfe6b73"
    },
    "status": "ok",
    "message": "Minify SQL",
    "success": true
}
```

### Reference

#### `GET /v1/dialects` — Supported dialects

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/sqlformat-api/v1/dialects"
```

**Response:**
```json
{
    "data": {
        "count": 21,
        "dialects": [
            "bigquery",
            "clickhouse",
            "db2",
            "db2i",
            "duckdb",
            "hive",
            "mariadb",
            "mysql",
            "n1ql",
            "plsql",
            "postgresql",
            "redshift",
            "spark",
            "sqlite",
            "sql",
            "tidb",
            "trino",
            "transactsql",
            "tsql",
            "singlestoredb",
            "snowflake"
        ]
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:58.444Z",
        "request_id": "952edcc2-b02f-43b6-b4de-11786dc9ab38"
    },
    "status": "ok",
    "message": "Supported dialects",
    "success": true
}
```

### Meta

#### `GET /v1/meta` — Spec

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/sqlformat-api/v1/meta"
```

**Response:**
```json
{
    "data": {
        "auth": "none upstream; this gateway requires x-api-key",
        "name": "SQL Formatter API",
        "note": "Format/beautify SQL (/v1/format?sql=...&dialect=postgresql&keyword_case=upper&tab_width=2) across 15+ dialects (Postgres, MySQL, SQLite, BigQuery, Snowflake, T-SQL, …), and minify SQL to one line (/v1/minify, comments stripped, string literals preserved). /v1/dialects lists the dialects. Instant, nothing stored.",
        "source": "Local SQL formatting (sql-formatter) — no key, no upstream",
        "endpoints": 4
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:58.554Z",
        "request_id": "366de6de-b72f-40dd-8ca2-c107f67b625d"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


---
Marketplace page: https://www.oanor.com/api/sqlformat-api
OpenAPI spec: https://www.oanor.com/api/sqlformat-api/openapi.json
