⚖️ OpenThai 2.0 Legal

The Thai legal AI that knows the law by heart — built by Thais, for Thailand.
openthai2.0-legal-thaillm-nemotron-3-nano-30b-a3b
An open-weight model exploring how far Thai legal knowledge and verifiable, section-level citation can be pushed on a self-hostable 30B base — with or without retrieval.
Built by the OpenThai team (AIEAT / iApp Technology) on the NVIDIA NeMo stack, in collaboration with the Big Data Institute (BDI), the ThaiLLM initiative and NVIDIA.
🎮 Try it live
The hosted API retrieves from a 39-law, 6,300-section Thai statute corpus (hybrid BM25 + Qwen3 embedding search + reranker) and grounds each answer in the current law text. The demo shows the sections the system selected under every answer, so you can see the retrieval step working. Send "rag": false to call the bare model instead (the Closed-book tab does exactly that).
Try OpenThai 2.0 Legal — Live
FREE API · 1 MONTHReal model, real answers. Free with your iApp API key until 24 Aug 2026.
This API retrieves from a 39-law, 6,300-section Thai statute corpus (hybrid BM25 + embedding search + reranker) and grounds every answer in the current law text. The sections it selects are shown below each answer. Switch to Closed-book mode (rag: false in the API) to compare with the bare model.
Full legal analysis in prose, citing มาตรา — grounded in auto-retrieved current statute text.
🧑💻 Developer view — the API call behind this demo
This curl command updates live as you change the question, mode and toggles above. Run it in your terminal with your own API key — it is exactly what this page sends.
curl -s https://api.iapp.co.th/v3/llm/openthai2p0-legal/chat/completions \
-H "Content-Type: application/json" \
-H "apikey: YOUR_IAPP_API_KEY" \
-d '{
"model": "openthai2.0-legal",
"rag": true,
"rag_inject": "system",
"messages": [
{
"role": "system",
"content": "You are a Thai legal expert. Answer with legal analysis and cite the relevant มาตรา."
},
{
"role": "user",
"content": "จำเลยขีดฆ่าและฉีกเอกสารหลักฐานแห่งหนี้ แม้ยังอ่านได้ ถือเป็นความผิดสำเร็จหรือเพียงพยายามกระทำผิด"
}
],
"temperature": 0,
"top_p": 1,
"max_tokens": 4096,
"chat_template_kwargs": {
"enable_thinking": true
}
}'Outputs are decision support, not legal advice. Verify every citation against the current law. Free with an iApp API key to 24 Aug 2026; standard pricing afterwards is 0.01/0.02 IC per 1K input/output tokens (same as Thanoy Legal AI).
🔓 Free hosted API — 1 month (free iApp API key required)
Don't want to run GPUs? We host the model for you. The endpoint is OpenAI-compatible and free until 24 August 2026 — you just need a free iApp API key: register → API Keys → Create New API Key. Rate-limited to 30 requests/minute. After the promo it stays available at standard Thanoy-rate pricing: 0.01 / 0.02 IC per 1K input/output tokens.
| Base URL | https://api.iapp.co.th/v3/llm/openthai2p0-legal |
| Endpoint | POST /chat/completions (OpenAI-compatible) |
| Model | openthai2.0-legal |
| Auth | iApp API key (apikey header or Authorization: Bearer) · free registration, free usage to 24 Aug 2026 |
| RAG | on by default — server-side hybrid retrieval over the Thai statute corpus; "rag": false for the bare model, "rag_top_k" (1–20, default 8) to tune depth, "rag_inject": "system" for essay/long-form prompts (default "user" fits the JSON citation contract) |
Every RAG response includes a retrieved_documents array — the exact sections (law name, มาตรา, current text, reranker score) the answer was grounded in, so you can display or audit the retrieval step in your own product:
from openai import OpenAI
client = OpenAI(base_url="https://api.iapp.co.th/v3/llm/openthai2p0-legal", api_key="YOUR_IAPP_API_KEY")
r = client.chat.completions.create(
model="openthai2.0-legal",
messages=[{"role": "user", "content": "ลักทรัพย์ในเวลากลางคืน ผิดมาตราใด"}],
max_tokens=1024,
# extra_body={"rag": False} # uncomment to call the bare model (closed-book)
)
print(r.choices[0].message.content)
print(r.model_extra.get("retrieved_documents")) # the law sections the answer used
curl -s https://api.iapp.co.th/v3/llm/openthai2p0-legal/chat/completions \
-H "Content-Type: application/json" -H "apikey: YOUR_IAPP_API_KEY" \
-d '{"model":"openthai2.0-legal","messages":[{"role":"user","content":"ลักทรัพย์ในเวลากลางคืน ผิดมาตราใด"}],"max_tokens":1024}'
🔗 Self-host it with RAG
This model is at its best when the law is in the prompt: open-book citation accuracy is 0.99 versus 0.07–0.40 from pure memory. That's why our hosted API ships with retrieval already built in. If you self-host the open weights, pair them with your own retrieval the same way:
- Full tutorial: Open WebUI & OpenThaiRAG → — connect the most popular self-hosted chat UI, or the Thai-native OpenThaiRAG framework (project page), in under an hour.
- Recommended datasets: WangchanX-Legal-ThaiCCL-RAG for training/eval pairs, NitiBench to score your pipeline, and krisdika.go.th for authoritative statute text.
- Chunk by มาตรา — one section per chunk with
law_name+sectionmetadata matches the citation contract the model was RL-trained on.
Thinking is off by default, so you get a clean, direct answer. To see step-by-step legal reasoning, add "chat_template_kwargs": {"enable_thinking": true} — the reasoning appears in content, wrapped in <think>...</think>.
✨ Highlights
🔓 1. Open weights, self-hostable
30B Mixture-of-Experts with only ~3B parameters active per token. Runs on a single GPU from 24 GB VRAM in NVFP4 (4-bit), so law firms and agencies can keep sensitive matters entirely on their own infrastructure.
📖 2. Cites the law, not vibes
Every answer can return the exact law name and มาตรา in a fixed JSON contract — ready to drop straight into RAG pipelines, drafting tools and legal-tech products.
🧠 3. Knows the statute book from memory
Asked with no statute in the prompt, it recalls and cites the right section: roughly 4× the closed-book recall of the much larger Qwen3.6-35B on the Civil and Commercial Code.
✍️ 4. Writes like a lawyer
Ahead of Qwen3.6-35B on all four legal-essay axes — citations, holding, coverage and fluency — graded on held-out Thai Supreme Court cases.
🇹🇭 5. Grounded in real Thai legal sources
Trained on published Thai statutes and court rulings, with every answer tied back to its source section.
📊 Benchmark results

