curl --request POST \
--url https://api.pyai.com/v1/omni/sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"allowed_origins": [
"https://acme.com"
],
"ttl_seconds": 60,
"session_label": "<string>"
}
'import requests
url = "https://api.pyai.com/v1/omni/sessions"
payload = {
"allowed_origins": ["https://acme.com"],
"ttl_seconds": 60,
"session_label": "<string>"
}
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({
allowed_origins: ['https://acme.com'],
ttl_seconds: 60,
session_label: '<string>'
})
};
fetch('https://api.pyai.com/v1/omni/sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pyai.com/v1/omni/sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'allowed_origins' => [
'https://acme.com'
],
'ttl_seconds' => 60,
'session_label' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.pyai.com/v1/omni/sessions"
payload := strings.NewReader("{\n \"allowed_origins\": [\n \"https://acme.com\"\n ],\n \"ttl_seconds\": 60,\n \"session_label\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.pyai.com/v1/omni/sessions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"allowed_origins\": [\n \"https://acme.com\"\n ],\n \"ttl_seconds\": 60,\n \"session_label\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.pyai.com/v1/omni/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"allowed_origins\": [\n \"https://acme.com\"\n ],\n \"ttl_seconds\": 60,\n \"session_label\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"object": "omni.session",
"token": "pyai_live_sess_a1B2…",
"expires_at": 123,
"url": "wss://api.pyai.com/v1/omni?format=pcm16&rate=24000",
"session_label": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "<string>",
"detail": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "invalid_request_error",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "invalid_request_error",
"param": "<string>"
}
}Mint an ephemeral Omni session token
Most integrations do not need this endpoint. Server-side apps, telephony, and backend agents connect to wss /v1/omni directly with their API key (see “Open an Omni voice-agent session”). Use this only when a browser or other untrusted client must open an Omni session without holding your secret key.
It mints a short-lived, origin-locked token the browser can use to open ONE Omni realtime session, the public/private split for realtime. Call this from your server with your secret key (which must hold omni:session); never ship the secret key to a page. The returned token carries only omni:session, is limited to one concurrent session, is locked to the allowed_origins you supply, and expires after ttl_seconds (default 60s, max 600s). Use it as the WebSocket subprotocol pyai-key.<token>, offered after the pyai.v1 marker, against the returned url. See the Omni browser guide for the full flow.
curl --request POST \
--url https://api.pyai.com/v1/omni/sessions \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"allowed_origins": [
"https://acme.com"
],
"ttl_seconds": 60,
"session_label": "<string>"
}
'import requests
url = "https://api.pyai.com/v1/omni/sessions"
payload = {
"allowed_origins": ["https://acme.com"],
"ttl_seconds": 60,
"session_label": "<string>"
}
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({
allowed_origins: ['https://acme.com'],
ttl_seconds: 60,
session_label: '<string>'
})
};
fetch('https://api.pyai.com/v1/omni/sessions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.pyai.com/v1/omni/sessions",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => json_encode([
'allowed_origins' => [
'https://acme.com'
],
'ttl_seconds' => 60,
'session_label' => '<string>'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.pyai.com/v1/omni/sessions"
payload := strings.NewReader("{\n \"allowed_origins\": [\n \"https://acme.com\"\n ],\n \"ttl_seconds\": 60,\n \"session_label\": \"<string>\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.post("https://api.pyai.com/v1/omni/sessions")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"allowed_origins\": [\n \"https://acme.com\"\n ],\n \"ttl_seconds\": 60,\n \"session_label\": \"<string>\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.pyai.com/v1/omni/sessions")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"allowed_origins\": [\n \"https://acme.com\"\n ],\n \"ttl_seconds\": 60,\n \"session_label\": \"<string>\"\n}"
response = http.request(request)
puts response.read_body{
"object": "omni.session",
"token": "pyai_live_sess_a1B2…",
"expires_at": 123,
"url": "wss://api.pyai.com/v1/omni?format=pcm16&rate=24000",
"session_label": "<string>"
}{
"title": "<string>",
"status": 123,
"type": "<string>",
"detail": "<string>",
"request_id": "<string>"
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "invalid_request_error",
"param": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"code": "invalid_request_error",
"param": "<string>"
}
}Authorizations
Use Authorization: Bearer pyai_live_... (or pyai_test_...).
Body
Browser origins (scheme://host[:port]) the token may connect from. Required and non-empty, a browser token must be origin-locked. * is not allowed.
1["https://acme.com"]
Token lifetime in seconds. Keep it short; a leaked token is worth seconds, not minutes.
1 <= x <= 600Optional opaque tag echoed back to your kb_endpoint and recorded on the call.
Response
Minted session token
"omni.session"
The ephemeral session token. Offer it as the WebSocket subprotocol pyai-key.<token> after the pyai.v1 marker. Short-lived and origin-locked; safe to hand to the browser.
"pyai_live_sess_a1B2…"
Token expiry, Unix epoch milliseconds.
The Omni realtime WebSocket URL to connect to.
"wss://api.pyai.com/v1/omni?format=pcm16&rate=24000"
Echoed back when supplied on the request.