AnrakLegal Developer Playbook

API v1 • 588,024+ docs

REST API & MCP Integration

AnrakLegal provides a branded interface to Indian legal case law. Authenticate once, access 588,024+ Supreme Court and High Court judgments, statutes, and tribunals—all without revealing upstream infrastructure to your users.

Quick StartGet results in 2 minutes

From Zero to Legal Research

1

Get your API key

Visit /console and generate a new API key. Save it securely—you'll only see the full key once.

2

Search for cases

bash
curl "https://anraklegal.fly.dev/api/v1/search?q=arbitration+supreme+court" \
  -H "x-anrak-key: YOUR_API_KEY"

Returns 10 results per page with insights: top courts, year distribution, popular tags.

3

Retrieve full judgment

bash
curl "https://anraklegal.fly.dev/api/v1/documents/63240555" \
  -H "x-anrak-key: YOUR_API_KEY"

Get complete case text (50-200KB), metadata, citations, and case history.

4

Monitor usage

bash
curl "https://anraklegal.fly.dev/api/v1/usage" \
  -H "x-anrak-key: YOUR_API_KEY"

Or visit /usage for a visual dashboard with per-key stats, endpoint distribution, and recent activity.

Authentication

Every request requires your AnrakLegal API key. We support multiple header formats for flexibility across different client integrations:

Preferred

x-anrak-key: YOUR_KEY

Alternative

x-api-key: YOUR_KEY

Bearer Token

Authorization: Bearer YOUR_KEY

Legacy

x-lexsight-key: YOUR_KEY

Security

Keys are SHA-256 hashed server-side. Never commit keys to version control, share in Slack/email, or expose in client-side code. Rotate immediately if compromised.

REST API Endpoints

Base URL: https://anraklegal.fly.dev

GET/api/v1/search

Full-text search across 588,024+ Indian legal documents with AI-powered insights.

Parameters

qstringrequired

Search query (keywords, phrases, field filters)

pageNumnumber

Page number (default: 0, starts at 0)

maxPagesnumber

Fetch multiple pages in one call (max: 1000)

doctypesstring

Filter by: judgments, laws, tribunals, supremecourt

fromyearnumber

Start year for temporal filtering

toyearnumber

End year for temporal filtering

forumstring

Filter by court/forum name

statestring

Filter district courts by state (e.g., maharashtra)

GET/api/v1/documents/:docId

Retrieve complete judgment text with metadata, citations, and case history.

Parameters

docIdstringrequired

Document ID from search results (tid field)

maxCitesnumber

Number of citations to include (max: 50)

maxCitedbynumber

Number of citing cases to include (max: 50)

GET/api/v1/documents/:docId/meta

Lightweight metadata for dashboards—no full text, ~2KB response.

Parameters

docIdstringrequired

Document ID from search results

GET/api/v1/documents/:docId/fragment

Get context snippets where query terms appear in the document.

Parameters

docIdstringrequired

Document ID from search results

qstringrequired

Query terms to search within document

GET/api/v1/documents/:docId/original

Download original court-filed document (PDF/HTML/DOC) as base64.

Parameters

docIdstringrequired

Document ID from search results

GET/api/v1/usage

View usage statistics for your API key (requests, endpoints, status codes).

Response Examples

Search Response

json
{
  "query": "arbitration supreme court",
  "page": 0,
  "insights": {
    "topCourts": [
      { "court": "Supreme Court of India", "count": 45 },
      { "court": "Delhi High Court", "count": 23 }
    ],
    "judgmentsByYear": [
      { "year": "2024", "count": 18 },
      { "year": "2023", "count": 27 }
    ],
    "popularTags": ["arbitration", "section-11", "appointment-of-arbitrator"],
    "relatedQueries": ["arbitration award", "section 34 arbitration act"]
  },
  "results": {
    "docs": [
      {
        "tid": 63240555,
        "title": "My Preferred Transformation And ... vs Sumithra Inn on 5 January, 2021",
        "court": "Delhi High Court",
        "publishdate": "2021-01-05",
        "numcites": 26,
        "numcitedby": 7,
        "docsize": 117292
      }
    ],
    "found": 588024
  }
}

Document Response

json
{
  "doc": {
    "tid": 63240555,
    "title": "My Preferred Transformation And ... vs Sumithra Inn",
    "court": "Delhi High Court",
    "publishdate": "2021-01-05",
    "judges": "C. Hari Shankar",
    "headline": "Arbitration And Conciliation Act (26 of 1996) - Section 11(6)...",
    "section": "<p>IN THE HIGH COURT OF DELHI AT NEW DELHI...</p>",
    "numcites": 26,
    "numcitedby": 7,
    "citeList": [...],
    "citedbyList": [...]
  }
}

