Attach to a PTY session over WebSocket
curl --request GET \
--url wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws \
--header 'Authorization: Bearer <token>'import requests
url = "wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws', 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 => "wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"error": "<string>",
"code": "<string>"
}{
"error": "<string>",
"code": "<string>"
}PTY Sessions
Attach PTY WebSocket
Upgrade to a WebSocket connection for an interactive PTY session.
GET
/
api
/
v1
/
pty
/
{session_id}
/
ws
Attach to a PTY session over WebSocket
curl --request GET \
--url wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws \
--header 'Authorization: Bearer <token>'import requests
url = "wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws"
headers = {"Authorization": "Bearer <token>"}
response = requests.get(url, headers=headers)
print(response.text)const options = {method: 'GET', headers: {Authorization: 'Bearer <token>'}};
fetch('wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws', 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 => "wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws"
req, _ := http.NewRequest("GET", url, nil)
req.Header.Add("Authorization", "Bearer <token>")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws")
.header("Authorization", "Bearer <token>")
.asString();require 'uri'
require 'net/http'
url = URI("wss://{identifier}.sandbox.tensorlake.ai/api/v1/pty/{session_id}/ws")
http = Net::HTTP.new(url.host, url.port)
request = Net::HTTP::Get.new(url)
request["Authorization"] = 'Bearer <token>'
response = http.request(request)
puts response.read_body{
"error": "<string>",
"code": "<string>"
}{
"error": "<string>",
"code": "<string>"
}Attach to a PTY session over WebSocket.
Use the WebSocket endpoint on the sandbox proxy host:
Query-string token:
Endpoint
GET /api/v1/pty/{session_id}/ws
wss://<sandbox-id-or-name>.sandbox.tensorlake.ai/api/v1/pty/<session-id>/ws
Authentication
You must provide the PTY token returned from Create PTY Session. Tensorlake accepts the token in either place:- Preferred:
X-PTY-Token: <token> - Backward-compatible fallback:
?token=<token>
WebSocket Protocol
After connecting, send a binaryREADY frame immediately so Tensorlake can flush any buffered output.
For an end-to-end example that creates the session, sends READY, runs a command, reads output, and closes cleanly, see PTY Sessions.
Client-to-server opcodes
| Opcode | Meaning | Payload |
|---|---|---|
0x00 | Data | Raw terminal input bytes |
0x01 | Resize | cols as big-endian u16, then rows as big-endian u16 |
0x02 | Ready | No payload |
Server-to-client opcodes
| Opcode | Meaning | Payload |
|---|---|---|
0x00 | Data | Raw terminal output bytes |
0x03 | Exit | Exit code as big-endian i32 |
Example Connection
Header-based token:wscat -H "X-PTY-Token: <token>" -c "wss://<sandbox-id>.sandbox.tensorlake.ai/api/v1/pty/<session-id>/ws"
wscat -c "wss://<sandbox-id>.sandbox.tensorlake.ai/api/v1/pty/<session-id>/ws?token=<token>"
Connection Semantics
- If the token is invalid, Tensorlake returns
403 Forbiddenwith codeINVALID_TOKEN. - If the session does not exist, Tensorlake returns
404 Not Foundwith codeSESSION_NOT_FOUND. - When the process exits, Tensorlake sends the
0x03exit frame and then closes the WebSocket with reasonexit:<code>. - If the PTY session is terminated while the socket is open, Tensorlake closes the WebSocket with code
1001and reasonsession terminated. - If you do not send
READY, Tensorlake buffers output up to 1 MB before disconnecting the client.
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Headers
Preferred PTY session token header for WebSocket authentication.
Path Parameters
The PTY session identifier.
Query Parameters
Optional PTY token. Prefer the X-PTY-Token header instead of the query string.
Response
WebSocket upgrade successful
Was this page helpful?