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
Required for custom browser clients. Trusted 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 an 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.
Only an active server API key for the exact authenticated project can mint. Browser session/publishable tokens cannot delegate or renew tokens. A positive per-key monthly spending cap returns HTTP 403 key_budget_delegation_unsupported: child tokens do not share the parent’s spend counter. Do not remove a spending cap to bypass this error; retain the bounded server-side workflow or establish an approved application-level budget. Token expiry limits admission, not the duration or spend of an established session. Token responses are not cacheable.
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
Body
Response
Minted session token