Skip to content
POST AI agent ready /v1/code/format

Code Format API - Pretty Print JS, JSON, HTML, CSS, SQL, XML

Applies language-specific formatting rules: JSON uses 2-space indentation via JSON.parse/stringify, HTML and XML indent nested tags, CSS expands rules to one-property-per-line, SQL uppercases keywords and newlines major clauses, and JavaScript follows brace-depth indentation.

Parameters

stringrequired

Source code to format.

stringrequired

Language key.

Code examples

curl -X POST https://api.botoi.com/v1/code/format \
  -H "Content-Type: application/json" \
  -d '{"code":"SELECT id, name FROM users WHERE active=true ORDER BY created_at DESC LIMIT 10","language":"sql"}'

When to use this API

Format user-pasted snippets in a web app

Users paste unformatted code into a text area; call this endpoint on blur to normalize it. No local Prettier install or browser-bundle weight required.

Pre-commit formatting for generated code

When a codegen step emits JSON or SQL, format it through this endpoint before writing to disk. Keeps generated files readable in pull requests.

Format LLM-generated SQL for review

LLMs often output single-line SQL. Route the response through this endpoint with language:"sql" to get a multi-line form that reviewers can read in Slack or Notion.

Frequently asked questions

Is the JavaScript formatter equivalent to Prettier?
No. The JS formatter is a simple brace-depth indenter. It does not enforce semicolons, split long lines, or normalize quotes. For full Prettier-compatible formatting, run Prettier locally.
What happens with invalid JSON?
Invalid JSON fails with a FORMAT_ERROR. Use /v1/json/validate first to get a specific parse-error location before attempting to format.
Does SQL formatting work for all dialects?
The keyword list covers standard ANSI SQL plus common extensions (LIMIT, OFFSET, JOIN variants). Dialect-specific syntax (Postgres RETURNING, MSSQL TOP) is preserved but not recognized as formatting boundaries.
Is indentation configurable?
Not in /v1/code/format. JSON uses 2 spaces; SQL uses 2 for subqueries. For finer control, use /v1/sql/format which accepts an indent parameter.
Will this fix syntax errors?
No. The formatter only rearranges whitespace and casing. Syntactically broken code either fails (JSON) or gets re-indented as-is (others).

Get your API key

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