adventurous-potato-31716
12/03/2025, 12:43 AMtall-airline-16756
12/03/2025, 12:43 AMtall-airline-16756
12/03/2025, 12:44 AMsip.admin grant (set "sip":{"admin":true} in the claims) and is signed with your LiveKit API secret (HMAC-SHA256).
• From PHP, generate the JWT (use a library like firebase/php-jwt) and send a JSON POST via cURL with Authorization: Bearer <token>.
I can provide a ready-to-use PHP example. Before I do, please confirm:
1. Do you want an example for an inbound trunk, an outbound trunk, or both?
2. Do you already have an API key/secret and a preferred JWT library (e.g., firebase/php-jwt) available in your project?
3. Any required fields for the trunk (example: phone numbers in E.164, krispEnabled, SIP URI, auth credentials) or should I use a minimal example?
Tell me the answers and I'll return a concise PHP script you can copy/paste.
Sources: LiveKit SDKs Overview | LiveKit Docsadventurous-potato-31716
12/03/2025, 12:45 AMadventurous-potato-31716
12/03/2025, 12:45 AMtall-airline-16756
12/03/2025, 12:45 AMsip.admin grant using firebase/php-jwt
• Calls LiveKit's CreateSIPInboundTrunk Twirp endpoint with cURL
Replace the placeholders before running.
<?php
require 'vendor/autoload.php';
use Firebase\JWT\JWT;
// --- CONFIG: fill these ---
$livekitDomain = 'your-subdomain.livekit.cloud'; // no trailing slash
$apiKey = 'LK_API_KEY';
$apiSecret = 'LK_API_SECRET';
$jwtSubject = 'php-admin';
$expiresIn = 3600; // seconds
// inbound trunk payload
$inboundTrunk = [
'name' => 'My PHP Inbound Trunk',
'numbers' => ['+15105550100'], // E.164
'krispEnabled' => true
];
// ---------------------------
// 1) Build JWT claims (include sip.admin)
$now = time();
$claims = [
'iss' => $apiKey,
'sub' => $jwtSubject,
'iat' => $now,
'exp' => $now + $expiresIn,
'video' => ['room' => 'any', 'roomJoin' => true],
'sip' => ['admin' => true]
];
// 2) Sign JWT (HS256)
$jwt = JWT::encode($claims, $apiSecret, 'HS256');
// 3) Call Twirp endpoint to create inbound trunk
$url = "https://{$livekitDomain}/twirp/livekit.SIP/CreateSIPInboundTrunk";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $jwt
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($inboundTrunk));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);
curl_close($ch);
// 4) Handle response
if ($response === false) {
echo "cURL error: $err\n";
exit(1);
}
if ($httpCode === 200) {
echo "Inbound trunk created:\n";
print_r(json_decode($response, true));
} else {
echo "Error (HTTP $httpCode):\n";
echo $response . "\n";
}
Notes:
• Install firebase/php-jwt: composer require firebase/php-jwt
• Ensure phone numbers are E.164 formatted.
• Keep your API secret in environment variables, not in source code.
Want a version that includes basic error parsing and retries or one that uses Guzzle instead of cURL?tall-airline-16756
12/03/2025, 12:46 AMsip.admin grant using firebase/php-jwt
• Calls LiveKit’s CreateSIPInboundTrunk Twirp endpoint via cURL
Fill in your domain, API key, and API secret before running.
<?php
require 'vendor/autoload.php';
use Firebase\JWT\JWT;
// --- CONFIG: replace these ---
$livekitDomain = 'your-subdomain.livekit.cloud'; // no trailing slash
$apiKey = 'LK_API_KEY';
$apiSecret = 'LK_API_SECRET';
$jwtSubject = 'php-admin';
$expiresIn = 3600; // seconds
// inbound trunk payload (edit as needed)
$inboundTrunk = [
'name' => 'My PHP Inbound Trunk',
'numbers' => ['+15105550100'], // E.164 format
'krispEnabled' => true
];
// -------------------------------
// Build JWT claims (include sip.admin)
$now = time();
$claims = [
'iss' => $apiKey,
'sub' => $jwtSubject,
'iat' => $now,
'exp' => $now + $expiresIn,
'video' => ['room' => 'any', 'roomJoin' => true],
'sip' => ['admin' => true]
];
// Sign JWT (HS256)
$jwt = JWT::encode($claims, $apiSecret, 'HS256');
// Call Twirp endpoint to create inbound trunk
$url = "https://{$livekitDomain}/twirp/livekit.SIP/CreateSIPInboundTrunk";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $jwt
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($inboundTrunk));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$err = curl_error($ch);
curl_close($ch);
// Handle response
if ($response === false) {
echo "cURL error: $err\n";
exit(1);
}
if ($httpCode === 200) {
echo "Inbound trunk created:\n";
print_r(json_decode($response, true));
} else {
echo "Error (HTTP $httpCode):\n";
echo $response . "\n";
}
Notes:
• Install JWT lib: composer require firebase/php-jwt
• Keep LK_API_SECRET out of source (use env vars).
• Use E.164 phone numbers (e.g., +15105550100).
Would you like:
• a version using Guzzle,
• added error parsing for Twirp error formats, or
• a helper function/class to reuse for multiple trunk calls?