Skip to main content

API Reference

Legible exposes a REST API for programmatic access to SQL generation, query execution, AI-driven analysis, and knowledge management. All endpoints are served from your Legible instance at port 3000.

Base URL

https://<your-legible-host>/api/v1

Authentication

All API requests require an API key passed in the Authorization header:

Authorization: Bearer <api-key>

Key Types

Key PrefixTypeScope
osk-...Organization KeyFull access to all projects
psk-...Project KeyScoped to a single project

Generate API keys from Settings → API Keys in the Legible UI.

Project Scoping

When using an organization key, include the X-Project-Id header to target a specific project. Project keys automatically scope to their assigned project.

Rate Limiting

All endpoints enforce per-key rate limits. Response headers indicate your current status:

HeaderDescription
X-RateLimit-LimitMaximum requests per window
X-RateLimit-RemainingRemaining requests in window
X-RateLimit-ResetUnix timestamp when the window resets

Response Format

Success

Successful responses return JSON with endpoint-specific fields:

{
"id": "1fbc0d64-1c58-45b2-a990-9183bbbcf913",
"sql": "SELECT * FROM customers",
"threadId": "9c537507-9cec-46ed-b877-07bfa6322bed"
}

Error

Error responses include a code and message:

{
"id": "75c13d09-6f86-4e79-a00e-a4f85f73f2d7",
"code": "NON_SQL_QUERY",
"error": "Unable to generate SQL for this question."
}

Common error codes:

CodeHTTP StatusDescription
NON_SQL_QUERY400Question cannot be answered with SQL
DEPLOYMENT_REQUIRED400No active model deployment
UNAUTHORIZED401Invalid or missing API key
RATE_LIMITED429Rate limit exceeded

Conversation Threads

Most endpoints accept and return a threadId parameter. Threads maintain conversation context across related requests — pass the threadId from a previous response to keep context in follow-up queries.

Endpoints Overview

EndpointMethodDescription
/generate_sqlPOSTConvert natural language to SQL
/run_sqlPOSTExecute SQL and return results
/askPOSTGenerate SQL + summary in one call
/generate_summaryPOSTSummarize query results
/generate_vega_chartPOSTGenerate a Vega chart spec
/modelsGETGet deployed models and schema
/semantics-descriptionsPOST/GETGenerate model descriptions
/relationship-recommendationsPOST/GETRecommend model relationships
/stream/generate_sqlPOSTStream SQL generation (SSE)
/stream/askPOSTStream ask results (SSE)
/stream_explanationGETStream non-SQL explanations (SSE)
/knowledge/instructionsGET/POSTManage instructions
/knowledge/instructions/:idPUT/DELETEUpdate or delete an instruction
/knowledge/sql_pairsGET/POSTManage SQL pairs
/knowledge/sql_pairs/:idPUT/DELETEUpdate or delete a SQL pair