SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.4 KB · 31 lines python
Raw Blame History
1#!/usr/bin/env python32"""STATUS: LIVE_VERIFIED 2026-09-18 — POST /v1/realtime/client_secrets → 200 {value: ek_…, expires_at, session}.34Mint an ephemeral key for a browser/mobile Realtime client. Logged to reports/live-requests.jsonl by scripts/live.py.5Run: .venv/bin/python examples/openai/realtime/client_secrets.py [transcription]6"""7from __future__ import annotations89import json10import sys11import time12from pathlib import Path1314sys.path.insert(0, str(Path(__file__).resolve().parents[3]))15from scripts.live import openai_request  # noqa: E4021617if len(sys.argv) > 1 and sys.argv[1] == "transcription":18    session = {"type": "transcription", "audio": {"input": {"transcription": {"model": "gpt-4o-mini-transcribe"}, "turn_detection": None}}}19else:20    session = {"type": "realtime", "model": "gpt-realtime-mini", "output_modalities": ["text"], "instructions": "Reply with OK."}2122status, body, _ = openai_request("POST", "/v1/realtime/client_secrets",23                                 {"expires_after": {"anchor": "created_at", "seconds": 300}, "session": session},24                                 note="example client_secrets.py")25print("HTTP", status)26if status == 200:27    print("secret prefix:", body["value"][:3] + "***", "| expires in", body["expires_at"] - int(time.time()), "s")28    print("session:", json.dumps({k: body["session"][k] for k in ("type", "id", "object")}))29else:30    print(json.dumps(body, indent=1))31