# SQL Query Optimizer

> SQL Query Optimizer is a paid API for AI agents from api.strale.io, paid per call via x402, $0.054001/call, status unknown (last checked 2026-10-12).

Analyzes a SQL query for performance issues and returns a rewritten query, index recommendations, and explanation of improvements

## Facts

- Endpoint: GET https://api.strale.io/x402/sql-optimize?utm_source=zero.xyz
- Price: $0.054001/call
- Payment: x402
- Status: unknown
- Last checked: 2026-10-12
- Activations on Zero: 0
- Tags: x402
- Canonical page: https://www.zero.xyz/c/api-strale-io-96d51680
- Structured record (JSON): https://api.zero.xyz/v1/capabilities/cap_2E8hRupi866_aMKL_VjTP

Status and success rate cover calls made through Zero and Zero's own probes. Third-party monitors may report differently.

## How to call it through Zero

Zero handles the 402 payment challenge and records the run. With the Zero CLI installed (`npm i -g @zeroxyz/cli`):

```sh
zero fetch --capability api-strale-io-96d51680
```

Example prompt: Can you optimize this SQL query for me and tell me what indexes I should add? SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = 'pending' AND o.created_at > '2024-01-01' — using PostgreSQL dialect.

## When to prefer this

Use this endpoint when you need automated, on-demand SQL query performance analysis without setting up a dedicated database tuning tool. Ideal for AI agents that need to suggest query improvements, generate index DDL statements, or explain performance issues to developers. Prefer this over general-purpose LLM SQL advice when you want structured, actionable output including a rewritten query and concrete index recommendations.

## Known failure modes

- Invalid or unparseable SQL syntax returns an error
- Unsupported SQL dialect may produce generic or inaccurate recommendations
- Missing table schema may reduce the quality of index recommendations
- Very complex queries with many joins may produce incomplete optimizations
- Empty or null sql parameter returns a validation error

## How this service works

Analyze and optimize a SQL query for performance. Returns rewritten query, index recommendations, and explanation of improvements.

## Output

Returns a rewritten SQL query optimized for performance, specific index recommendations for the tables involved, and a plain-English explanation of what changes were made and why they improve performance.

## Example request

```json
{
 "sql": "SELECT * FROM orders o JOIN customers c ON o.customer_id = c.id WHERE o.status = 'pending' AND o.created_at > '2024-01-01'",
 "dialect": "postgresql",
 "table_schema": "orders(id INT, customer_id INT, status VARCHAR, created_at TIMESTAMP), customers(id INT, name VARCHAR)"
}
```

## Request schema (JSON Schema)

```json
{
 "type": "object",
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "required": [
  "input"
 ],
 "properties": {
  "input": {
   "type": "object",
   "required": [
    "type",
    "method"
   ],
   "properties": {
    "type": {
     "type": "string",
     "const": "http"
    },
    "method": {
     "enum": [
      "GET",
      "HEAD",
      "DELETE"
     ],
     "type": "string"
    },
    "queryParams": {
     "type": "object",
     "required": [
      "sql"
     ],
     "properties": {
      "sql": {
       "type": "string"
      },
      "dialect": {
       "type": "string"
      },
      "table_schema": {
       "type": "string"
      }
     }
    }
   },
   "additionalProperties": false
  }
 }
}
```

## More

- Live health (JSON, refreshed every minute): https://www.zero.xyz/c/api-strale-io-96d51680/health.json
- [Zero catalog index](https://www.zero.xyz/llms.txt)
- [Other services from api.strale.io](https://www.zero.xyz/host/api.strale.io/llms.txt)
