Skip to main content
Try Lexiel for freeTry now →
For developers

Lexiel API

Integrate into your own applications a legal AI with a verified corpus of Spanish and Latin American law.

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 cases
cases:writeCreate, edit, archive and delete cases
documents:readRead and download documents
documents:writeUpload and delete documents (analysis uses quota)
conversations:readRead conversations and messages
conversations:writeAsk the AI and delete conversations (uses quota)
invoices:readRead invoices
invoices:writeCreate invoices
calendar:readRead the calendar
clients:readRead clients
clients:writeCreate clients
analytics:readRead fee analytics

Cases, 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.

MethodPathScopeWhat it does
GET/v1/casescases:readList cases (status, q, limit, offset)
POST/v1/casescases:writeCreate a case (title, parties, facts)
GET/v1/cases/{id}cases:readRead a case (archived too)
PATCH/v1/cases/{id}cases:writeUpdate; a status other than archived reopens it
DELETE/v1/cases/{id}cases:writeArchive (read-only, no new messages)
DELETE/v1/cases/{id}?permanent=truecases:writePermanent cascading erasure
GET/v1/documentsdocuments:readList documents (caseId, limit, offset)
POST/v1/documentsdocuments:writeUpload and analyse (multipart: file, caseId)
GET/v1/documents/{id}documents:readStatus, summary and key findings
GET/v1/documents/{id}/downloaddocuments:readDownload link (15 min)
DELETE/v1/documents/{id}documents:writeDelete a document and its file
GET/v1/conversationsconversations:readList conversations
POST/v1/conversationsconversations:writeCreate a conversation (optional caseId)
GET/v1/conversations/{id}/messagesconversations:readRead messages and citations
POST/v1/conversations/{id}/messagesconversations:writeAsk the AI, SSE answer
DELETE/v1/conversations/{id}conversations:writeArchive a conversation
DELETE/v1/conversations/{id}/permanentconversations:writeDelete 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

Limits

Errors

Always { "error": { "code", "message" } }. The code is stable; the message may change.

400VALIDATION / BAD_REQUESTInvalid parameters
401UNAUTHORIZEDMissing, unknown, disabled or expired key
401MEMBER_INACTIVEThe key owner is deactivated
403API_KEY_SCOPEMissing the scope in error.requiredScope, or the endpoint takes no key
403FORBIDDENThe user may not do that (e.g. erase a case they did not create)
404NOT_FOUNDDoes not exist or is not yours (never told apart)
409CASE_ARCHIVEDArchived case: no new conversations or messages
409CONVERSATION_ARCHIVEDArchived conversation
409CASE_HAS_RETAINED_RECORDSThe case holds records the law requires us to keep; nothing is deleted
409DOCUMENT_IN_USEDocument with a pending signature
429RATE_LIMITEDRate limit; wait for Retry-After
429PLAN_LIMIT_REACHEDMonthly 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.

Weekly legal updates

Legislative changes, relevant case law, and Lexiel news. No spam. Unsubscribe anytime.

GDPR compliant. We never share your email with third parties.