# AnrakLegal REST API — Agent Skills Reference

> **Base URL:** `https://anrak.legal/api/v1`
> **Auth:** `X-API-Key: ANRAK-xxxxx-xxxxx-xxxxx-xxxxx` header on every request
> **Get a key:** https://anrak.legal/console

---

## Quick Start

```bash
# List all available tools
curl https://anrak.legal/api/v1/tools \
  -H "X-API-Key: YOUR_KEY"

# Execute any tool
curl -X POST https://anrak.legal/api/v1/tools/paralegal_case \
  -H "X-API-Key: YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{"action": "list", "limit": 5}'
```

---

## Architecture

Two ways to access every capability:

1. **RESTful endpoints** — clean URLs for common operations (cases, search, statutes)
2. **Universal tool gateway** — `POST /api/v1/tools/{toolName}` with `{"action": "...", ...params}` for all 25+ tools and 100+ actions

Both use the same API key. No scopes, no connectors — full access.

---

## 1. Legal Research

### Search Cases
```
GET /api/v1/search?q={query}&page={0}&maxPages={10}
```
Search 588K+ Indian court judgments. Returns case cards with court, date, citation, headline.

**Also via tool gateway:**
```json
POST /api/v1/tools/search_cases
{"q": "bail in NDPS cases", "page": 0}
```

### Get Document
```
GET /api/v1/documents/{docId}
```
Full judgment text, metadata, citations. Token-gated.

**Also via tool gateway:**
```json
POST /api/v1/tools/get_document
{"doc_id": "123456"}
```

### Document Metadata
```
GET /api/v1/documents/{docId}/meta
```
Lightweight metadata for dashboards (no full text).

### Document Fragment
```
GET /api/v1/documents/{docId}/fragment?q={query}
```
Search within a specific document. Returns matched paragraphs.

### Document Original
```
GET /api/v1/documents/{docId}/original
```
Download the original binary file (PDF/Word).

---

## 2. Statutes & Legislation

### Search Statutes
```
GET /api/v1/statutes/search?query={query}&act={BNS}&limit={5}
```
Semantic search across Indian statutes: BNS, BNSS, BSA, IPC, CrPC, Evidence Act, Constitution.

**Also via tool gateway:**
```json
POST /api/v1/tools/search_statutes
{"query": "punishment for theft", "act": "BNS", "limit": 5}
```

**Response fields:** `shortName`, `fullName`, `sectionNumber`, `heading`, `body`, `explanation`, `provisos`, `crossReferences`, `similarity`

### Get Statute Section
```
GET /api/v1/statutes/section?act={BNS}&section={302}
```
Exact lookup of a specific section. Returns full text with old/new law cross-references.

**Also via tool gateway:**
```json
POST /api/v1/tools/get_statute_section
{"act": "BNS", "section": "302"}
```

**Response fields:** `act`, `fullName`, `sectionNumber`, `heading`, `body`, `explanation`, `provisos`, `crossReferences`, `amendments`, `status`, `tags`

---

## 3. Web Search

### Search Web
```
GET /api/v1/web/search?query={query}&focus={legal_news}
```
Web search focused on legal content. Focus options: `legal_news`, `amendments`, `comparative_law`, `academic`, `general`.

**Also via tool gateway:**
```json
POST /api/v1/tools/search_web
{"query": "Supreme Court ruling on bail", "focus": "legal_news"}
```

**Response fields:** `query`, `focus`, `content`, `citations`

---

## 4. Case Management

### List Cases
```
GET /api/v1/cases?status={ACTIVE}&limit={20}&offset={0}
```
List your paralegal cases. Filter by status: `ACTIVE`, `ON_HOLD`, `CLOSED`, `PENDING`.

### Create Case
```
POST /api/v1/cases
{"case_name": "...", "case_number": "...", "client_name": "...", "court": "...", "description": "...", "practice_area": "...", "opposing_party": "...", "opposing_counsel": "..."}
```
Only `case_name` is required.

### Get Case
```
GET /api/v1/cases/{caseId}
```
Full case details with AI intelligence (key facts, timeline, legal issues, parties), document list, and counts.

### Update Case
```
PATCH /api/v1/cases/{caseId}
{"status": "ON_HOLD", "description": "Updated description"}
```

### Archive Case
```
POST /api/v1/cases/{caseId}/archive
```

### Trigger AI Analysis
```
POST /api/v1/cases/{caseId}/analyze
```
Triggers background AI analysis of case documents. Results available in the case intelligence fields after a few minutes.

---

## 5. Case Documents

