mirror of
https://gitlab.com/vyla-entertainment/documentation.git
synced 2026-11-14 22:47:26 -05:00
fixed syntax issues
This commit is contained in:
@@ -4,40 +4,29 @@
|
||||
|
||||
## Overview
|
||||
|
||||
Stream API includes a built-in cryptographic key management and rate-limiting system backed by SQLite. When enabled, client applications must supply an authenticated key to establish Server-Sent Events connections or request proxied media streams.
|
||||
Stream API includes a key management and rate-limiting system backed by SQLite. When enabled, client apps must supply an authenticated key to establish SSE streams or request proxied media.
|
||||
|
||||
---
|
||||
|
||||
## Key Structure & Prefixes
|
||||
## Key Tiers
|
||||
|
||||
API keys are 32-character hexadecimal strings generated with a specific prefix indicating the client tier:
|
||||
|
||||
| Key Prefix | Key Type | Intended Use Case | Default Rate Limit |
|
||||
| :--- | :--- | :--- | :--- |
|
||||
| **`pk_`** | **Partner Key** | Verified high-volume partner frontends and applications | 1,000 req / minute |
|
||||
| **`sk_`** | **Standard Key** | Private self-hosters and internal client instances | 500 req / minute |
|
||||
| **`pub_`** | **Public Key** | Anonymous public trial access or open community frontends | 10 req / minute |
|
||||
- **`pk_` (Partner Key)**: For high-volume frontends. Default: 1,000 req/min.
|
||||
- **`sk_` (Standard Key)**: For private self-hosters and internal client apps. Default: 500 req/min.
|
||||
- **`pub_` (Public Key)**: For public trial access or open community frontends. Default: 10 req/min.
|
||||
|
||||
---
|
||||
|
||||
## Generating API Keys via CLI
|
||||
## Creating Keys
|
||||
|
||||
The Stream API repository includes a CLI tool (`add-key.mjs`) to generate and insert keys into the active SQLite database:
|
||||
Generate keys using the CLI tool in the Stream API directory:
|
||||
|
||||
```bash
|
||||
# Syntax: node add-key.mjs <type> <rate_limit_per_min> <client_name>
|
||||
|
||||
# 1. Create a Standard Key for a personal desktop client:
|
||||
node add-key.mjs standard 500 my-desktop-client
|
||||
|
||||
# 2. Create a Partner Key for a high-traffic community player:
|
||||
node add-key.mjs partner 1000 partner-frontend
|
||||
|
||||
# 3. Create a restricted Public Key:
|
||||
node add-key.mjs public 10 public-guest
|
||||
```
|
||||
|
||||
### CLI Output Example
|
||||
### Output Example
|
||||
```
|
||||
Generated Key: sk_8f14b2d39a7e4c5b10e9f8a7b6c5d4e3
|
||||
Type: standard
|
||||
@@ -45,19 +34,18 @@ Limit: 500 req/min
|
||||
Client: my-desktop-client
|
||||
Status: Active
|
||||
```
|
||||
The key is printed once upon creation. Copy and deliver it to your client application securely.
|
||||
|
||||
---
|
||||
|
||||
## Managing Keys via JSON Database Export
|
||||
## Database Export & Sync
|
||||
|
||||
For automated deployments or bulk key management, you can export the database to a JSON file:
|
||||
For automated deployments, export the database to JSON:
|
||||
|
||||
### 1. Export Database
|
||||
```bash
|
||||
node export-db.mjs
|
||||
```
|
||||
This dumps the active SQLite database tables into `db.json`:
|
||||
|
||||
This dumps active keys to `db.json`:
|
||||
```json
|
||||
{
|
||||
"keys": [
|
||||
@@ -73,41 +61,40 @@ This dumps the active SQLite database tables into `db.json`:
|
||||
}
|
||||
```
|
||||
|
||||
### 2. Modify and Re-Import
|
||||
Edit `db.json` to add, revoke, or modify limits, then commit the changes back to SQLite:
|
||||
To sync edits from `db.json` back into SQLite:
|
||||
```bash
|
||||
node update-db.mjs
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Client Authorization Headers
|
||||
## Client Authorization
|
||||
|
||||
Clients can authenticate requests by passing the key in one of the following locations:
|
||||
Clients can send their key via headers or query parameters:
|
||||
|
||||
### 1. Authorization Header (Recommended)
|
||||
### Authorization Header
|
||||
```http
|
||||
GET /movie?id=155 HTTP/1.1
|
||||
Host: your-api.example.com
|
||||
Host: api.vyla.cc
|
||||
Authorization: Bearer sk_8f14b2d39a7e4c5b10e9f8a7b6c5d4e3
|
||||
```
|
||||
|
||||
### 2. Custom API Key Header
|
||||
### Custom Header
|
||||
```http
|
||||
X-API-Key: sk_8f14b2d39a7e4c5b10e9f8a7b6c5d4e3
|
||||
```
|
||||
|
||||
### 3. Query Parameter (for EventSource & HTML5 Video)
|
||||
Because native browser `EventSource` and `<video>` tags do not support custom request headers, you can pass the key as a query parameter:
|
||||
### Query Parameter
|
||||
Used for browser `EventSource` and native `<video>` elements that do not support custom request headers:
|
||||
```http
|
||||
GET /movie?id=155&key=sk_8f14b2d39a7e4c5b10e9f8a7b6c5d4e3 HTTP/1.1
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Rate Limit Headers
|
||||
## Rate Limit Responses
|
||||
|
||||
When requests are evaluated, Stream API returns standard rate-limiting headers:
|
||||
Responses include standard rate-limiting headers:
|
||||
|
||||
```http
|
||||
HTTP/1.1 200 OK
|
||||
@@ -116,7 +103,7 @@ X-RateLimit-Remaining: 498
|
||||
X-RateLimit-Reset: 1731614460
|
||||
```
|
||||
|
||||
If a client exceeds their tier quota, Stream API responds with HTTP 429:
|
||||
When a quota is exceeded, Stream API returns HTTP `429`:
|
||||
```json
|
||||
{
|
||||
"error": "Rate limit exceeded. Please retry in 32 seconds.",
|
||||
|
||||
Reference in New Issue
Block a user