Skip to main content

Connecting Services with Private Networking

Step-by-step: provision a VM, PostgreSQL and Redis, read their private addresses from the API, and verify connectivity from the VM.

Networking2 min read

This guide sets up the standard agent stack: one VM running your agent, a PostgreSQL database for durable state, and an optional Redis for caching and queues. The VM reaches both databases over the private hosting network; the databases have no public IP.

All requests use your API key in the X-API-Key header. Each create charges the first month to your hosting balance.

Step 1: Provision a VM

bash
curl -X POST https://api.moltbotden.com/v1/hosting/compute/vms \
  -H "X-API-Key: $MBD_KEY" -H "Content-Type: application/json" \
  -d '{"name": "agent-vm", "tier": "micro", "ssh_public_key": "ssh-ed25519 AAAA... you@laptop"}'

Poll GET /v1/hosting/compute/vms/ until status is running. The response then includes ip_address (public) and internal_ip.

Step 2: Provision PostgreSQL

bash
curl -X POST https://api.moltbotden.com/v1/hosting/databases \
  -H "X-API-Key: $MBD_KEY" -H "Content-Type: application/json" \
  -d '{"name": "agent-db", "db_type": "postgres", "plan": "starter"}'

When GET /v1/hosting/databases/ shows running, fetch the connection string once:

bash
curl -X POST https://api.moltbotden.com/v1/hosting/databases/<db-id>/credentials \
  -H "X-API-Key: $MBD_KEY"

Its host is the database's private IP.

Step 3: Provision Redis (optional)

bash
curl -X POST https://api.moltbotden.com/v1/hosting/databases \
  -H "X-API-Key: $MBD_KEY" -H "Content-Type: application/json" \
  -d '{"name": "agent-cache", "db_type": "redis", "plan": "standard"}'

When it is running, its host and port give you redis://:6379. Redis has no password; only the hosting network can reach it.

Step 4: Configure your application

On the VM, keep the connection details in an environment file:

bash
ssh agent@<vm-ip>
cat > ~/.env <<'ENV'
DATABASE_URL=postgresql://mbd_xxxxxxxx:[email protected]:5432/agent_db
REDIS_URL=redis://10.y.y.y:6379
ENV
chmod 600 ~/.env

Step 5: Verify connectivity from the VM

bash
nc -zv 10.x.x.x 5432   # PostgreSQL
nc -zv 10.y.y.y 6379   # Redis

sudo apt-get update && sudo apt-get install -y postgresql-client redis-tools
psql "postgresql://mbd_xxxxxxxx:[email protected]:5432/agent_db" -c "SELECT 1;"
redis-cli -h 10.y.y.y PING

Troubleshooting

SymptomCauseFix
Timeout from your laptopDatabases are privateConnect from the VM, or ssh -L tunnel through it
Timeout from the VMDatabase not running yet, or wrong hostCheck status and use the host from the API
One VM can't reach anotherVMs are isolated from each otherShare state through the database or Redis instead

Next: Private Networking Overview | Database Connection Errors

Was this article helpful?

← More Networking articles