Server SDK (Python) — receive reports and integrate with your server
Your backend does two things: receive report callbacks (verify the signature, store the report) and, optionally, fetch results with your server key.
01 Install
The Python SDK isn't on a public package index yet, so there is nothing to pip install. The signature check on this page uses only the Python standard library; the web framework code that receives the request is only a sketch.
02 Without the client SDK: upload and submit from your backend
When you can't use the client SDK — a video already on your server, a mini program, another language — your backend uploads and submits with your server key: ① call POST /v1/upload/presign with {"filename": "…", "content_type": "…"} (filename is required); it returns upload_id, put_url and more; ② PUT the video file to put_url as is, without changing its query string; ③ call POST /v1/analyze/full/submit (it needs analyze:write) with the upload_id from step ①, or a publicly reachable video_url, in input; client_ref, callback_url and consent are optional. Send the complete original video, not segments. It returns task_id and status: "pending"; then wait for the webhook or query GET /v1/analyze/status/{task_id}. Both reports are in the result.
import json, time, urllib.request API_BASE = "https://open.hslingxin.com" # production gateway base URL API_KEY = "sk_YOUR_KEY" # your server key def call(method, path, body=None): request = urllib.request.Request( API_BASE + path, data=None if body is None else json.dumps(body).encode(), headers={"X-API-Key": API_KEY, "Content-Type": "application/json"}, method=method, ) with urllib.request.urlopen(request) as response: # raises on a non-2xx status return json.load(response) # 1. ask for an upload address (filename is required) upload = call("POST", "/v1/upload/presign", {"filename": "session.mp4", "content_type": "video/mp4"}) # 2. PUT the video file to put_url as is; don't change its query string with open("session.mp4", "rb") as f: put = urllib.request.Request(upload["put_url"], data=f.read(), method="PUT", headers={"Content-Type": "video/mp4"}) urllib.request.urlopen(put) # 3. submit the uploaded video; the complete original video, not segments task = call("POST", "/v1/analyze/full/submit", {"input": {"upload_id": upload["upload_id"]}, "client_ref": "user_20394"}) # task = {"task_id": ..., "status": "pending"}; wait for the webhook, or read the status status = call("GET", f"/v1/analyze/status/{task['task_id']}")
03 Receive a report callback
The platform POSTs the report to your webhook. Verify the signature, then store it. The signing secret is whsec_… from the console — not your sk_.
# ② Backend webhook receiver (verify with whsec_ → dedupe → correlate → store · sk_ for fallback fetch) import hmac, hashlib, time def verify(sig, ts, body, secret): # body = raw request bytes if abs(time.time() - int(ts)) > 300: # reject stale deliveries (>5 min) — replay protection raise ValueError("stale timestamp") msg = f"{ts}.".encode() + body # timestamp + "." + raw body expected = "sha256=" + hmac.new(secret.encode(), msg, hashlib.sha256).hexdigest() if not hmac.compare_digest(expected, sig): raise ValueError("bad signature") @app.post("/hooks/lynxin") def on_report(request): verify(request.headers["X-Lynxin-Signature"], request.headers["X-Lynxin-Timestamp"], request.raw_body, WEBHOOK_SECRET) # whsec_ webhook signing secret delivery_id = request.headers["X-Lynxin-Delivery"] if already_handled(delivery_id): # a delivery can arrive more than once — dedupe by delivery ID return event = request.json if event["event"] == "analysis.completed": user_id = event["client_ref"] # correlate to your user reports = event["result"] # result.model1 = signal report · result.model2 = personality report save_report(user_id, reports) # store permanently mark_handled(delivery_id) # fallback: within 30 days, fetch with sk_ via GET /v1/results?client_ref=user_20394
Lynxin Affect report. If you only use Lynxin Affect, read the full report with your server key from GET /v1/rdp/{session_id}/report (it needs the report:read permission, which server keys have by default). The session_id comes from the upload and from the ingest.completed event.
import json, time, urllib.request API_BASE = "https://open.hslingxin.com" # production gateway base URL API_KEY = "sk_YOUR_KEY" # your server key def call(method, path, body=None): request = urllib.request.Request( API_BASE + path, data=None if body is None else json.dumps(body).encode(), headers={"X-API-Key": API_KEY, "Content-Type": "application/json"}, method=method, ) with urllib.request.urlopen(request) as response: # raises on a non-2xx status return json.load(response) # session_id comes from the upload response and from the ingest.completed event report = call("GET", f"/v1/rdp/{session_id}/report")
04 Optional: transcripts, speech emotion and Pro video curves
With uploadAndSubmit() only, the Lynxin Affect report doesn't include audio analysis or Pro video curves by default; ingestAndAnalyze() adds them automatically, so you don't need the endpoints below. When you need them, your backend runs extraction with your server key: transcripts and speech emotion with POST /v1/rdp/{session_id}/audio or the asynchronous POST /v1/jobs/audio-extract; Pro video curves with POST /v1/rdp/{session_id}/pro (engine is standard or high) or the asynchronous POST /v1/jobs/pro-extract. Track asynchronous jobs with GET /v1/jobs/{job_id}. Once extraction succeeds, read the report again from GET /v1/rdp/{session_id}/report; the results are in the same report. Extraction is billed in credits: the actual length of the audio or video is converted to tokens, then to credits. Asynchronous Pro video extraction reserves credits up front and returns 402 if your balance isn't enough.
import json, time, urllib.request API_BASE = "https://open.hslingxin.com" # production gateway base URL API_KEY = "sk_YOUR_KEY" # your server key def call(method, path, body=None): request = urllib.request.Request( API_BASE + path, data=None if body is None else json.dumps(body).encode(), headers={"X-API-Key": API_KEY, "Content-Type": "application/json"}, method=method, ) with urllib.request.urlopen(request) as response: # raises on a non-2xx status return json.load(response) # synchronous: extract the audio of this session call("POST", f"/v1/rdp/{session_id}/audio") # asynchronous: submit a job linked to the session, then check it until it ends # video_ref comes from the upload response, returned with session_id job = call("POST", "/v1/jobs/audio-extract", {"video_ref": video_ref, "session_id": session_id}) while True: state = call("GET", f"/v1/jobs/{job['job_id']}") if state["status"] in ("success", "failed"): # pending | running | success | failed break time.sleep(5) # read the report again; the transcript is in the same report report = call("GET", f"/v1/rdp/{session_id}/report")
05 If a delivery is missed
The webhook is the primary — and usually the only — path you need. If a delivery fails all retries, resend it from the console (Webhook deliveries log). For the full retry schedule and recovery options, see Webhooks → Retries & fallback.