| Evaluation | OpenThai 2.0 Legal | Qwen3.6-35B | Nemotron-3-30B base |
|---|---|---|---|
| Closed-book: knows the law from memory | |||
| Civil & Commercial: recall the Civil and Commercial Code (n=3,729) | 0.07 | 0.02 | 0.001 |
| Tax: recall the Revenue Code (n=50) | 0.40 | 0.36 | 0.31 |
| Open-book: uses provided law (the RAG setting) | |||
| Civil & Commercial: cite the applicable sections from context (n=3,729) | 0.99 | 0.99 | 0.98 |
| Tax echo: cite the sections provided (n=50) | 0.84 | 0.84 | 0.64 |
| Tax selection: cite only the applicable sections among distractors (n=50) | 0.69 | 0.64 | 0.45 |
| Legal essays (Thai Supreme Court cases) | |||
| Citations: correct citations inside the essay (n=72) | 0.25 | 0.09 | 0.02 |
| Holding: reaches the correct legal conclusion (n=72) | 0.57 | 0.50 | 0.31 |
| Coverage: covers the key legal points (n=72) | 0.60 | 0.55 | 0.27 |
| Fluency: writing quality (n=72) | 0.46 | 0.43 | 0.13 |
Scores run 0 to 1, higher is better. Citation rows use NitiBench's citation-F1 scorer (single pass, temperature 0, thinking off); essay holding, coverage and fluency are judged by Gemini 3.1 Flash Lite. Every model was re-run end to end under one identical protocol.
This is the strongest closed-book Thai-law recall we have measured in a self-hostable model, scored by code rather than by an AI judge. A closed cloud API still scores higher — the claim is scoped to models you can run on your own hardware.
🔬 How it was trained

