# Lawneu AI And Internal P2P Call Flow

Base URL:

```text
https://page.law.indias.cloud/api/v1
```

Auth header:

```text
X-Master-Key: SET_IN_POSTMAN
```

or:

```text
Authorization: Bearer SET_IN_POSTMAN
```

## Internal P2P Call Flow

P2P calling is wrapped inside the Lawneu app flow and is not published as a direct public API surface in zlawpanel docs or the Postman collection.

Current behavior:

```text
Lawneu app -> Lawneu backend -> internal call/session handling -> private P2P room link
```

Implementation notes:

- The app should not call the P2P server directly for business state.
- The app should not expose raw room-management endpoints in public API docs.
- Payment, time limit, start/end state, and room lifecycle stay controlled by the Lawneu app/backend flow.
- The P2P server host is an implementation detail and can be changed later without changing public app docs.

### Call Mode Setting

Set this from:

```text
zlawpanel -> Settings -> Default P2P Call Mode
```

Supported values:

```text
auto
audio
video
```

The internal app flow can override this with `callMode` when creating a call. Public Postman docs do not expose direct call-room requests.

## Open WebUI AI Provider

AI draft generation is wrapped by Lawneu API. The app calls Lawneu; Lawneu calls Open WebUI server-side when enabled.

Configure from:

```text
zlawpanel -> Settings
```

Settings:

| Setting | Purpose |
| --- | --- |
| `openwebui_api_enabled` | Enables Open WebUI provider for AI drafts. |
| `openwebui_base_url` | Open WebUI base URL. |
| `openwebui_api_key` | Open WebUI API key, stored server-side only. |
| `openwebui_model` | Model id to use, for example `llama3.1`. |
| `openwebui_system_prompt` | Optional system prompt for legal drafting style. |

Lawneu uses Open WebUI's OpenAI-compatible endpoint:

```text
POST /api/chat/completions
```

Open WebUI documents this endpoint as an OpenAI-compatible chat completion API using `Authorization: Bearer YOUR_API_KEY`.

## AI Draft

The app requests AI drafts through Lawneu API. If Open WebUI is disabled or unavailable, Lawneu falls back to a built-in template draft.

```bash
curl -X POST "https://page.law.indias.cloud/api/v1/ai/generate-draft" \
  -H "X-Master-Key: SET_IN_POSTMAN" \
  -H "Content-Type: application/json" \
  -d '{"draftType":"LEGAL_NOTICE","statePartiesDetail":"Client vs opposite party facts","specificClausesOverride":"Add payment demand clause","countryCode":"IN","countryName":"India"}'
```

Example response:

```json
{
  "generatedCode": "DRAFT-1",
  "mdLegalContent": "Draft content...",
  "calculatedReviewCharge": 0,
  "serverModelSign": "open-webui:llama3.1",
  "providerWarning": "",
  "countryCode": "IN",
  "countryName": "India",
  "generatedAt": "2026-06-19T10:00:00Z"
}
```

## App Notes

- Login stays Firebase-side; API access uses the project master key.
- P2P calls are app-wrapped and not documented as direct external endpoints.
- AI draft generation uses Open WebUI when enabled, otherwise returns a stored template draft.
- The Open WebUI API key is never exposed in Postman or client responses.
