How to run Multilogin API scripts on multiple servers with Python
Need to run the same Multilogin API script on several servers? Python and SSH let you run everything from one computer, so you don't have to connect to each server and start the script yourself.
➡️ Generate an automation token → set up SSH access → add remote_api.py to each server → run auto.py from your computer.
This example checks your Multilogin API connection by retrieving a list of cloud phones. Once it works, you can replace the test request with your own automation tasks.
Before you start
You'll need:
- Python 3 on your computer and remote servers
- SSH key access to each server, with its host key verified
- A valid Multilogin automation token
- Internet access from each server to the Multilogin API
SSH and Multilogin use different credentials. Your SSH key connects you to a server, while your automation token lets the script send Multilogin API requests.
This example uses Linux or macOS servers
You can also use Windows servers, but you'll need to adjust the file paths and Python commands.
Step 1: prepare your servers
First, make sure you can connect to each server through SSH.
Open a terminal on your computer and try:
ssh username@server-ipReplace username and server-ip with your details.
If it's your first connection, check the server's SSH fingerprint with your administrator before trusting it.
Next, install the Python libraries.
On your computer:
python3 -m pip install paramikoOn each remote server:
python3 -m pip install requestsIf you're using a Python virtual environment, install the libraries there and use that environment to run your scripts.
Step 2: create the Multilogin API script
Let's start with a simple test. We'll ask the Multilogin API for your cloud phone list to make sure each server can connect.
Create a file called remote_api.py in the home folder of each remote server.
import sys
import requests
token = sys.stdin.readline().strip()
if not token:
raise SystemExit("No automation token provided.")
url = "https://api.multilogin.com/mobile_profiles/phone/list"
headers = {
"Authorization": f"Bearer {token}",
"Accept": "application/json",
}
params = {
"page": 1,
"page_size": 10,
}
try:
response = requests.get(
url,
headers=headers,
params=params,
timeout=30,
)
response.raise_for_status()
result = response.json()
status = result.get("status", {})
if status.get("http_code") != 200:
raise RuntimeError(
status.get("message", "Unknown API error")
)
print("Connected to Multilogin API successfully.")
except (requests.RequestException, ValueError, RuntimeError) as error:
print(f"API request failed: {error}")
raise SystemExit(1)The script receives your automation token when it runs. You don't need to save your Multilogin email, password, or token in the file.
This test doesn't change your profiles. It only requests the first page of your cloud phone list.
Step 3: create the server connection script
Now let's connect everything.
Create auto.py on your computer. This script connects to each server, passes your automation token, and runs remote_api.py.
import sys
import getpass
import paramiko
servers = [
{"username": "username1", "host": "server1-ip", "port": 22},
{"username": "username2", "host": "server2-ip", "port": 22},
]
token = getpass.getpass("Multilogin automation token: ")
if not token:
raise SystemExit("No automation token provided.")
failed_servers = []
for server in servers:
username = server["username"]
host = server["host"]
port = server.get("port", 22)
print(f"\nConnecting to {username}@{host}")
try:
with paramiko.SSHClient() as ssh:
ssh.load_system_host_keys()
ssh.set_missing_host_key_policy(
paramiko.RejectPolicy()
)
ssh.connect(
hostname=host,
port=port,
username=username,
look_for_keys=True,
allow_agent=True,
timeout=15,
)
stdin, stdout, stderr = ssh.exec_command(
"python3 ~/remote_api.py"
)
stdin.write(token + "\n")
stdin.flush()
stdin.channel.shutdown_write()
output = stdout.read().decode().strip()
errors = stderr.read().decode().strip()
exit_code = stdout.channel.recv_exit_status()
if output:
print(output)
if errors:
print(errors)
if exit_code != 0:
print(f"Script failed with code {exit_code}")
failed_servers.append(host)
except Exception as error:
print(f"Connection failed: {error}")
failed_servers.append(host)
if failed_servers:
print("\nFailed servers: " + ", ".join(failed_servers))
sys.exit(1)Replace the example usernames, server addresses, and ports with your own.
The script uses SSH keys, so you don't need to put server passwords in your code. It also checks that each server is trusted before connecting.
Step 4: run your scripts
Everything ready? Let's check the connection.
- Open a terminal on your computer
-
Go to the folder containing
auto.py - Run:
python3 auto.py- Enter your automation token when prompted.
- Check the results for each server.
- If a server connects successfully, you'll see:
Connected to Multilogin API successfully.If something goes wrong, the script will show which server failed.
Your token won't appear while you type it, and the script won't print or save it.
Step 5: add your own automation
Once the test works, you're ready to do more than check the connection.
Replace the test request in remote_api.py with the Multilogin API actions you need.
For example, you can:
- Get a list of cloud phones or browser profiles
- Check which profiles are running
- Create or update profiles
- Start or stop supported profiles
Say you manage accounts across several servers. You could use this setup to check profile statuses on all of them without connecting to each server separately.
You'll find the available endpoints, required parameters, and response examples in the Multilogin API documentation.
Using local launcher endpoints?
If your script starts or controls browser profiles through the local launcher API, the required Multilogin desktop components must be running on that server. The cloud API connection alone doesn't start the desktop app.
Troubleshooting
SSH connection fails
Try connecting manually:
ssh username@server-ipIf that doesn't work, check your SSH key and make sure you have permission to access the server.
If you get an unknown host key error, verify the server's fingerprint and add it to your trusted SSH hosts before trying again.
Python can't find a library
Check that you've installed the right library in the right place:
-
Your computer:
paramiko -
Remote servers:
requests
If you use a virtual environment, make sure you're running the script with the correct Python interpreter.
The Multilogin API returns an error
Check the error message first. These are some common responses:
-
401 – Unauthorized: your automation token may be missing, incorrect, or expired -
403 – Forbidden: your workspace or role may not have permission for the request -
429 – Too Many Requests: your workspace has reached its API rate limit
For more help, see Multilogin API rate limits and response codes.
Python can't verify the API certificate
If you're using a company proxy or custom network setup, Python might not recognize the certificate used for the connection.
Ask your administrator for the approved certificate authority (CA) bundle and configure Requests to use it.
Don't disable certificate verification. It's there to protect your connection.
Keep your automation token private
Only run these scripts on servers you trust.
Your automation token travels through an encrypted SSH connection, but the remote script can access it while running. Someone with control of that server could potentially capture the token and use its workspace permissions.