Перейти к содержимому
POST AI agent ready /v1/sql/format

SQL Format API - Pretty-Print Queries with Keyword Casing

Uppercases SQL keywords, normalizes whitespace, and inserts newlines before major clauses (SELECT, FROM, WHERE, JOIN variants, GROUP BY, ORDER BY, UNION, and more). Subqueries are indented by the configured number of spaces. Dialect-agnostic within standard ANSI SQL.

Parameters

stringrequired

SQL query to format.

number

Indent spaces for subqueries.

Code examples

curl -X POST https://api.botoi.com/v1/sql/format \
  -H "Content-Type: application/json" \
  -d '{"sql":"select id,name from users where active=true order by created_at desc","indent":4}'

When to use this API

Format logged slow queries for review

When your DB exposes slow queries as single-line log entries, format them before pasting into a ticket. Reviewers can read the structure without visually parsing wrapped text.

Normalize queries in migration files

Pre-commit hook that formats every .sql file. Keeps migrations uniform across contributors and makes diffs easier to review.

Render LLM-generated SQL in your UI

LLMs often return compact single-line SQL. Format it through this endpoint before rendering so users see a clean multi-line query instead of a wall of text.

Frequently asked questions

Which SQL dialects are supported?
Standard ANSI SQL with common extensions (LIMIT, OFFSET, INSERT INTO, ALTER TABLE, etc.). Dialect-specific syntax (Postgres RETURNING, MSSQL TOP, MySQL backticks, CTEs) is preserved but not recognized as clause boundaries.
How is subquery indentation controlled?
The indent parameter sets how many spaces to indent SELECT clauses inside parentheses. Default is 2. Pass indent:4 for Python-like depth or 0 to disable.
What happens with keywords that appear as identifiers?
Keywords in string literals ("FROM") and single-quoted strings are not rewritten. Unquoted column names that happen to share keyword names (e.g., a column named "count") will be uppercased; wrap them in quotes or backticks to preserve case.
Does this parse the query?
No. Formatting is regex-based and does not build an AST. Syntactically broken SQL is still formatted (badly) rather than rejected. Use /v1/sql/parse to get structural info.
Will it fix dangerous queries?
No. Formatting is cosmetic. A DELETE without WHERE or a Cartesian JOIN will format cleanly but still do what it says. Run queries through lint rules separately.

Get your API key

Free tier includes 5 requests per minute with no credit card required. Upgrade for higher limits.