Three stages on the NVIDIA NeMo stack, each solving one problem:
- CPT (continued pretraining) teaches the law itself — the model drills the full text of every section in both directions, so the knowledge lives in the weights. 360,985 law drills, ~800M Thai-law tokens.
- SFT (supervised fine-tuning) teaches grounded answering — every answer follows a fixed JSON contract that cites only the sections it was given. 16,436 exam answers and essays.
- GRPO (reinforcement learning) teaches precision — the reward is the benchmark's own citation F1, penalizing wrong or missing citations. 8,568 graded questions, ~68,500 drafts.
🧾 Model details
| Base model | nvidia/Nemotron-3-Nano-Omni-30B-A3B-Reasoning (text core extracted; Mamba2-Transformer hybrid MoE) |
| Parameters | 30B total, ~3B active per token |
| Context length | 32,768 tested (architecture supports up to 256k) |
| Languages | Thai (primary), English (reasoning) |
| Precision | bfloat16 safetensors, 17 shards · NVFP4 for 24 GB single-GPU serving |
| Training stack | NVIDIA NeMo (Megatron-Bridge for CPT/SFT, NeMo-RL for GRPO) |
| Serving | vLLM (verified) and NVIDIA NIM (OpenAI-compatible) |
| License | NVIDIA Open Model Agreement |
| Status | Open-weight release |
🧪 How it is evaluated
RAG mode means you put candidate law sections in the prompt and the model cites only the ones that apply. It works with any retriever you already have and needs no particular embedding or rerank model. Because it is also strong closed-book, many questions need no retrieval at all.
| Mode | What it tests | Setup |
|---|---|---|
| Open-book "echo" | RAG best case: uses exactly the right documents | Only the relevant sections are provided; cite them all |
| Open-book "selection" | RAG realistic case: rejects near-miss documents | Relevant sections mixed with inapplicable ones; cite only the right subset |
| Closed-book | Pure memory, no retrieval | The question alone; recall law name and section from weights |
| Legal essays | Long-form legal writing | 72 held-out Thai Supreme Court cases reformatted as essay questions, graded on citations, holding, coverage and fluency |
What the model actually produces
All examples below are verbatim model output on held-out benchmark questions.
Open-book selection — the hardest mode. Five sections supplied, three applicable.
Question (TH): บริษัทจัดตั้งขึ้นตามกฎหมายประเทศไทย ... ได้แต่งตั้งให้ผู้บริหารหรือพนักงานไปดำรงตำแหน่งกรรมการในบริษัทลูกในต่างประเทศ โดยจะได้รับค่าตอบแทนเงินเดือน สวัสดิการต่าง ๆ
Answer (TH): 1. บริษัทมีหน้าที่ต้องนำเงินได้ที่จ่ายจากหน้าที่งานที่ทำให้นายจ้างในประเทศไทยมารวมคำนวณเป็นรายได้เพื่อนำส่งภาษีหัก ณ ที่จ่าย ตามมาตรา 50 (1) แห่งประมวลรัษฎากร ... 2. ... หากไม่ได้นำเงินค่าตอบแทนที่ได้รับเข้ามาในประเทศไทยในปีภาษีเดียวกัน ผู้บริหารหรือพนักงานดังกล่าวไม่มีหน้าที่ต้องเสียภาษีเงินได้บุคคลธรรมดา
Answer (EN): The company must include income paid for duties performed for the Thai employer when computing withholding tax under Revenue Code section 50(1). An executive paid for the overseas directorship is not liable to Thai personal income tax if the money is not brought into Thailand in the same tax year.
Cited 41, 50 and 56; left out 40 and 48. Citation F1 1.00.
Closed-book — no statute text in the prompt at all.
Question (TH): บริษัทฯ ได้นำเข้าสินค้าชื่อว่า "C." เพื่อใช้ทดแทน Choline Chloride ในอาหารสัตว์ โดยมีสรรพคุณใช้เพื่อช่วยในการทำงานของตับ ... ได้รับยกเว้นภาษีมูลค่าเพิ่มหรือไม่
Answer (TH): การนำเข้าสินค้าชื่อ "C." ... โดยบริษัทฯ เป็นผู้รับใบอนุญาตนำเข้าอาหารสัตว์ควบคุมเฉพาะ ถือเป็นการนำเข้าอาหารสัตว์ที่ได้รับยกเว้นภาษีมูลค่าเพิ่มตามมาตรา 81 (1) (ง) และมาตรา 81 (2) (ก) แห่งประมวลรัษฎากร
Answer (EN): The import qualifies as an import of animal feed exempt from VAT under Revenue Code section 81(1)(d) and section 81(2)(a), the company holding the controlled animal-feed import licence.
Section and both sub-paragraphs recalled from weights, with no statute provided. Citation F1 1.00.
Legal essay — graded on four axes.
Question (TH): จำเลยเป็นหนี้เงินกู้ยืมและเงินเล่นแชร์จำนวน 95,600 บาทแก่โจทก์ร่วม ซึ่งได้จดทะเบียนไว้ในสมุดบันทึกของโจทก์ร่วม โดยมีข้อความและตัวเลขเป็นหลักฐานแห่งหนี้ และจำเลยได้ลงลายมือชื่อรับรองข้อความและตัวเลขในเอกสารนั้นไว้ ต่อมาจำเลยได้ใช้ปากกาขีดฆ่าเป็นเครื่องหมายกากบาทและเครื่องหมายวงกลมลงบนข้อความและตัวเลข
Answer (TH, excerpt): ศาลฎีกาพิพากษายืนตามศาลอุทธรณ์ โดยวินิจฉัยว่า การกระทำของจำเลยเป็นความผิดฐานทำให้เสียหายหรือทำลายเอกสารในประการที่น่าจะเกิดความเสียหายแก่ผู้อื่น ตามประมวลกฎหมายอาญา มาตรา 188 ... แม้เอกสารที่ยังเหลืออยู่จะสามารถอ่านเข้าใจข้อความและตัวเลขเดิมได้ ก็ถือเป็นการทำให้เสียหายหรือทำลายเอกสารในประการที่น่าจะเกิดความเสียหายแก่ผู้อื่นแล้ว
Answer (EN, excerpt): The Supreme Court affirmed the Court of Appeal, holding the defendant guilty of damaging or destroying a document in a manner likely to cause injury to another, under Criminal Code section 188 ... Striking out the text and figures and then tearing the document apart constitutes damage or destruction likely to cause injury, even though the remaining fragments can still be read.
🚀 Deployment
The model exposes an OpenAI-compatible API under both serving paths below, so the Python examples that follow work unchanged either way.
vLLM (2 GPUs, tensor parallel)
vllm serve iapp/openthai2.0-legal-thaillm-nemotron-3-nano-30b-a3b \
--tensor-parallel-size 2 --trust-remote-code \
--max-model-len 32768 --enforce-eager
NVIDIA NIM
The base is an NVIDIA Nemotron, so it fits the NIM for LLMs path:
docker run --rm --gpus all --shm-size=16g \
-v <path-to-model>:/model \
-e NIM_MODEL_NAME=/model \
-e NIM_SERVED_MODEL_NAME=openthai2.0-legal \
-p 8000:8000 \
nvcr.io/nim/nvidia/llm-nim:latest
Use the current container tag and configuration from the NVIDIA NIM for LLMs catalog; NIM exposes the same OpenAI-compatible endpoint.
vLLM 0.19.1, tensor-parallel 2 on 2× H100 (80 GB), --max-model-len 32768, --gpu-memory-utilization 0.90, --enforce-eager, --trust-remote-code. Thinking on and off, and temperatures 0.0 and 0.7, all verified. For single-GPU deployment, serve the NVFP4 (4-bit) weights on a card with at least 24 GB of VRAM.
🛠️ Quickstart
Grounded citation answering (RAG mode)
This exact example was run against the released weights; the output shown is the model's real response.
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="none")
SYSTEM = ("You are OpenThaiGPT-Legal, an expert assistant on Thai law. You are given a legal "
"question and the exact statutory sections needed to answer it. Reason step by step in "
"English, then give the final answer in Thai. Cite ONLY sections present in the provided "
"context, using each section's exact law_name and bare section number (e.g. 132, 77/1). "
'Output the final answer as JSON: {"answer": "<Thai answer>", '
'"citations": [{"law": "<law_name>", "section": "<bare id>"}]}.')
USER = """Provided context:
<law law_name="ประมวลกฎหมายแพ่งและพาณิชย์" section="420">
ผู้ใดจงใจหรือประมาทเลินเล่อ ทำต่อบุคคลอื่นโดยผิดกฎหมายให้เขาเสียหาย ... จำต้องใช้ค่าสินไหมทดแทนเพื่อการนั้น
</law>
Question (ตอบเป็นภาษาไทย):
นาย ก. ขับรถโดยประมาทชนรถของนาย ข. เสียหาย นาย ก. ต้องรับผิดตามกฎหมายใด"""
r = client.chat.completions.create(
model="openthai2.0-legal-thaillm-nemotron-3-nano-30b-a3b",
messages=[{"role": "system", "content": SYSTEM}, {"role": "user", "content": USER}],
temperature=0.0, max_tokens=1024,
extra_body={"chat_template_kwargs": {"enable_thinking": False}})
print(r.choices[0].message.content)
Actual model output:
{"answer": "นาย ก. ต้องรับผิดตามประมวลกฎหมายแพ่งและพาณิชย์ มาตรา 420",
"citations": [{"law": "ประมวลกฎหมายแพ่งและพาณิชย์", "section": "420"}]}
Closed-book mode
No context at all — the model recalls the section from its weights.
SYSTEM = ("You are an expert on Thai law. You are given ONLY a legal question, with NO reference "
"material provided. Using your OWN knowledge of Thai statutes, answer in Thai and cite the "
"specific sections that apply (law name + bare section number, มาตรา). "
'Output ONLY a JSON object: {"answer":"<Thai answer>","citations":[{"law":"<law name>",'
'"section":"<bare section number e.g. 40 or 77/1>"}]}.')
USER = """บริษัท ก. (บริษัทฯ) ได้หารือเกี่ยวกับภาษีมูลค่าเพิ่ม กรณีการนำเข้าสินค้าที่ใช้ชื่อ C. โดยบริษัทฯ ได้นำเข้าสินค้าชื่อว่า "C." เพื่อใช้ทดแทน Choline Chloride ในอาหารสัตว์ ซึ่งบริษัทฯ เป็นผู้รับใบอนุญาตนำเข้าอาหารสัตว์ควบคุมเฉพาะ จึงขอหารือว่า การนำเข้าสินค้าดังกล่าวได้รับยกเว้นภาษีมูลค่าเพิ่มหรือไม่"""
r = client.chat.completions.create(
model="openthai2.0-legal-thaillm-nemotron-3-nano-30b-a3b",
messages=[{"role": "system", "content": SYSTEM}, {"role": "user", "content": USER}],
temperature=0.0, max_tokens=1024,
extra_body={"chat_template_kwargs": {"enable_thinking": False}})
print(r.choices[0].message.content)
Essay mode
A short system prompt and the exam question. The model writes a full legal essay, citing มาตรา in prose rather than JSON, so raise max_tokens.
SYSTEM = "You are a Thai legal expert. Answer the question with legal analysis and cite the relevant มาตรา."
USER = """จำเลยเป็นหนี้เงินกู้ยืมและเงินเล่นแชร์จำนวน 95,600 บาทแก่โจทก์ร่วม ซึ่งได้จดทะเบียนไว้ในสมุดบันทึกของโจทก์ร่วม โดยมีข้อความและตัวเลขเป็นหลักฐานแห่งหนี้ ต่อมาจำเลยได้ใช้ปากกาขีดฆ่าและฉีกเอกสารจนขาดออกจากกัน แม้เอกสารที่ยังเหลืออยู่จะสามารถอ่านเข้าใจข้อความและตัวเลขเดิมได้ จำเลยมีความผิดฐานใด หรือเป็นเพียงกา รพยายามกระทำความผิดหรือไม่"""
r = client.chat.completions.create(
model="openthai2.0-legal-thaillm-nemotron-3-nano-30b-a3b",
messages=[{"role": "system", "content": SYSTEM}, {"role": "user", "content": USER}],
temperature=0.7, max_tokens=3000,
extra_body={"chat_template_kwargs": {"enable_thinking": False}})
print(r.choices[0].message.content)
⚙️ Recommended generation settings
| Use case | temperature | top_p | max_tokens (suggested) | thinking |
|---|---|---|---|---|
| Citation answering (RAG or closed-book) | 0.0 | 1.0 | 1024 | off |
| Legal essay drafting | 0.7 | 0.9 | 2048–4096 | on or off |
| General chat | 0.7 | 0.9 | 1024 | off |
max_tokensvalues are suggestions, not limits: any budget up to the 32k window works, and answers terminate naturally (citation answers rarely exceed 700 tokens). Raise it freely for long essays or thinking mode.- Thinking mode is fully supported: the model reasons in English inside a think block, then answers in Thai. It helps on essays and complex analysis. The benchmark numbers above use thinking off, which is the tuned path for citation tasks; allow roughly 2× the token budget when thinking is on.
- Always serve with
--max-model-len 32768: real Revenue Code contexts overflow smaller windows.
✅ Suitable for
- Legal RAG and search — pair it with any retriever; it cites only what applies from the supplied sections.
- Drafting and review tools — the JSON citation contract plugs straight into automation.
- In-house counsel and compliance — self-hosted, so client and case data never leaves your perimeter.
- Public agencies — data residency and governance stay entirely under your control.
- Research and fine-tuning — open weights, ready to adapt to your own legal domain.
⚠️ Limitations and responsible use
- Retrieval quality drives results. Given the right sections, citations are near-perfect; if the retriever supplies the wrong sections, the answer follows them. For production RAG, pair the model with a sound retriever and monitor retrieval quality.
- Near-miss rejection is the hardest task. Tax selection (picking the applicable section among close alternatives) is the lowest-scoring axis for every model, ours included. Retrieval tuning and human review are advised for high-stakes use.
- Structured output is the strong path. The JSON citation contract is ideal for automation and legal-tech pipelines; free-form chat is supported but less structured.
- Scope. Trained on Thai statutory law (Revenue Code, Civil and Commercial Code, related acts) and Revenue Department rulings; coverage of niche areas or very recent amendments may be thinner, and statutes change over time.
- Human oversight required. Outputs are decision support, not legal advice. A qualified professional should verify every citation against the current law before relying on it.
- Data provenance. Some essay training data derives from Thai bar examination materials; confirm redistribution terms for your jurisdiction and use case.
🙏 Sources and acknowledgements
- Base model: NVIDIA Nemotron-3-Nano-Omni-30B-A3B-Reasoning, NVIDIA Open Model Agreement. We train on its extracted text core.
- Evaluation: NitiBench (VISAI-AI, MIT); SFT data built from WangchanX-Legal-ThaiCCL (VISTEC, MIT).
- Built by the OpenThai team (AIEAT / iApp Technology) on the NVIDIA NeMo stack, with the Big Data Institute (BDI), the ThaiLLM initiative and NVIDIA.
📬 Get in touch
Deploying OpenThai 2.0 Legal in your organization, or want it tuned to your own corpus?
- Email: sale@iapp.co.th · Phone: 086-322-5858
- Discord: iApp community
- More open models: OpenThai Chinda 4B