OpenAPI specification
Swagger UI and JSON at /api-docs/openapi.json
Create an API key
Settings > API, on any paid plan
Authentication
Every request carries the key in the Authorization header. The key acts as the user who created it, inside their firm: it sees and changes only what that user sees in the app. Use it only from your server; if it leaks, disable or rotate it in Settings > API.
Authorization: Bearer lx_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Scopes
When you create the key you tick what it may do. Ask only for what your integration needs. Without the scope the API answers 403 API_KEY_SCOPE and names the missing one in error.requiredScope. Keys created before 11 November 2026 have them all.
cases:readRead casescases:writeCreate, edit, archive and delete casesdocuments:readRead and download documentsdocuments:writeUpload and delete documents (analysis uses quota)conversations:readRead conversations and messagesconversations:writeAsk the AI and delete conversations (uses quota)invoices:readRead invoicesinvoices:writeCreate invoicescalendar:readRead the calendarclients:readRead clientsclients:writeCreate clientsanalytics:readRead fee analyticsCases, documents and conversations
Legal context goes in two places: in the text of each question (up to 45,000 characters) and in the documents of the case, which every answer of the conversations linked to it searches. To analyse documents, upload them to the case, wait for status ready (summary and key findings are in GET /v1/documents/{id}; keyFindings is an object with the lists clauses, risks, obligations and deadlines, each of strings, plus appealRoutes when the ruling declares appeal routes) and ask about them in a conversation of the case.
| Method | Path | Scope | What it does |
|---|---|---|---|
| GET | /v1/cases | cases:read | List cases (status, q, limit, offset) |
| POST | /v1/cases | cases:write | Create a case (title, parties, facts) |
| GET | /v1/cases/{id} | cases:read | Read a case (archived too) |
| PATCH | /v1/cases/{id} | cases:write | Update; a status other than archived reopens it |
| DELETE | /v1/cases/{id} | cases:write | Archive (read-only, no new messages) |
| DELETE | /v1/cases/{id}?permanent=true | cases:write | Permanent cascading erasure |
| GET | /v1/documents | documents:read | List documents (caseId, limit, offset) |
| POST | /v1/documents | documents:write | Upload and analyse (multipart: file, caseId) |
| GET | /v1/documents/{id} | documents:read | Status, summary and key findings |
| GET | /v1/documents/{id}/download | documents:read | Download link (15 min) |
| DELETE | /v1/documents/{id} | documents:write | Delete a document and its file |
| GET | /v1/conversations | conversations:read | List conversations |
| POST | /v1/conversations | conversations:write | Create a conversation (optional caseId) |
| GET | /v1/conversations/{id}/messages | conversations:read | Read messages and citations |
| POST | /v1/conversations/{id}/messages | conversations:write | Ask the AI, SSE answer |
| DELETE | /v1/conversations/{id} | conversations:write | Archive a conversation |
| DELETE | /v1/conversations/{id}/permanent | conversations:write | Delete a conversation and its messages |
AI answer (SSE)
POST /v1/conversations/{id}/messages answers as text/event-stream. Events: status (progress, e.g. reading documents), text (answer chunks as plain text), done (final, with messageId, model and verified citations) and error. If you would rather not read the stream, wait for the end and fetch the full answer with GET /v1/conversations/{id}/messages.
Deletion
- DELETE /v1/documents/{id}: the document ceases to exist for the API and the app (404 on read, no longer used as context) and its file is removed from storage.
- DELETE /v1/conversations/{id} archives it (404 on read, 409 CONVERSATION_ARCHIVED to new messages); DELETE /v1/conversations/{id}/permanent deletes it with all its messages.
- DELETE /v1/cases/{id} ARCHIVES: the case stays readable and takes no new conversations or messages (409 CASE_ARCHIVED). Reopen it with PATCH and a status other than archived.
- DELETE /v1/cases/{id}?permanent=true ERASES the case for good and, in cascade, its conversations and messages, documents (with indexed chunks, versions and files), deadlines, drafts and notes, and answers with a count of what it removed. The creator of the case or a firm owner or admin may do it.
- If the case holds records the law requires us to keep (invoices, quotes, time or expenses; signature or recording-consent evidence; meetings or recordings), permanent erasure answers 409 CASE_HAS_RETAINED_RECORDS and deletes nothing. The firm audit log is always kept.
Limits
- 60 requests per minute per key and per source IP, on top of each route’s limits (e.g. 10 or 20 AI questions per minute depending on the plan). Headers X-RateLimit-Limit, X-RateLimit-Remaining and, on 429, Retry-After.
- Each AI question and each document analysis uses the monthly quota of the account’s plan, as in the app (429 PLAN_LIMIT_REACHED when used up).
Errors
Always { "error": { "code", "message" } }. The code is stable; the message may change.
| 400 | VALIDATION / BAD_REQUEST | Invalid parameters |
| 401 | UNAUTHORIZED | Missing, unknown, disabled or expired key |
| 401 | MEMBER_INACTIVE | The key owner is deactivated |
| 403 | API_KEY_SCOPE | Missing the scope in error.requiredScope, or the endpoint takes no key |
| 403 | FORBIDDEN | The user may not do that (e.g. erase a case they did not create) |
| 404 | NOT_FOUND | Does not exist or is not yours (never told apart) |
| 409 | CASE_ARCHIVED | Archived case: no new conversations or messages |
| 409 | CONVERSATION_ARCHIVED | Archived conversation |
| 409 | CASE_HAS_RETAINED_RECORDS | The case holds records the law requires us to keep; nothing is deleted |
| 409 | DOCUMENT_IN_USE | Document with a pending signature |
| 429 | RATE_LIMITED | Rate limit; wait for Retry-After |
| 429 | PLAN_LIMIT_REACHED | Monthly plan quota used up |
Server-to-server example
const API = 'https://api.lexiel.ai';
const headers = {
Authorization: `Bearer ${process.env.LEXIEL_API_KEY}`, // lx_…
'Content-Type': 'application/json',
};
// 1. Expediente del asunto
const { case: expediente } = await (await fetch(`${API}/v1/cases`, {
method: 'POST', headers,
body: JSON.stringify({ title: 'Debt claim', factsSummary: 'Facts of the matter…' }),
})).json();
// 2. A document to analyse (multipart). Poll GET /v1/documents/{id} until status 'ready'
const form = new FormData();
form.append('file', new Blob([pdfBuffer], { type: 'application/pdf' }), 'contrato.pdf');
form.append('caseId', expediente.id);
await fetch(`${API}/v1/documents`, { method: 'POST', headers: { Authorization: headers.Authorization }, body: form });
// 3. A conversation in the case and a question to the AI (SSE answer)
const { conversation } = await (await fetch(`${API}/v1/conversations`, {
method: 'POST', headers, body: JSON.stringify({ caseId: expediente.id }),
})).json();
const res = await fetch(`${API}/v1/conversations/${conversation.id}/messages`, {
method: 'POST', headers,
body: JSON.stringify({ content: 'Context: commercial lease, the landlord is a company. Which clauses of the contract are problematic?' }),
});
let answer = '';
for (const block of (await res.text()).split('\n\n')) {
const lines = block.split('\n');
const event = lines.find((l) => l.startsWith('event: '))?.slice(7);
const data = lines.filter((l) => l.startsWith('data: ')).map((l) => l.slice(6)).join('\n');
if (event === 'text') answer += data; // plain text
if (event === 'done') console.log(JSON.parse(data).messageId);
}
// 4. Permanent erasure of the case and everything in it
await fetch(`${API}/v1/cases/${expediente.id}?permanent=true`, { method: 'DELETE', headers });Every field and response is in the OpenAPI specification.