# LL Repo API (repo.ll.kg) — reference for AI agents and scripts

Base URL: `https://repo.ll.kg`. Human-readable version: `https://repo.ll.kg/docs`.
App repository for iOS `.ipa` and Android `.apk` files with versions. Compatible with
SideStore / AltStore sources (format v2 + legacy v1 fields).

## Concepts
- App identity: `(platform, bundleId)`. `platform` is `ios` or `android`. `bundleId` = iOS `CFBundleIdentifier` / Android `package`.
- Version identity: `(platform, bundleId, version, build)`.
  - iOS: `version` = `CFBundleShortVersionString`, `build` = `CFBundleVersion`.
  - Android: `version` = `versionName`, `build` = `versionCode`.
- Metadata is extracted from the uploaded file automatically: bundleId, version, build, name, minOS, icon, entitlements (iOS code signature), privacy usage descriptions (iOS `NS*UsageDescription`). Any of them can be overridden by upload parameters.
- Uploading an existing `(version, build)` returns 409 unless `replace=1`/`true`.
- Version order: newest upload first.
- Hidden apps (`hidden: true`) are excluded from public lists and from the source.

## Authentication
Header `Authorization: Bearer <key>` or `X-API-Key: <key>`. Public read endpoints need no key.
An invalid key returns 401 even on public endpoints.

Key scopes:
- `upload`: upload/edit/delete apps whose bundleId starts with the key's `bundlePrefix` (empty prefix = any bundleId). Cannot hide apps or manage keys.
- `admin`: everything, including keys and hidden apps.

Keys look like `rk_...`. Only the SHA-256 is stored; the key is returned once at creation.

## Errors
JSON `{"error": "<message>"}` with status 400 (bad input), 401 (no/invalid key), 403 (scope or bundle prefix), 404, 409 (version exists), 500.

## Public endpoints

### GET /source.json
SideStore/AltStore source. Aliases: `/apps.json`, `/altstore.json`. iOS apps only, non-hidden, apps with at least one version.
Add to SideStore: `sidestore://source?url=https://repo.ll.kg/source.json` (AltStore: `altstore://source?url=...`).
Shape:
```json
{
  "name": "LL Repo", "identifier": "kg.ll.repo", "subtitle": "...", "description": "...",
  "iconURL": "https://repo.ll.kg/icon.png", "website": "https://repo.ll.kg", "tintColor": "#3b82f6",
  "featuredApps": [], "news": [],
  "apps": [{
    "name": "App", "bundleIdentifier": "kg.ll.app", "developerName": "...", "subtitle": "...",
    "localizedDescription": "...", "iconURL": "...", "tintColor": "#3b82f6", "category": "other",
    "screenshots": [], "screenshotURLs": [],
    "versions": [{"version": "1.2.3", "buildVersion": "45", "date": "2026-11-28T10:00:00.000Z",
      "localizedDescription": "changelog", "downloadURL": "https://repo.ll.kg/dl/<id>/<file>.ipa",
      "size": 1050386, "sha256": "<hex>", "minOSVersion": "15.0"}],
    "appPermissions": {"entitlements": ["com.apple.security.application-groups"], "privacy": {"NSCameraUsageDescription": "..."}},
    "version": "1.2.3", "versionDate": "...", "versionDescription": "...", "downloadURL": "...", "size": 1050386
  }]
}
```

### GET /api/apps
Query: `q` (substring of name, bundleId, developer, subtitle; optional), `platform` (`ios`|`android`, optional). Admin keys also see hidden apps. Max 500 results.
Response: `{"apps": [App & {"versionCount": number, "latest": {"id","version","build","size","date","downloadURL"} | null}]}`

`App` object:
```json
{"platform": "ios", "bundleId": "kg.ll.app", "name": "App", "developer": "", "subtitle": "", "description": "",
 "category": "other", "tint": "", "website": "", "iconURL": "https://repo.ll.kg/icons/ios/kg.ll.app?v=...",
 "screenshots": [], "hidden": false, "createdAt": "ISO-8601", "updatedAt": "ISO-8601"}
```

