curl --request POST \
--url https://secureai.hiperai.ai/api/external/speech/s2s/webrtc \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sdp": "v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n...",
"model": "gpt-4o-mini-realtime-preview",
"voice": "alloy",
"smltp_policy": "internal",
"output_audio": true,
"user_id": "60a7c8f5e8b4f5001f7a8c23",
"instructions": "You are a helpful customer service agent."
}
'import requests
url = "https://secureai.hiperai.ai/api/external/speech/s2s/webrtc"
payload = {
"sdp": "v=0
o=- 4611731400430051336 2 IN IP4 127.0.0.1
s=-
t=0 0
...",
"model": "gpt-4o-mini-realtime-preview",
"voice": "alloy",
"smltp_policy": "internal",
"output_audio": True,
"user_id": "60a7c8f5e8b4f5001f7a8c23",
"instructions": "You are a helpful customer service agent."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sdp: 'v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n...',
model: 'gpt-4o-mini-realtime-preview',
voice: 'alloy',
smltp_policy: 'internal',
output_audio: true,
user_id: '60a7c8f5e8b4f5001f7a8c23',
instructions: 'You are a helpful customer service agent.'
})
};
fetch('https://secureai.hiperai.ai/api/external/speech/s2s/webrtc', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));"v=0\r\no=- 1234567890 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n..."Initiieren Sie eine Speech-to-Speech-WebRTC-Sitzung
Establishes a WebRTC connection for real-time speech-to-speech conversations using OpenAI Realtime API. This endpoint accepts a WebRTC SDP offer and returns an SDP answer that can be used to establish a peer connection with OpenAI’s Realtime API.
Usage Flow:
- Client creates a WebRTC offer (RTCPeerConnection.createOffer)
- Client sends the SDP offer to this endpoint
- This endpoint proxies the offer to OpenAI Realtime API
- Client receives SDP answer and establishes WebRTC connection
- Client can then have real-time voice conversations with the AI
S2S Time Tracking:
- Each user has a monthly S2S time quota based on their license
- Time is tracked in minutes and deducted when sessions are logged
- Use
/speech/s2s/statusto check remaining time - Use
/speech/s2s/log-sessionto log session duration and deduct time
SMLTP Integration:
- All requests are processed through SMLTP for security and compliance
- Model validation is enforced based on the specified SMLTP policy
- Requests are audited and logged for compliance tracking
curl --request POST \
--url https://secureai.hiperai.ai/api/external/speech/s2s/webrtc \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"sdp": "v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n...",
"model": "gpt-4o-mini-realtime-preview",
"voice": "alloy",
"smltp_policy": "internal",
"output_audio": true,
"user_id": "60a7c8f5e8b4f5001f7a8c23",
"instructions": "You are a helpful customer service agent."
}
'import requests
url = "https://secureai.hiperai.ai/api/external/speech/s2s/webrtc"
payload = {
"sdp": "v=0
o=- 4611731400430051336 2 IN IP4 127.0.0.1
s=-
t=0 0
...",
"model": "gpt-4o-mini-realtime-preview",
"voice": "alloy",
"smltp_policy": "internal",
"output_audio": True,
"user_id": "60a7c8f5e8b4f5001f7a8c23",
"instructions": "You are a helpful customer service agent."
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
sdp: 'v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n...',
model: 'gpt-4o-mini-realtime-preview',
voice: 'alloy',
smltp_policy: 'internal',
output_audio: true,
user_id: '60a7c8f5e8b4f5001f7a8c23',
instructions: 'You are a helpful customer service agent.'
})
};
fetch('https://secureai.hiperai.ai/api/external/speech/s2s/webrtc', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));"v=0\r\no=- 1234567890 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n..."Speech-to-Speech-WebRTC-Sitzung starten
Stellen Sie mithilfe der OpenAI Realtime API eine WebRTC-Verbindung für Echtzeit-Sprachgespräche her.Endpunkt
POST /speech/s2s/webrtc
Beschreibung
Stellt mithilfe der OpenAI Realtime API eine WebRTC-Verbindung für Echtzeit-Sprachgespräche her. Dieser Endpunkt akzeptiert ein WebRTC-SDP-Angebot und gibt eine SDP-Antwort zurück, die zum Herstellen einer Peer-Verbindung mit der Echtzeit-API von OpenAI verwendet werden kann.Nutzungsablauf
- Der Client erstellt ein WebRTC-Angebot (RTCPeerConnection.createOffer).
- Der Client sendet das SDP-Angebot an diesen Endpunkt
- Dieser Endpunkt leitet das Angebot an die OpenAI Realtime API weiter
- Der Client empfängt die SDP-Antwort und stellt eine WebRTC-Verbindung her
- Der Kunde kann dann in Echtzeit Sprachgespräche mit der KI führen
S2S-Zeiterfassung
- Jeder Benutzer verfügt über ein monatliches S2S-Zeitkontingent basierend auf seiner Lizenz
- Die Zeit wird in Minuten erfasst und bei der Protokollierung von Sitzungen abgezogen
- Verwenden Sie
/speech/s2s/status, um die verbleibende Zeit zu überprüfen - Verwenden Sie
/speech/s2s/log-session, um die Sitzungsdauer zu protokollieren und Zeit abzuziehen
SMLTP-Integration
- Alle Anfragen werden aus Sicherheits- und Compliance-Gründen über SMLTP verarbeitet – Die Modellvalidierung wird basierend auf der angegebenen SMLTP-Richtlinie erzwungen
- Anfragen werden zur Compliance-Nachverfolgung geprüft und protokolliert
Authentifizierung
Erforderlich: API-SchlüsselAuthorization: Bearer sk-your-api-key-here
Anforderungstext
| Parameter | Geben Sie | ein Erforderlich | Beschreibung | |
|---|---|---|---|---|
sdp | Zeichenfolge | Ja | WebRTC SDP-Angebot aus der RTCPeerConnection | des Clients |
model | Zeichenfolge | Nein | OpenAI-Echtzeitmodell (Standard: „gpt-4o-mini-realtime-preview“) | |
voice | Zeichenfolge | Nein | Für die KI-Antwort zu verwendende Stimme (Standard: „Legierung“) | |
smltp_policy | Zeichenfolge | Nein | SMLTP-Richtlinie (Standard: „intern“) | |
output_audio | boolescher Wert | Nein | Ob die Audioausgabe aktiviert werden soll (Standard: true) | |
user_id | Zeichenfolge | Nein | Benutzer-ID, der diese Sitzung in Rechnung gestellt werden soll (standardmäßig API-Schlüsselbesitzer) | |
instructions | Zeichenfolge | Nein | Optionale Systemanweisungen für den KI-Assistenten |
Verfügbare Modelle
gpt-4o-mini-realtime-previewgpt-4o-realtime-preview
Verfügbare Stimmen
alloy(Standard)echofableonyxnovashimmerashballadcoral
Verfügbare SMLTP-Richtlinien
publicinternal(Standard)internal-strictconfidentialhipaagdprpci-dss
Beispiel für Anfrage
curl -X POST "https://{customer.name}.hiperai.ai/api/external/speech/s2s/webrtc" \
-H "Authorization: Bearer sk-your-api-key-here" \
-H "Content-Type: application/json" \
-d '{
"sdp": "v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n...",
"model": "gpt-4o-mini-realtime-preview",
"voice": "alloy",
"smltp_policy": "internal",
"output_audio": true,
"instructions": "You are a helpful customer service agent."
}'
JavaScript/Node.js
// Create WebRTC peer connection
const pc = new RTCPeerConnection();
// Create offer
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);
// Send SDP offer to SecureAI
const response = await fetch('https://{customer.name}.hiperai.ai/api/external/speech/s2s/webrtc', {
method: 'POST',
headers: {
'Authorization': 'Bearer sk-your-api-key-here',
'Content-Type': 'application/json'
},
body: JSON.stringify({
sdp: offer.sdp,
model: 'gpt-4o-mini-realtime-preview',
voice: 'alloy',
smltp_policy: 'internal',
output_audio: true,
instructions: 'You are a helpful customer service agent.'
})
});
// Get SDP answer
const sdpAnswer = await response.text();
// Set remote description
await pc.setRemoteDescription(new RTCSessionDescription({
type: 'answer',
sdp: sdpAnswer
}));
// Now you can have real-time voice conversations
Python
import requests
url = "https://{customer.name}.hiperai.ai/api/external/speech/s2s/webrtc"
headers = {
"Authorization": "Bearer sk-your-api-key-here",
"Content-Type": "application/json"
}
data = {
"sdp": "v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n...",
"model": "gpt-4o-mini-realtime-preview",
"voice": "alloy",
"smltp_policy": "internal",
"output_audio": True,
"instructions": "You are a helpful customer service agent."
}
response = requests.post(url, headers=headers, json=data)
sdp_answer = response.text
print('SDP Answer:', sdp_answer)
Antwort
Erfolgsantwort (200)
Inhaltstyp:application/sdp
Die Antwort ist eine SDP-Antwortzeichenfolge, die mit RTCPeerConnection.setRemoteDescription() verwendet werden kann.
v=0
o=- 1234567890 2 IN IP4 127.0.0.1
s=-
t=0 0
...
Fehlerantworten
400 Ungültige Anfrage
{
"success": false,
"error": "Invalid SDP offer",
"message": "SDP offer is required and must be a string",
"request_id": "96bba6a4-0e7a-4fd7-93a7-3b40428729fb"
}
403 Verboten
S2S-Zeitlimit erreicht
{
"success": false,
"error": "S2S time limit reached",
"message": "Insufficient S2S time remaining for this user",
"remaining_minutes": 0,
"next_renewal_date": "2024-12-01T12:55:35.721Z",
"request_id": "96bba6a4-0e7a-4fd7-93a7-3b40428729fb"
}
Modellvalidierung fehlgeschlagen
{
"success": false,
"error": "Model validation failed",
"message": "Model gpt-4o-mini-realtime-preview is not allowed by SMLTP policy test-policy-active",
"request_id": "96bba6a4-0e7a-4fd7-93a7-3b40428729fb"
}
500 Interner Serverfehler
{
"success": false,
"error": "S2S WebRTC failed",
"message": "An error occurred while processing your request",
"request_id": "96bba6a4-0e7a-4fd7-93a7-3b40428729fb"
}
Notizen
– Das SDP-Angebot muss eine gültige WebRTC-SDP-Angebotszeichenfolge sein- Nachdem Sie die SDP-Antwort erhalten haben, verwenden Sie diese, um die Remote-Beschreibung auf Ihrer RTCPeerConnection festzulegen
- Überprüfen Sie den S2S-Zeitstatus, bevor Sie Sitzungen mit
/speech/s2s/statusstarten. - Protokollieren Sie die Sitzungsdauer nach Abschluss mit
/speech/s2s/log-session - Alle Anfragen werden aus Sicherheits- und Compliance-Gründen über SMLTP verarbeitet
- Der Parameter
user_idermöglicht die Abrechnung über ein anderes Benutzerkonto
Autorisierungen
API key authentication using Bearer token format.
Example: Authorization: Bearer sk-your-api-key-here
Body
WebRTC SDP offer from the client's RTCPeerConnection
"v=0\r\no=- 4611731400430051336 2 IN IP4 127.0.0.1\r\ns=-\r\nt=0 0\r\n..."
OpenAI Realtime model to use
gpt-4o-mini-realtime-preview, gpt-4o-realtime-preview Voice to use for the AI response
alloy, echo, fable, onyx, nova, shimmer, ash, ballad, coral SMLTP policy to apply for this session
public, internal, internal-strict, confidential, hipaa, gdpr, pci-dss Whether to enable audio output (default: true)
Optional user ID to bill this session to (defaults to API key owner)
"60a7c8f5e8b4f5001f7a8c23"
Optional system instructions for the AI assistant
"You are a helpful customer service agent."
Antwort
SDP answer from OpenAI Realtime API
SDP answer that can be used with RTCPeerConnection.setRemoteDescription()