Usage Response

json
{
  "apiKey": {
    "id": "cm5x...",
    "name": "Production API Key",
    "preview": "ANRAK-••••-••••-••••-beKJu9",
    "active": true,
    "requestCount": 147,
    "lastUsedAt": "2025-10-12T10:23:45.123Z",
    "createdAt": "2025-10-10T08:15:30.000Z"
  },
  "recentLogs": [
    {
      "endpoint": "/api/v1/search",
      "status": 200,
      "createdAt": "2025-10-12T10:23:45.123Z"
    }
  ]
}

Original Document Response

json
{
  "data": {
    "content": "JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC...",
    "mimeType": "application/pdf",
    "encoding": "base64"
  },
  "metadata": {
    "docId": "63240555",
    "sizeBytes": 245678
  }
}

Error Responses

401 Unauthorized
json
{
  "error": "Unauthorised",
  "message": "Invalid or missing API key"
}

Check your API key format and ensure it's active in /console.

404 Not Found
json
{
  "error": "Document not found",
  "message": "No document with ID 99999999"
}

Verify the document ID (tid) from search results. Some very old documents may be unavailable.

500 Server Error
json
{
  "error": "Upstream service unavailable",
  "message": "Upstream API timeout"
}

Retry with exponential backoff. If errors persist, contact support. We cache responses (5-min TTL) to minimize upstream issues.

Rate Limiting & Caching

Rate Limits

  • 3 API keys per email (request more via support)
  • No per-minute throttling—subject to plan limits
  • Monitor usage at /usage
  • Deactivate unused keys to prevent abuse

Caching

  • LRU in-memory cache: 200 entries, 5-minute TTL
  • Repeated queries return in <50ms
  • Reduces API quota consumption
  • Cache-Control headers indicate cache hits

Performance Characteristics

Based on production testing with 588,024+ documents (cached responses significantly faster):

OperationResponse SizeTime (uncached)Best Use Case
Search~50KB1-2sInitial discovery
Document50-200KB2-4sFull analysis
Metadata~2KB0.5sQuick reference
Fragment5-20KB1sTargeted lookup
Original100KB-5MB3-10sOfficial record

Code Examples

Node.js / TypeScript

typescript
const ANRAK_KEY = process.env.ANRAK_API_KEY;
const BASE_URL = "https://anraklegal.fly.dev/api/v1";

async function searchCases(query: string) {
  const response = await fetch(`${BASE_URL}/search?q=${encodeURIComponent(query)}`, {
    headers: { "x-anrak-key": ANRAK_KEY }
  });

  if (!response.ok) {
    throw new Error(`Search failed: ${response.statusText}`);
  }

  const data = await response.json();
  return data;
}

async function getDocument(docId: string) {
  const response = await fetch(`${BASE_URL}/documents/${docId}`, {
    headers: { "x-anrak-key": ANRAK_KEY }
  });

  const data = await response.json();
  return data;
}

// Usage
const results = await searchCases("arbitration section 11");
const firstDoc = results.results.docs[0];
const fullJudgment = await getDocument(firstDoc.tid);
console.log(fullJudgment.doc.section); // Full HTML text

Python

python
import requests
import os

ANRAK_KEY = os.environ["ANRAK_API_KEY"]
BASE_URL = "https://anraklegal.fly.dev/api/v1"

def search_cases(query: str):
    response = requests.get(
        f"{BASE_URL}/search",
        params={"q": query},
        headers={"x-anrak-key": ANRAK_KEY}
    )
    response.raise_for_status()
    return response.json()

def get_document(doc_id: str):
    response = requests.get(
        f"{BASE_URL}/documents/{doc_id}",
        headers={"x-anrak-key": ANRAK_KEY}
    )
    response.raise_for_status()
    return response.json()

# Usage
results = search_cases("arbitration section 11")
first_doc = results["results"]["docs"][0]
full_judgment = get_document(str(first_doc["tid"]))
print(full_judgment["doc"]["section"])  # Full HTML text

cURL

bash
# Search with pagination and filtering
curl "https://anraklegal.fly.dev/api/v1/search?q=cheque+bounce&pageNum=0&maxPages=3&fromyear=2020&toyear=2024&doctypes=supremecourt" \
  -H "x-anrak-key: YOUR_KEY"

# Get document with citations
curl "https://anraklegal.fly.dev/api/v1/documents/63240555?maxCites=10&maxCitedby=5" \
  -H "x-anrak-key: YOUR_KEY"