### List Documents
```
GET /api/v1/cases/{caseId}/documents
```
Returns documents with: `documentId`, `filename`, `wordCount`, `pageCount`, `mimeType`, `addedAt`.

### Save Document
```
POST /api/v1/cases/{caseId}/documents
{"title": "Research Notes", "content": "...", "file_type": "md"}
```
File types: `md`, `txt`, `html`, `json`, `csv`. Triggers case reanalysis.

### Get Document Content
```
GET /api/v1/cases/{caseId}/documents/{documentId}/content
```
Full text content reconstructed from chunks. Truncated at 100K characters.

### Search Documents
```
GET /api/v1/cases/{caseId}/documents/search?query={term}&limit={10}
```
Full-text search across all documents in a case.

### Get Checklist
```
GET /api/v1/cases/{caseId}/checklist
```
AI-generated procedural checklist with items, phases, priorities, due dates.

---

## 6. Universal Tool Gateway

The gateway exposes ALL capabilities through a single pattern:

```
POST /api/v1/tools/{toolName}
Content-Type: application/json
X-API-Key: YOUR_KEY

{"action": "action_name", ...params}
```

### List All Tools
```
GET /api/v1/tools
```
Returns every available tool with name, description, and input schema.

### Available Tool Modules

#### `paralegal_case` — Case management
| Action | Description |
|--------|-------------|
| `list` | List all cases with filtering and pagination |
| `get` | Get case details with AI intelligence |
| `create` | Create a new case |
| `update` | Update case fields |
| `analyze` | Trigger AI analysis |
| `archive` | Close/archive a case |

#### `paralegal_workflow` — Multi-step AI workflows
| Action | Description |
|--------|-------------|
| `list_templates` | List available workflow templates |
| `list` | List workflow runs |
| `get` | Get workflow run details |
| `create` | Create a new workflow |
| `update` | Update a workflow |
| `delete` | Delete a workflow |
| `run` | Execute a workflow |
| `run_status` | Check run status |

#### `paralegal_checklist` — Procedural checklists
| Action | Description |
|--------|-------------|
| `get` | Get checklist for a case |
| `regenerate` | Regenerate the checklist |
| `add_item` | Add a checklist item |
| `update_item` | Update item status/notes |
| `delete_item` | Remove an item |
| `generate_document` | Generate document from checklist |
| `link_document` | Link a document to a checklist item |

#### `paralegal_task` — Task management
| Action | Description |
|--------|-------------|
| `list` | List tasks (filter by case, status) |
| `create` | Create a task |
| `update` | Update a task |
| `complete` | Mark task complete |
| `delete` | Delete a task |

#### `paralegal_calendar` — Calendar events
| Action | Description |
|--------|-------------|
| `list` | List upcoming events |
| `create` | Create a calendar event |
| `update` | Update an event |
| `delete` | Delete an event |

#### `paralegal_document` — Advanced document operations
| Action | Description |
|--------|-------------|
| `semantic_search` | AI-powered vector search across case documents |
| `categorize` | Auto-classify document type |
| `list_categories` | Document category breakdown |
| `share` | Generate a share link |

#### `paralegal_contract` — Contract lifecycle
| Action | Description |
|--------|-------------|
| `list` | List contracts |
| `get` | Get contract details |
| `list_redlines` | View redline suggestions |
| `add_redline` | Add a redline |
| `update_redline` | Update redline status |
| `list_obligations` | View tracked obligations |
| `update_obligation` | Update obligation status |
| `list_versions` | Version history |
| `get_version` | Get specific version |

#### `paralegal_billing` — Time & billing
| Action | Description |
|--------|-------------|
| `list` | List time entries |
| `create` | Log time entry |
| `update` | Update time entry |
| `delete` | Delete time entry |
| `summary` | Billing summary |

#### `paralegal_client` — Client CRM
| Action | Description |
|--------|-------------|
| `list` | List clients |
| `get` | Get client details |
| `create` | Create a client |
| `update` | Update client |
| `list_contacts` | Client contacts |
| `add_contact` | Add contact |
| `list_matters` | Client matters |

#### `paralegal_collaboration` — Multi-party collaboration
| Action | Description |
|--------|-------------|
| `list_collaborators` | List case collaborators |
| `invite` | Invite collaborator |
| `update_access` | Change access level |
| `revoke` | Remove collaborator |
| `list_comments` | List case comments |
| `post_comment` | Post a comment |
| `resolve_comment` | Resolve a comment |

#### `paralegal_knowledge` — Case knowledge base
| Action | Description |
|--------|-------------|
| `search` | Search knowledge base |
| `list_files` | List knowledge files |
| `get_file` | Get file content |
| `create_file` | Create knowledge file |
| `graph_stats` | Knowledge graph stats |
| `graph_build` | Rebuild knowledge graph |

