SDK & API Documentation

Integrate file protection into your application

Quick Start

Install SDK
npm install @dgr/sdk # Or use the REST API directly with any HTTP client curl https://api.dgr.dev/api/files/upload
example.js — Upload and protect a file
import { DGR } from '@dgr/sdk'; const dgr = new DGR({ apiKey: process.env.DGR_API_KEY, apiUrl: 'https://api.dgr.dev' }); // Upload and protect a file const file = await dgr.protect({ file: fileBuffer, fileName: 'model.safetensors', maxCopies: 50, decayRate: 20, watermarkText: 'CONFIDENTIAL' }); // Get shareable link const shareUrl = dgr.getShareLink(file.shareToken); console.log('Share: ${shareUrl}'); // Download as owner (always returns original) const original = await dgr.download(file.id);

Authentication

DGR uses API keys for authentication. Get your API key from the dashboard after creating an account.

Authentication header
Authorization: Bearer YOUR_API_KEY

Node.js SDK

SDK initialization
import { DGR } from '@dgr/sdk'; const dgr = new DGR({ apiKey: 'dgr_sk_...', apiUrl: 'https://api.dgr.dev' // optional, defaults to production });

Methods

dgr.protect(options)

Upload and protect a file

fileBuffer | ReadStream

File content to upload

fileNamestring

Original file name with extension

maxCopiesnumber

Maximum allowed unauthorized downloads

decayRatenumber (1-100)

Percentage degradation per unauthorized copy

watermarkTextstring (optional)

Text to embed in degraded copies

dgr.download(fileId)

Download file as owner (returns original)

fileIdstring

File ID returned from protect()

dgr.getShareLink(shareToken)

Generate public download URL

dgr.list()

List all protected files for authenticated user

dgr.delete(fileId)

Permanently delete a file and all copies

REST API

POST /api/files/upload

Upload and protect a file

Request

POST /api/files/upload Authorization: Bearer YOUR_API_KEY Content-Type: multipart/form-data file: [binary] maxCopies: 50 decayRate: 20 watermarkText: "CONFIDENTIAL"

Response

{ "file": { "id": "dgr_abc123xyz", "fileName": "model.safetensors", "fileSize": 2400000000, "fileType": "model", "shareToken": "share_xyz789", "maxCopies": 50, "decayRate": 20, "copiesMade": 0, "createdAt": "2026-02-16T12:00:00Z" } }
GET /api/files/download/:fileId

Download file as owner (authenticated)

Request

GET /api/files/download/dgr_abc123xyz Authorization: Bearer YOUR_API_KEY

Response Headers

X-DGR-Is-Original: true X-DGR-Decay-Level: 0 X-DGR-Copy-Number: 0 Content-Type: application/octet-stream Content-Disposition: attachment; filename="model.safetensors"
GET /api/files/share/:shareToken

Public download link (degraded for non-owners)

Request

GET /api/files/share/share_xyz789 # No authorization required

Response Headers

X-DGR-Is-Original: false X-DGR-Decay-Level: 25 X-DGR-Copy-Number: 3 Content-Type: application/octet-stream
GET /api/files

List all files for authenticated user

{ "files": [ { "id": "dgr_abc123", "fileName": "model.safetensors", "fileSize": 2400000000, "copiesMade": 3, "maxCopies": 50, "shareToken": "share_xyz789" } ] }
DELETE /api/files/:fileId

Permanently delete file and all copies

DELETE /api/files/dgr_abc123 Authorization: Bearer YOUR_API_KEY # Response: 204 No Content