curl --request POST \
--url https://api.anchorbrowser.io/v1/sessions/{session_id}/tokens \
--header 'Content-Type: application/json' \
--header 'anchor-api-key: <api-key>' \
--data '
{
"scopes": [],
"allowed_ips": [
"203.0.113.7",
"198.51.100.0/24"
]
}
'import requests
url = "https://api.anchorbrowser.io/v1/sessions/{session_id}/tokens"
payload = {
"scopes": [],
"allowed_ips": ["203.0.113.7", "198.51.100.0/24"]
}
headers = {
"anchor-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'anchor-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({scopes: [], allowed_ips: ['203.0.113.7', '198.51.100.0/24']})
};
fetch('https://api.anchorbrowser.io/v1/sessions/{session_id}/tokens', 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.anchorbrowser.io/v1/sessions/{session_id}/tokens",
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([
'scopes' => [
],
'allowed_ips' => [
'203.0.113.7',
'198.51.100.0/24'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"anchor-api-key: <api-key>"
],
]);
$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.anchorbrowser.io/v1/sessions/{session_id}/tokens"
payload := strings.NewReader("{\n \"scopes\": [],\n \"allowed_ips\": [\n \"203.0.113.7\",\n \"198.51.100.0/24\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anchor-api-key", "<api-key>")
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.anchorbrowser.io/v1/sessions/{session_id}/tokens")
.header("anchor-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"scopes\": [],\n \"allowed_ips\": [\n \"203.0.113.7\",\n \"198.51.100.0/24\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.anchorbrowser.io/v1/sessions/{session_id}/tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["anchor-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"scopes\": [],\n \"allowed_ips\": [\n \"203.0.113.7\",\n \"198.51.100.0/24\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"live_view_read_only_url": "<string>",
"live_view_url": "<string>",
"cdp_url": "<string>",
"allowed_ips": [
"<string>"
],
"tokens": [
{
"id": "tok_3f1c2b7e-9a4d-4c2e-8f6b-1d2e3f4a5b6c",
"scope": "live_view_read_only",
"created_at": "2023-11-07T05:31:56Z",
"expires_at": "2023-11-07T05:31:56Z",
"token": "<string>",
"url": "<string>",
"allowed_ips": [
"<string>"
]
}
]
}
}{
"error": {
"code": 123,
"message": "<string>"
}
}{
"error": {
"code": 123,
"message": "<string>"
}
}{
"error": {
"code": 123,
"message": "<string>"
}
}{
"error": {
"code": 123,
"message": "<string>"
}
}Create Session Tokens
Mint URLs for a running session that can be handed to end users without exposing the session id.
Each scope gets its own token, carried as ?token= in the URL:
live_view_read_only: watch the browser only.live_view: watch and interact with the browser.cdp: full CDP control.
Every call mints new tokens. A token stops working when the session ends or when it is revoked.
Each token in tokens has a non-secret id: keep the id to get or revoke the token later, and hand
out only the URL.
On a session created with live_view.read_only, live_view is watch-only too: live_view_url is the
read-only URL.
The first token makes the session token-only, as scoped_access does: new connections with only
?sessionId= are refused from then on, even after the tokens are revoked. Connections already open stay up.
curl --request POST \
--url https://api.anchorbrowser.io/v1/sessions/{session_id}/tokens \
--header 'Content-Type: application/json' \
--header 'anchor-api-key: <api-key>' \
--data '
{
"scopes": [],
"allowed_ips": [
"203.0.113.7",
"198.51.100.0/24"
]
}
'import requests
url = "https://api.anchorbrowser.io/v1/sessions/{session_id}/tokens"
payload = {
"scopes": [],
"allowed_ips": ["203.0.113.7", "198.51.100.0/24"]
}
headers = {
"anchor-api-key": "<api-key>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {'anchor-api-key': '<api-key>', 'Content-Type': 'application/json'},
body: JSON.stringify({scopes: [], allowed_ips: ['203.0.113.7', '198.51.100.0/24']})
};
fetch('https://api.anchorbrowser.io/v1/sessions/{session_id}/tokens', 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.anchorbrowser.io/v1/sessions/{session_id}/tokens",
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([
'scopes' => [
],
'allowed_ips' => [
'203.0.113.7',
'198.51.100.0/24'
]
]),
CURLOPT_HTTPHEADER => [
"Content-Type: application/json",
"anchor-api-key: <api-key>"
],
]);
$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.anchorbrowser.io/v1/sessions/{session_id}/tokens"
payload := strings.NewReader("{\n \"scopes\": [],\n \"allowed_ips\": [\n \"203.0.113.7\",\n \"198.51.100.0/24\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("anchor-api-key", "<api-key>")
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.anchorbrowser.io/v1/sessions/{session_id}/tokens")
.header("anchor-api-key", "<api-key>")
.header("Content-Type", "application/json")
.body("{\n \"scopes\": [],\n \"allowed_ips\": [\n \"203.0.113.7\",\n \"198.51.100.0/24\"\n ]\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.anchorbrowser.io/v1/sessions/{session_id}/tokens")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["anchor-api-key"] = '<api-key>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"scopes\": [],\n \"allowed_ips\": [\n \"203.0.113.7\",\n \"198.51.100.0/24\"\n ]\n}"
response = http.request(request)
puts response.read_body{
"data": {
"live_view_read_only_url": "<string>",
"live_view_url": "<string>",
"cdp_url": "<string>",
"allowed_ips": [
"<string>"
],
"tokens": [
{
"id": "tok_3f1c2b7e-9a4d-4c2e-8f6b-1d2e3f4a5b6c",
"scope": "live_view_read_only",
"created_at": "2023-11-07T05:31:56Z",
"expires_at": "2023-11-07T05:31:56Z",
"token": "<string>",
"url": "<string>",
"allowed_ips": [
"<string>"
]
}
]
}
}{
"error": {
"code": 123,
"message": "<string>"
}
}{
"error": {
"code": 123,
"message": "<string>"
}
}{
"error": {
"code": 123,
"message": "<string>"
}
}{
"error": {
"code": 123,
"message": "<string>"
}
}Authorizations
API key for your Anchor Browser account, sent as the anchor-api-key header on every
request. Create one at app.anchorbrowser.io (API Access).
Body
Was this page helpful?

