# Prettier API
> Format and beautify source code with Prettier, the de-facto code formatter. Pass code and a language and get it consistently re-formatted: JavaScript, JSX, TypeScript, TSX, CSS, SCSS, LESS, GraphQL and Vue. Tune the output with print width, tab width / tabs, semicolons, single vs double quotes and trailing-comma style. Syntax errors come back with a clear message. The inverse of a minifier. Pure local processing — no key, no third-party service, instant. Live. 3 endpoints. Built for code editors and playgrounds, paste-and-format tools, snippet beautification, docs and CI formatting checks. Complements the SQL formatter and the JSON/YAML/Markdown tools (which cover their own languages).

## 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/prettier-api/..."
```

## Pricing
- **Free** (Free) — 1,380 calls/Mo, 2 req/s
- **Starter** ($6/Mo) — 22,000 calls/Mo, 8 req/s
- **Pro** ($25/Mo) — 170,000 calls/Mo, 20 req/s
- **Mega** ($61/Mo) — 870,000 calls/Mo, 50 req/s

## Endpoints

### Format

#### `GET /v1/format` — Format code with Prettier

**Parameters:**
- `code` (query, required, string) — Source code Example: `const x=[1,2,3].map(i=>i*2);console.log(x)`
- `language` (query, required, string) — js|jsx|ts|tsx|css|scss|less|graphql|vue Example: `js`
- `print_width` (query, optional, string) — Wrap width (default 80)
- `tab_width` (query, optional, string) — Indent width
- `single_quote` (query, optional, string) — true for single quotes
- `semi` (query, optional, string) — false to omit semicolons

**Example:**
```bash
curl -H "x-oanor-key: $KEY" \
  "https://api.oanor.com/prettier-api/v1/format?code=const+x%3D%5B1%2C2%2C3%5D.map%28i%3D%3Ei%2A2%29%3Bconsole.log%28x%29&language=js"
```

**Response:**
```json
{
    "data": {
        "parser": "babel",
        "language": "js",
        "formatted": "const x = [1, 2, 3].map((i) => i * 2);\nconsole.log(x);\n"
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:56.844Z",
        "request_id": "de384e7e-1662-47dc-863a-c918900fb65c"
    },
    "status": "ok",
    "message": "Format code with Prettier",
    "success": true
}
```

### Reference

#### `GET /v1/languages` — Supported languages

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

**Response:**
```json
{
    "data": {
        "count": 15,
        "parsers": [
            "babel",
            "flow",
            "typescript",
            "css",
            "scss",
            "less",
            "graphql",
            "vue",
            "json5"
        ],
        "languages": [
            "js",
            "javascript",
            "jsx",
            "babel",
            "flow",
            "ts",
            "typescript",
            "tsx",
            "css",
            "scss",
            "less",
            "graphql",
            "gql",
            "vue",
            "json5"
        ]
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:56.950Z",
        "request_id": "2f6b5ae1-f073-49f0-bdbb-44870d1ba8a6"
    },
    "status": "ok",
    "message": "Supported languages",
    "success": true
}
```

### Meta

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

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

**Response:**
```json
{
    "data": {
        "auth": "none upstream; this gateway requires x-api-key",
        "name": "Prettier API",
        "note": "Format/beautify code with Prettier. /v1/format?code=...&language=js|ts|jsx|tsx|css|scss|less|graphql|vue (options: tab_width, print_width, semi, single_quote, use_tabs, trailing_comma). /v1/languages lists what's supported. Syntax errors return 422. Instant, nothing stored. Complements minify-api (the inverse) and the SQL/JSON/YAML/Markdown tools.",
        "source": "Local code formatting (Prettier 3) — no key, no upstream",
        "endpoints": 3
    },
    "meta": {
        "timestamp": "2026-06-02T16:51:57.055Z",
        "request_id": "c598fa8c-a6c0-402d-bd9a-ea1c1046d4c8"
    },
    "status": "ok",
    "message": "Meta",
    "success": true
}
```


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