LAMH Guide

Everything you need to connect LAMH to your AI assistant in about 15 minutes: what to send, where to put it, and what to do with the answer.

Contents

  1. What LAMH does
  2. Before you start
  3. Quick start: 3 steps
  4. Python example
  5. JavaScript example
  6. Command-line example (curl)
  7. What LAMH returns
  8. Certificate fields
  9. Verdicts: what to do
  10. Keeping LAMH up to date
  11. If LAMH cannot be reached
  12. API reference
  13. Plans and limits
  14. Errors
  15. Security and privacy
  16. Frequently asked questions

What LAMH does

Your AI assistant searches your documents and sends the passages it finds (called chunks) to a language model. If a passage is outdated, edited, deleted, or relies on a law or standard that is no longer in force, the model still answers confidently. LAMH sits between your search and your model and checks every chunk first.

Your search finds chunks → LAMH certifies them → Your model answers from the certified context

Before you start

Lost your key? Email [email protected] from the address you registered with and we will issue a new one and revoke the old one.

Quick start: 3 steps

  1. Sync your documents
    Send each document once as a list of chunks, in order. Use the same chunks your search index already uses. doc_id is your own stable name for the document (letters, numbers, . _ : / -). LAMH replies with the document's version. Send the whole document again whenever it changes; LAMH records the new version.
  2. Save three labels with every chunk
    In your search index (vector database or search engine), store doc_id, chunk_no (the chunk's position, starting at 0) and version next to each chunk's text. These labels are how LAMH recognises the chunk later.
  3. Certify before every model call
    After your search returns chunks, send them to POST /v1/certify with their labels and text. Put the returned context in your prompt instead of the raw chunks. It contains the current text and a clear notice for anything outdated, and it leaves out blocked chunks.

Python example

import os
from lamh_client import Lamh          # download: https://lamh.mubtkrat.ai/sdk/lamh_client.py

lamh = Lamh(os.environ["LAMH_API_KEY"])          # keep the key in an environment variable

# 1) Sync: once now, and again every time a document changes
r = lamh.sync([
    {"doc_id": "refund-policy", "chunks": [
        "Refunds are accepted within 30 days of purchase.",
        "VAT in Saudi Arabia is 15% and is included in the price.",
    ]},
])
version = r["versions"]["refund-policy"]   # save this number with each chunk in your search index

# 2) Certify: before every model call, send the chunks your search returned
retrieved = [
    {"doc_id": "refund-policy", "chunk_no": 0, "version": version,
     "text": "Refunds are accepted within 30 days of purchase."},
]
out = lamh.certify(retrieved, lang="en")      # lang="ar" for Arabic notes

# 3) Use: give the model out["context"] instead of the raw chunks
prompt = (
    "Answer only from these sources. Respect any notice marked with a warning sign.\n\n"
    + out["context"] + "\n\nQuestion: " + question
)

JavaScript example

// Node 18+ or any server runtime with fetch. Never call LAMH from a browser: the key must stay secret.
const LAMH = "https://api.mubtkrat.ai";

async function lamh(method, path, body) {
  const r = await fetch(LAMH + path, {
    method,
    headers: { Authorization: `Bearer ${process.env.LAMH_API_KEY}`, "Content-Type": "application/json" },
    body: body ? JSON.stringify(body) : undefined,
  });
  const j = await r.json();
  if (!r.ok) throw new Error(`${r.status} ${j.error.code}: ${j.error.message}`);
  return j;
}

// 1) Sync
const s = await lamh("PUT", "/v1/documents", {
  documents: [{ doc_id: "refund-policy", chunks: ["Refunds are accepted within 30 days of purchase."] }],
});
// 2) Certify
const out = await lamh("POST", "/v1/certify", {
  lang: "en",
  chunks: [{ doc_id: "refund-policy", chunk_no: 0, version: s.versions["refund-policy"],
             text: "Refunds are accepted within 30 days of purchase." }],
});
// 3) Use out.context in your prompt

Command-line example (curl)

export LAMH_API_KEY="lamh_live_..."

# Sync a document
curl -X PUT https://api.mubtkrat.ai/v1/documents \
  -H "Authorization: Bearer $LAMH_API_KEY" -H "Content-Type: application/json" \
  -d '{"documents":[{"doc_id":"refund-policy","chunks":["Refunds are accepted within 30 days of purchase."]}]}'

# Certify retrieved chunks
curl -X POST https://api.mubtkrat.ai/v1/certify \
  -H "Authorization: Bearer $LAMH_API_KEY" -H "Content-Type: application/json" \
  -d '{"lang":"en","chunks":[{"doc_id":"refund-policy","chunk_no":0,"version":1,"text":"Refunds are accepted within 30 days of purchase."}]}'

# Check your plan and usage
curl https://api.mubtkrat.ai/v1/usage -H "Authorization: Bearer $LAMH_API_KEY"

What LAMH returns

After sync

{"epoch": 3, "root": "0abb2816…2740", "versions": {"refund-policy": 2}, "stored_chunks": 2}

After certify

A real response: the first chunk had been edited (14 days became 30 days), so LAMH replaced it with the current text. The second relies on Saudi VAT at 5%, which changed to 15% in 2020, so LAMH added a notice.

{
  "certificates": [
    {
      "ref": {"doc_id": "refund-policy", "chunk_no": 0, "version": 1},
      "intact": true, "current": false, "change": "material",
      "verdict": "REPLACED",
      "notes": ["This passage was outdated and has been replaced with the current version since 2026-10-27."],
      "text": "Refunds are accepted within 30 days of purchase.",
      "basis": []
    },
    {
      "ref": {"doc_id": "refund-policy", "chunk_no": 1, "version": 2},
      "intact": true, "current": true, "change": "same",
      "verdict": "VALID_WITH_NOTICE",
      "basis": [{"authority": "sa.vat_rate5.1439", "status": "superseded", "effective_to": "2020-07-01",
                 "current_reference": "VAT 15% (from 1 July 2020)", "evidence": "https://zatca.gov.sa/…"}],
      "notes": ["Note: this passage relies on VAT 5%, which is superseded since 2020-07-01; current reference: VAT 15%."],
      "text": "VAT in Saudi Arabia is 5% and is included in the price."
    }
  ],
  "context": "[1] (refund-policy) ⚠ This passage was outdated and has been replaced …\nRefunds are accepted within 30 days of purchase.\n\n[2] (refund-policy) ⚠ Note: …",
  "epoch": 3
}

Certificate fields

refThe chunk you sent: doc_id, chunk_no, version.
intacttrue if the text matches the version you synced (cryptographic check).
currenttrue if it is the latest version of that chunk.
changesame · cosmetic · minor · material · removed · tampered
basisLaws, standards, guidelines or software versions the chunk relies on, with their status, end date, current replacement and official source.
verdictWhat to do with the chunk (see below).
notesHuman-readable notices, in the language you asked for.
textThe text to give the model (current text when it was replaced).

Verdicts: what to do

VerdictMeaningYour action
VALIDIntact and current, nothing to flag.Use it.
VALID_WITH_NOTICECurrent, but relies on an authority that was repealed or superseded.Use it with the notice (already in context).
REFRESHEDA small change since you indexed it; LAMH silently swapped in the current text.Use text.
REPLACEDA material change; replaced with the current text plus a notice.Use text and the notice.
BLOCKEDTampered with, or the source no longer exists.Do not send it to the model. context already leaves it out.

Only want the usable chunks?

usable = lamh.usable(retrieved, lang="en")    # drops BLOCKED chunks, keeps current text
chunks_for_model = [c["text"] for c in usable]

Keeping LAMH up to date

If LAMH cannot be reached

The SDK waits up to 10 seconds. Decide in advance what your assistant should do:

from lamh_client import Lamh, LamhError
try:
    out = lamh.certify(retrieved, lang="en")
    context = out["context"]
except (LamhError, OSError):
    # LAMH unreachable or quota reached: choose your policy.
    # Regulated answers (legal, medical, finance): refuse and ask the user to retry.
    # General assistants: answer, but log the question for review.
    context = None

API reference

MethodPathPurpose
PUT/v1/documentsSync documents: {documents:[{doc_id, chunks:[…]}], delete:[doc_id]}
POST/v1/certifyCertify chunks: {chunks:[{doc_id, chunk_no, version, text}], lang:"en"|"ar"}
GET/v1/documents/<doc_id>A document's current version and chunk count (never its text)
GET/v1/usageYour plan, limits and this month's usage
GET/v1/registry?sector=The authorities LAMH tracks and their status
GET/v1/rootSigned ledger root and public key, so you can verify LAMH independently
GET/v1/accountYour account details
GET/v1/healthService status (no key needed)

Every request except /v1/health needs the header Authorization: Bearer <your key>.

Plans and limits

PlanCertified chunks / monthStored chunksRequests / second
Trial (14 days)10,00020,0005
Starter50,00025,00010
Pro1,000,000500,00050
Enterprise50,000,00020,000,000500

Check your own numbers at any time with GET /v1/usage.

Errors

Errors come back as {"error": {"code": "…", "message": "…"}}.

HTTPcodeWhat to do
400bad_chunk / bad_chunks / bad_doc_id / bad_jsonFix the request body: every chunk needs doc_id, chunk_no, version and text.
401unauthorizedKey missing, mistyped or revoked.
402certify_quota / storage_quotaMonthly limit reached. Upgrade your plan or wait for next month.
402subscription_expiredRenew on the website.
413too_largeSplit the request (max 4 MB).
429rate_limited / write_rate_limitedToo many requests. Wait a few seconds and retry.
503integrity_failureContact [email protected].

Security and privacy

Frequently asked questions

Does LAMH replace my vector database or my model?

No. Keep your search and your model. LAMH is one call between them.

Which model or framework does it work with?

Any: OpenAI, Claude, Gemini, Llama, LangChain, LlamaIndex, or your own code. LAMH only needs the chunk text and its three labels.

Do I have to send all my documents?

Only the documents your assistant searches. LAMH compares retrieved chunks against them.

Which languages?

Chunks can be in any language. Notices are in Arabic or English (lang).

How fast is it?

Typically a few milliseconds per chunk, well below the time a model takes to answer.

Need help connecting LAMH? Email [email protected] with your account email and the error message. Do not include your API key.