#### `paralegal_transcript` — Transcripts
| Action | Description |
|--------|-------------|
| `list` | List transcripts |
| `get` | Get transcript metadata |
| `get_content` | Get transcript text |
| `search` | Search transcripts |

#### `paralegal_hearing` — Court hearings
| Action | Description |
|--------|-------------|
| `list` | List hearings for a case |
| `create` | Add a hearing |
| `update` | Update hearing details |
| `delete` | Remove a hearing |

#### `paralegal_court_tracking` — eCourts integration
| Action | Description |
|--------|-------------|
| `list` | List tracked CNR numbers |
| `add_cnr` | Add CNR number for tracking |
| `sync` | Force sync with eCourts |
| `get_hearings` | Get hearing history |

#### `paralegal_long_task` — Async AI research
| Action | Description |
|--------|-------------|
| `dispatch` | Start a long-running AI task |
| `get_status` | Check task progress |
| `list` | List dispatched tasks |

#### `paralegal_memorial` — Legal memorial drafting
| Action | Description |
|--------|-------------|
| `list` | List memorials |
| `get` | Get memorial content |
| `create` | Create a new memorial |
| `get_section` | Get specific section |
| `update_status` | Update memorial status |

#### `court_watch` — Court alerts
| Action | Description |
|--------|-------------|
| `list` | List court watch entries |
| `create` | Create a watch |
| `delete` | Delete a watch |
| `list_alerts` | List triggered alerts |
| `mark_read` | Mark alert as read |
| `track_alert` | Track a specific alert |

#### `legal_feed` — Legal news (no auth scope required)
| Action | Description |
|--------|-------------|
| `search` | Search legal articles |
| `get` | Get article content |
| `recent` | Recent articles |

#### `moot_court` — Practice arguments
| Action | Description |
|--------|-------------|
| `list_sessions` | List practice sessions |
| `get_session` | Get session details |
| `create_session` | Start a moot court session |

#### `account_info` — Account status
| Action | Description |
|--------|-------------|
| `usage` | Token usage stats |
| `plan` | Current plan details |
| `features` | Available features |

#### `firm_management` — Firm operations
| Action | Description |
|--------|-------------|
| `info` | Firm information |
| `members` | List firm members |
| `conflict_check` | Run conflict check |

#### `anrakpilot_delegate` — Bot delegation
| Action | Description |
|--------|-------------|
| `create_task` | Delegate task to AnrakPilot |
| `get_task` | Check task status |
| `list_tasks` | List delegated tasks |
| `list_schedules` | List bot schedules |
| `create_schedule` | Create recurring schedule |

---

## 7. Composio Integrations (Gmail, Calendar, Drive, etc.)

### List Connected Tools
```
GET /api/v1/composio/tools
```
Returns connected toolkits and available tools with input schemas.

### Execute Tool
```
POST /api/v1/composio/execute
{"tool": "GMAIL_SEND_EMAIL", "arguments": {"to": "...", "subject": "...", "body": "..."}}
```

Supported toolkits: GMAIL, GOOGLECALENDAR, GOOGLEDRIVE, OUTLOOK, SLACK, NOTION.

---

## Error Handling

| Status | Meaning |
|--------|---------|
| 400 | Invalid parameters |
| 401 | Missing/invalid API key |
| 402 | Token limit exceeded (upgrade plan) |
| 404 | Resource not found |
| 429 | Rate limit exceeded (retry after header) |
| 500 | Internal error |
| 503 | Service unavailable |

Error response format:
```json
{"error": "Description of the error"}
```

---

## Rate Limits

- **API calls:** 120 requests/minute per user
- **Case reads:** 60 requests/minute per key
- **Case writes:** 10 requests/hour per key
- **Paralegal reads:** 120 requests/minute per key
- **Paralegal writes:** 30 requests/minute per key
- **Paralegal execute:** 5 requests/hour per key (AI-intensive operations)

---

## Indian Legal Framework Notes

When working with Indian law, always check BOTH old and new law:
- **IPC** (Indian Penal Code) → replaced by **BNS** (Bharatiya Nyaya Sanhita) from July 2024
- **CrPC** (Code of Criminal Procedure) → replaced by **BNSS** (Bharatiya Nagarik Suraksha Sanhita)
- **Evidence Act** → replaced by **BSA** (Bharatiya Sakshya Adhiniyam)

Use `search_statutes` with both old and new act names for comprehensive coverage. The `crossReferences` field in statute results maps between old/new law equivalents.
