SDKs & examples
從 OpenAPI 產生客戶端
第一版支援任何能送出 HTTP + JSON 的語言。官方 SDK 套件尚未公開;在此之前,使用公開 OpenAPI 產生型別客戶端,或採用簡單的 HTTP wrapper。
下載公開契約
curl --fail http://localhost:8000/v1/openapi.json --output sentinel-openapi.json
# Example generator; pin the generator version in production.
npx @openapitools/openapi-generator-cli generate -i sentinel-openapi.json -g typescript-fetch -o generated/sentinelPython
import os
import requests
class Sentinel:
def __init__(self, base_url: str, api_key: str):
self.base_url = base_url.rstrip("/")
self.session = requests.Session()
self.session.headers["Authorization"] = f"Bearer {api_key}"
def events(self, **params):
response = self.session.get(f"{self.base_url}/v1/events", params=params)
response.raise_for_status()
return response.json()
client = Sentinel("http://localhost:8000", os.environ["SENTINEL_API_KEY"])
print(client.events(limit=10))JavaScript
export function sentinel(baseUrl, apiKey) {
return async function request(path, init = {}) {
const response = await fetch(new URL(path, baseUrl), {
...init,
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
...init.headers,
},
});
if (!response.ok) throw await response.json();
return response.headers.get("content-type")?.includes("json")
? response.json()
: response;
};
}PowerShell
Source Kit 內含不依賴 Python 的 System.Net.Http 範例;它會走完 Source → Monitor → JPEG → Event,並驗證下載證據的 SHA-256。
Set-Location "$HOME\Sentinel-Monitor\deploy\api"
& ..\..\docs\api\examples\first_event.ps1 -BaseUrl "http://127.0.0.1:8000" -ApiKey $env:SENTINEL_API_KEY重試規則
只自動重試安全讀取、使用同一 Idempotency-Key 的可重試 mutation,以及 408/425/429/暫時性 5xx。409 只有在 error code 標為暫時衝突時重試。使用 exponential backoff、jitter 並遵守 Retry-After;不要記錄含 key 或 RTSP URL 的完整 request。
文件中的程式碼以目前 /v1 OpenAPI 為準;正式整合請在 CI 中下載 schema、比較 breaking diff 並鎖定已驗證的 Runtime 版本。