Retrieval over EU law for an LLM that has to cite.
Three calls make the retrieval step for EU legislation: find articles by meaning, read the article with its provenance, follow its citations. LexAPI returns the source text; your model writes the answer.
The free plan starts with 500 credits, no card. Your API key is on the dashboard once you confirm your email.
Find the article by meaning.
Legislation is indexed at article level. Send the user’s question as query; run this with your key in place of lex_your_key.
curl -X POST "https://lex-api.com/api/v1/legislation/semantic" \
-H "x-api-key: lex_your_key" \
-H "Content-Type: application/json" \
-d '{"query":"right to erasure of personal data","limit":3}'{
"success": true,
"searchType": "semantic-legislation",
"resultCount": 3,
"results": [
{
"law_id": "32018R1725",
"law_title": "Regulation (EU) 2018/1725 … on the protection of natural persons with regard to the processing of personal data by the Union institutions, bodies, offices and agencies …",
"article_ref": "art_19",
"score": 0.753812,
"inForce": true,
…
},
{
"law_id": "32016R0679",
"law_title": "Regulation (EU) 2016/679 … (General Data Protection Regulation) …",
"article_ref": "art_17",
"language": "en",
"score": 0.7511648,
"snippet": "1. The data subject shall have the right to obtain from the controller the erasure of personal data concerning him or her without undue delay …",
"inForce": true,
"provenance": {
"sourceUrl": "https://eur-lex.europa.eu/legal-content/EN/TXT/HTML/?uri=CELEX:32016R0679",
"versionIdentifier": "32016R0679",
"retrievedAt": null,
"contentHash": null,
…
},
…
},
…
],
"credits": { "operation_weight": 5, … }
}law_idis the act’s CELEX number andarticle_refthe article: the two arguments of the next call.- Each hit carries the
inForcelabel of its act when the status is known. - Send
inForce: trueto keep only hits whose act is known to be in force today. Hits of unknown status are removed too.
Costs 5 credits, on every credit plan including the free one. limit is capped by plan: 10 results on the free plan, 20 on Starter, 50 on the plans above.
The article, with its provenance.
Read the matched article in full and keep where it came from next to the text you put in the prompt.
curlcurl -X POST "https://lex-api.com/api/v1/documentContent" \
-H "x-api-key: lex_your_key" \
-H "Content-Type: application/json" \
-d '{"celexNumber":"32016R0679","articleId":"art_17","include":["articles"]}'{
"success": true,
"document": {
"celex": "32016R0679",
"language": "en",
"version": 1,
"inForce": true,
"provenance": {
"publisher": "Publications Office of the European Union",
"sourceUrl": "https://eur-lex.europa.eu/legal-content/EN/TXT/HTML/?uri=CELEX:32016R0679",
"sourceIdentifier": "32016R0679",
"retrievedAt": "2026-11-17T18:14:22.344Z",
"contentHash": "3c91009d05bbda7b9717678970c2d4d680cee402b00f8f0df92510f9bab42543",
"versionIdentifier": "32016R0679",
"language": "en",
"licence": "Commission reuse policy (Decision 2011/833/EU)"
},
"content": {
"articles": [
{
"id": "art_17",
"number": "Article 17",
"title": "Right to erasure (‘right to be forgotten’)",
"content": "1. The data subject shall have the right to obtain from the controller the erasure of personal data concerning him or her without undue delay …"
}
]
},
"fieldProvenance": {
"official_source_text": ["content.articles[].content"],
"machine_extracted_structure": ["inForce", "content.articles"]
},
…
},
"credits": { "operation_weight": 1, … }
}provenance.sourceUrlis the document’s page at EUR-Lex andversionIdentifierthe text you were served.contentHashcovers the whole document, not the article. A different value means the document’s text changed, at the source or by a re-parse: re-read the articles you indexed from it.fieldProvenancesays which fields are the publisher’s wording and which are LexAPI’s parsing.
Costs 1 credit when LexAPI already holds the document, 4 or 5 when it is fetched from the source first. credits.operation_weight is what you were charged.
Search, then read, with the SDKs
Install with pip install lexapi-client or npm install @lexapi/client. The snippets read the top hit.
from lexapi import LexAPI
client = LexAPI(api_key="lex_your_key")
search = client.semantic_legislation_search("right to erasure of personal data", limit=3)
if not search.results:
raise SystemExit("no article matched")
hit = search.results[0]
resp = client.get_document(hit.law_id, include=["articles"], article_id=hit.article_ref)
article = resp.document.content.articles[0]
print(resp.document.celex, "-", article.number, "-", article.title)
print(article.content[:120])import { LexAPI } from "@lexapi/client";
const client = new LexAPI({ apiKey: "lex_your_key" });
const search = await client.semanticLegislationSearch({
query: "right to erasure of personal data",
limit: 3,
});
const hit = search.results[0];
if (!hit?.law_id || !hit.article_ref) throw new Error("no article matched");
const resp = await client.getDocument({
celexNumber: hit.law_id,
include: ["articles"],
articleId: hit.article_ref,
});
const article = resp.document.content?.articles?.[0];
console.log(resp.document.celex, "-", article?.number, "-", article?.title);
console.log(article?.content?.slice(0, 120));32018R1725 - Article 19 - Right to erasure (‘right to be forgotten’)
1. The data subject shall have the right to obtain from the controller the erasure of personal data concerning him or heIn a framework: EU law in LangChain · EU law in LlamaIndex.
Follow the citations.
To widen the context, ask what the act cites. Each group in cites[] is a document with its celexNumber and title; each edge has a citationType. The list holds the edges LexAPI has so far, and can be empty.
curl "https://lex-api.com/api/v1/citations/cites/32016R0679?limit=20" \ -H "x-api-key: lex_your_key"
Costs 1 credit. For what corrects or amends an act, see the example on GDPR API; for case law on a question, European case law API.
The text in force on a date.
Add asOf to the search above and each hit answers with the version listed for that date: the newest consolidated version dated on or before it, or the act as published. It does not say whether an individual provision applied on that date; see POST /legislation/as-of.
curl -X POST "https://lex-api.com/api/v1/legislation/semantic" \
-H "x-api-key: lex_your_key" \
-H "Content-Type: application/json" \
-d '{"query":"right to erasure of personal data","limit":3,"asOf":"2017-01-01"}'{
"success": true,
"asOf": "2017-01-01",
"resultCount": 3,
"results": [
{
"law_id": "32018R1725",
"article_ref": "art_19",
"score": 0.753812,
"asOfResolved": false,
"asOfReason": "not_yet_adopted",
"inForce": true,
…
},
{
"law_id": "02016R0679-20160504",
"article_ref": "art_17",
"score": 0.7511648,
"consolidated": true,
"consolidatedAsOf": "2016-05-04",
"baseCelex": "32016R0679",
"consolidatedNote": "The act as amended, consolidated as of 2016-05-04; not the authentic text. Only the act as published in the Official Journal is authentic (32016R0679).",
"asOfResolved": true,
"asOfVersion": { "celex": "02016R0679-20160504", "date": "2016-05-04", "kind": "consolidated" },
"matchedVersion": { "law_id": "32016R0679", … },
"inForce": true,
…
},
{
"law_id": "02001R0045-20010201",
"article_ref": "art_16",
"score": 0.7292255,
"consolidated": true,
"baseCelex": "32001R0045",
"asOfResolved": true,
"asOfVersion": { "celex": "02001R0045-20010201", "date": "2001-02-01", "kind": "consolidated" },
"inForce": false,
"notInForceReason": "no_longer_in_force",
"endOfValidity": "2018-12-10",
…
}
],
…
}- Use only hits with
asOfResolved: true. A hit that cannot be answered for the date keeps its indexed text and says why inasOfReason. asOfVersionnames the version that answered.- A consolidated version is documentation without legal force:
baseCelexis the authentic act to cite. inForcestays about today: the third hit hasasOfResolved: true, and its act is no longer in force today.- The search costs 5 credits. A version LexAPI does not hold yet is fetched first and charged like a document read, so the same request can cost more the first time;
asOfSummary.liveFetchescounts those fetches.
One act on a date, without a search: EU law on a date.
What it does not do.
| Topic | What to know |
|---|---|
| Answers | LexAPI retrieves source text and its identifiers. It does not write answers and does not assess compliance: that part is your model and your review. |
| In force | inForce is about today and is left out when the status is unknown. It does not cover amendments: for the wording on a date, use asOf and keep only hits with asOfResolved: true. |
| Consolidated texts | A hit labelled consolidated: true is documentation without legal force. baseCelex names the authentic act. |
| Scores | score is a similarity between 0 and 1. Without min_score a default floor applies; a best-effort response below it carries a hint. |
| Hit ids | The id of a hit can change when the index is rebuilt. Key your store on law_id and article_ref. |
| Citations | The citation graph grows as documents are extracted. A short or empty list is not proof that nothing cites an act. |
Asked & answered.
N° 01How do I ground an LLM answer in EU law?+
N° 02What does asOf do in a semantic search?+
N° 03How do I cite a search hit that is a consolidated text?+
N° 04Do the ids of search hits stay the same?+
Keep building.
- GDPR APIRead the GDPR by article or recital, cite it, and list what corrects or amends it.
- European case law APISearch Court of Justice case law by meaning, resolve an ECLI, read the judgment.
- Legal data API for AI agentsThe MCP server, hosted or local, the REST API and the SDKs, all on the same credit pool.
- QuickstartA first request by curl, MCP, Python and TypeScript.
- API referenceEvery endpoint, parameter, response field and error.
- MCP serverSetup for Claude, Cursor and VS Code, and the tool list.
- PricingPlans, credit pools and what each call costs.
LexAPI returns source texts and their identifiers. It does not assess compliance and gives no legal advice.