Tor Support¶
Running Routstr as a Tor Hidden Service allows you to offer API access anonymously and bypass NAT/firewalls without port forwarding.
Automatic Setup (Docker)¶
The standard compose.yml includes a Tor container pre-configured to serve your node.
- Start the stack:
docker compose up -d - Wait: Tor takes about 30 seconds to generate keys and bootstrap.
- Find your address:
Output:
docker exec tor cat /var/lib/tor/hidden_service/hostnamev2xyz...longaddress.onion
Routstr will automatically detect this address (via the discover_onion_url_from_tor logic) and include it in:
- The /v1/info endpoint.
- Nostr announcements (RIP-02).
Manual Setup¶
If you are running outside Docker or managing Tor yourself:
- Install Tor:
sudo apt install tor - Edit
torrc:HiddenServiceDir /var/lib/tor/routstr/ HiddenServicePort 80 127.0.0.1:8000 - Restart Tor:
sudo systemctl restart tor - Get Address:
sudo cat /var/lib/tor/routstr/hostname - Configure Routstr:
Set
ONION_URL=http://youraddress.onionin your.envfile so the node knows its own address.
Client Usage¶
Clients connecting to your .onion address must route traffic through SOCKS5.
Python Example:
import httpx
from openai import OpenAI
client = OpenAI(
base_url="http://youraddress.onion/v1",
api_key="sk-...",
http_client=httpx.Client(proxy="socks5://127.0.0.1:9050")
)