### GET /api/apps/{platform}/{bundleId}
Response: `{"app": App, "permissions": {"entitlements": [...], "privacy": {...}} | null, "versions": [Version]}`
`Version`: `{"id","version","build","minOS","changelog","size","sha256","fileName","downloadURL","date","uploadedBy"}`

### GET /dl/{versionId}/{fileName}
Downloads the file. Supports `Range` (206) and `If-None-Match`. Use `downloadURL` from responses rather than building it.

### GET /icons/{platform}/{bundleId}
App icon (PNG/JPEG/WebP), or an SVG letter placeholder if none.

## Authenticated endpoints

### GET /api/me
Response: `{"id","name","scope":"upload"|"admin","bundlePrefix"}`. Use to validate a key.

### PUT /api/upload — single-request upload (file ≤ ~95 MB)
Body: raw file bytes (not multipart/form-data), `Content-Length` required.
Query: `filename` (required, must end with `.ipa` or `.apk`) plus optional overrides:
`bundleId, version, build, name, changelog, minOS, developer, subtitle, description, category, tint, website, replace`.
Response 201: `{"app": App, "version": Version, "replaced": bool, "detected": {...extracted metadata...}}`
```sh
curl -X PUT "https://repo.ll.kg/api/upload?filename=App.ipa&changelog=Fixes" \
  -H "Authorization: Bearer $REPO_KEY" --data-binary @App.ipa
```

### Multipart upload — any size (use for files > 95 MB, or always)
1. `POST /api/uploads` JSON `{"filename": "App.ipa"}` → 201 `{"id": "<uploadId>", "partSize": 52428800}`
2. For n = 1..N: `PUT /api/uploads/{id}/parts/{n}` raw bytes of part n (each part exactly `partSize` bytes except the last) → `{"partNumber": n, "etag": "..."}`
3. `POST /api/uploads/{id}/complete` JSON `{"parts": [{"partNumber":1,"etag":"..."}, ...], "sha256": "<optional hex of whole file>", ...overrides}` → same response as single upload. Overrides are JSON fields (same names as above; `replace` may be boolean).
- Abort: `DELETE /api/uploads/{id}`. An upload can only be continued by the key that started it.
- Ready-made script (POSIX sh + curl): https://repo.ll.kg/upload.sh
```sh
curl -fsSO https://repo.ll.kg/upload.sh
REPO_KEY=rk_... sh upload.sh build/App.ipa "Changelog text" '"replace":true,"developer":"LL"'
```

### PATCH /api/apps/{platform}/{bundleId}
JSON, any subset: `name, developer, subtitle, description, category, tint, website` (strings), `screenshots` (array of http(s) URLs), `hidden` (bool, admin only).
`category` ∈ `developer, entertainment, games, lifestyle, other, photo-video, social, utilities`.
Response: `{"app": App}`

### PUT /api/apps/{platform}/{bundleId}/icon
Raw image body, `Content-Type: image/png | image/jpeg | image/webp`, max 5 MB. Response: `{"app": App}`

### DELETE /api/apps/{platform}/{bundleId}
Deletes the app, all versions and files. Response `{"ok": true, "deletedFiles": n}`

### PATCH /api/versions/{versionId}
JSON `{"changelog"?: string, "minOS"?: string}` → `{"version": Version}`

### DELETE /api/versions/{versionId}
Deletes one version and its file → `{"ok": true}`

## Admin endpoints (scope admin)
- `GET /api/keys` → `{"keys": [{"id","name","prefix","scope","bundle_prefix","created_at","last_used_at","revoked_at"}]}` (unix seconds)
- `POST /api/keys` JSON `{"name": "ci-app", "scope": "upload"|"admin", "bundlePrefix": "kg.ll."}` → 201 `{"id","name","scope","bundlePrefix","key"}` (`key` shown once)
- `DELETE /api/keys/{id}` → revoke

## Typical agent workflows
- Publish a new build: `PUT /api/upload?filename=...&changelog=...` (or multipart); on 409 decide whether to bump version or pass `replace=1`.
- Find the latest download of an app: `GET /api/apps?q=<name>` → `apps[i].latest.downloadURL`.
- Check what's installed via SideStore: read `/source.json`.
