Skip to main content

lawsaathi — Official Python SDK

OpenAI-compatible Python client for the LawSaathi Developer API (delta-2.0-pro).

Install

pip install lawsaathi

(While in private beta, install from the repository: pip install <path-or-url-to-this-folder>. Publishing to PyPI: python -m build && twine upload dist/*.)

Quickstart

from lawsaathi import LawSaathi

client = LawSaathi(api_key="ls_live_...")  # from https://lawsaathi.in/developers

# ── Non-streaming ──
resp = client.chat.completions.create(
    model="delta-2.0-pro",
    messages=[{"role": "user", "content": "Explain anticipatory bail under BNSS 482"}],
)
print(resp.choices[0].message.content)
print(resp.usage.total_tokens)
print(resp.lawsaathi.cost_breakdown)   # {'input': ..., 'output': ..., 'total': ...}

# ── Streaming (SSE) ──
stream = client.chat.completions.create(
    model="delta-2.0-pro",
    messages=[{"role": "user", "content": "Draft a legal notice for cheque bounce"}],
    stream=True,
    thinking=True,                        # optional extended reasoning
)
for chunk in stream:
    delta = chunk.choices[0].delta
    if getattr(delta, "reasoning_content", None):
        print("[thinking]", delta.reasoning_content, end="")
    if delta.content:
        print(delta.content, end="")

# ── Custom persona (optional — default is DELTA) ──
resp = client.chat.completions.create(
    model="delta-2.0-pro",
    messages=[{"role": "user", "content": "What is Section 138 of the NI Act?"}],
    persona="A patient law-school tutor who explains with examples",
)

# ── Files (PDF / images / DOCX / text) ──
resp = client.chat.completions.create(
    model="delta-2.0-pro",
    messages=[{"role": "user", "content": "Summarize this FIR and cite the sections"}],
    files=["/path/to/fir.pdf"],
)

# ── Files: staged upload (reuse a file across many requests) ──
with open("/path/to/contract.docx", "rb") as f:
    staged = client.files.create(f)          # -> { id, filename, bytes, expires_at }

resp = client.chat.completions.create(
    model="delta-2.0-pro",
    messages=[{"role": "user", "content": "List every termination clause in this contract"}],
    file_ids=[staged.id],
)

# ── Models ──
print(client.models.list().data)

Attaching files

Two ways to attach documents:

1. Inline (one-off requests): pass local paths via files=[...] — the SDK uploads them as multipart with your request.

2. Staged (/v1/files): upload once with client.files.create(file), then reference file_ids=[...] in any number of chat requests. Files auto-expire after 24 hours.

Supported types PDF, PNG, JPEG, WEBP, GIF, DOCX, TXT, JSON, CSV, Markdown
Max per request 5 files
Max size 10 MB per file
PDF page limit 100 pages

DOCX handling: when you upload a .docx, LawSaathi converts it to PDF server-side (via Google Drive export) and attaches the rendered PDF to the model — so the AI sees the real layout, tables, and signatures, not just raw extracted text. If conversion ever fails, the server automatically falls back to text extraction. Your code doesn't need to do anything special — upload the .docx exactly as you would any other file.

cURL (staged upload):

# 1. Stage the file
curl https://lawsaathi.in/v1/files/   -H "Authorization: Bearer ls_live_..."   -F "file=@/path/to/contract.docx"
# -> {"id": "3f1c...", "filename": "contract.docx", "bytes": 48213, ...}

# 2. Reference it
curl https://lawsaathi.in/v1/chat/completions/   -H "Authorization: Bearer ls_live_..."   -H "Content-Type: application/json"   -d '{"model": "delta-2.0-pro", "messages": [{"role": "user", "content": "Summarize this contract"}], "file_ids": ["3f1c..."]}'

Rate limits

Limit Value
Requests 100 / minute per user
Input tokens 500,000 / minute per user
Output tokens 100,000 / minute per user

Exceeding any limit returns 429 RateLimitError — retry with backoff.

Web search

resp = client.chat.completions.create(
    model="delta-2.0-pro",
    messages=[{"role": "user", "content": "Latest Supreme Court judgment on Article 21?"}],
    web_search=True,   # model may call the server-executed google search tool
)
print(resp.lawsaathi.searches)                    # number of search executions
print(resp.lawsaathi.cost_breakdown["search"])    # Rs.0.50 per execution

Tool calling (OpenAI-compatible, client-executed)

import json

tools = [{
    "type": "function",
    "function": {
        "name": "get_case_status",
        "description": "Look up a court case status by number",
        "parameters": {
            "type": "object",
            "properties": {"case_number": {"type": "string"}},
            "required": ["case_number"],
        },
    },
}]

resp = client.chat.completions.create(
    model="delta-2.0-pro",
    messages=[{"role": "user", "content": "Status of case 1234/2024?"}],
    tools=tools,
)
if resp.choices[0].finish_reason == "tool_calls":
    call = resp.choices[0].message.tool_calls[0]
    result = your_function(**json.loads(call.function.arguments))
    # send the result back
    final = client.chat.completions.create(
        model="delta-2.0-pro",
        messages=[
            {"role": "user", "content": "Status of case 1234/2024?"},
            {"role": "assistant", "tool_calls": [
                {"id": call.id, "function": {"name": call.function.name,
                                             "arguments": call.function.arguments}}],
            },
            {"role": "tool", "tool_call_id": call.id,
             "content": json.dumps({"status": "Listed for hearing on 20-09-2026"})},
        ],
        tools=tools,
    )

Billing

Input: ₹145 / million tokens · Output: ₹449 / million tokens · Search: ₹0.50 per execution. Every response includes lawsaathi.cost_breakdown and credits_remaining. Errors: 401 AuthenticationError (bad key), 402 InsufficientQuotaError (top up at lawsaathi.in/developers → Billing), 429 RateLimitError, 400 InvalidRequestError.

Error handling

from lawsaathi import LawSaathi, InsufficientQuotaError, AuthenticationError

try:
    resp = client.chat.completions.create(model="delta-2.0-pro", messages=[...])
except AuthenticationError:
    ...
except InsufficientQuotaError:
    ...

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lawsaathi-2.0.1.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lawsaathi-2.0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file lawsaathi-2.0.1.tar.gz.

File metadata

  • Download URL: lawsaathi-2.0.1.tar.gz
  • Upload date:
  • Size: 8.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for lawsaathi-2.0.1.tar.gz
Algorithm Hash digest
SHA256 27cba4988ad523fb4d1adb88988d7819c892fb873088bd784df8eafa8e09cf9a
MD5 2a6a891ac40eb4605b7970ca8f26d0ab
BLAKE2b-256 b217ecb855e8c067c662197816f3fccf71fc24e4b98acb7bef8b02463020bf0a

See more details on using hashes here.

File details

Details for the file lawsaathi-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: lawsaathi-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for lawsaathi-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af9b069358db84860dc3e3218e326f2894f5ce6efd39dc0264cfe77c1ca88008
MD5 1b41bee2b61db193397cd2541f8291da
BLAKE2b-256 4984c2c44d188ee70e79baf148d87ca8bc28ea06210c4b9ec870bfd50e41c778

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page