# Get fragments matching query
curl "https://anraklegal.fly.dev/api/v1/documents/63240555/fragment?q=force+majeure" \
  -H "x-anrak-key: YOUR_KEY"

# Download original PDF (base64)
curl "https://anraklegal.fly.dev/api/v1/documents/63240555/original" \
  -H "x-anrak-key: YOUR_KEY"

# Check usage stats
curl "https://anraklegal.fly.dev/api/v1/usage" \
  -H "x-anrak-key: YOUR_KEY"

MCP Integration for AI Assistants

Model Context Protocol (MCP) allows AI assistants like Claude, Cursor, and other LLMs to directly access AnrakLegal tools. Instead of copy-pasting API responses, your AI can search cases, retrieve judgments, and analyze legal documents autonomously.

Installation

1

Configure Claude Desktop:

Open your Claude Desktop configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
2

Add the MCP server configuration:

json
{
  "mcpServers": {
    "anraklegal": {
      "command": "npx",
      "args": ["-y", "@anraklegal/mcp-server@latest"],
      "env": {
        "ANRAKLEGAL_KEY": "ANRAK-xxxxx-xxxxx-xxxxx-xxxxx"
      }
    }
  }
}

Replace ANRAK-xxxxx with your API key from /console

3

Restart Claude Desktop:

  • macOS: Press Cmd+Q then reopen
  • Windows: Close all windows, ensure process exits, then reopen
4

Verify installation:

Ask Claude: "What AnrakLegal tools do you have access to?" Should list 5 tools below.

NPX Installation

The npx command automatically downloads and runs the latest MCP server. No manual installation or updates required. Requires Node.js 18+ on your system.

Available MCP Tools

anraklegalSearch

Search Indian legal documents

query (string)pageNum? (number)maxPages? (number)
anraklegalDocument

Retrieve full judgment text

docId (string)maxCites? (number)maxCitedBy? (number)
anraklegalMetadata

Get lightweight case metadata

docId (string)
anraklegalFragment

Get snippets matching query

docId (string)query (string)
anraklegalOriginal

Download original PDF/HTML

docId (string)

Example MCP Workflow

User to Claude:

"Can a third party who wasn't a signatory invoke an arbitration agreement?"

Claude's Actions:

  1. Calls anraklegalSearch("arbitration third party non-signatory")
  2. Receives 50 relevant cases with insights
  3. Calls anraklegalDocument("63240555") for leading case
  4. Analyzes 117KB judgment text
  5. Synthesizes answer with proper citations: "Yes, under certain conditions established in My Preferred Transformation vs Sumithra Inn (2021)..."

Why MCP?

MCP enables agentic workflows: AI assistants can autonomously search, retrieve, analyze, and cite legal documents without manual API calls. Perfect for legal research, brief generation, and case analysis.

Troubleshooting

❌ "Unauthorised" or 401 errors
  • Verify API key is active in /console
  • Check for typos—keys are case-sensitive
  • Ensure header format: x-anrak-key: YOUR_KEY
  • Key must start with ANRAK-
🔍 No search results or "Document not found"
  • Try broader search terms (e.g., "arbitration" instead of "arbitration section 11(6)(a)")
  • Check document ID format—must be numeric string from search results (tid field)
  • Very old documents (<1990) may have limited availability
  • Use filters: ?doctypes=supremecourt&fromyear=2020
⏱️ Slow responses or timeouts
  • First request is slower (~2-4s), subsequent requests cached (<50ms)
  • Large documents (200KB+) take longer—use /meta endpoint for quick checks
  • Original PDFs (5MB+) can take 10s—download once and cache client-side
  • If errors persist, upstream service may be overloaded—retry with exponential backoff
🤖 MCP tools not showing in Claude/Cursor
  • Restart Claude Desktop completely (not just close window)
  • Verify dist/mcpServer.js exists—run npm run mcp:build
  • Check absolute path in config—no ~ or relative paths
  • Ensure ANRAKLEGAL_KEY env var is set correctly
  • Check Claude logs: ~/Library/Logs/Claude/mcp*.log
📊 Usage stats not updating
  • Usage updates in real-time but may take 1-2 seconds to reflect
  • Cached requests still count toward usage
  • Verify requests are successful (200 status) in /usage dashboard
  • Failed requests (401, 404, 500) are logged but don't increment your quota

Enterprise & Support

Need higher rate limits, custom SLAs, audit logging, or white-label deployment? Email us at support@anraklegal.com or open an issue on GitHub.

AnrakLegal - India's Premier Legal AI API | Verified Case Law & Statutes