Set up your local development environment with SMS-dev, Relay's local SMS testing server that acts like "Mailtrap for SMS". Test your SMS integration without sending real messages or incurring costs.
Overview
The Relay development environment includes:
SMS-dev server: Local API server that mimics the Relay SMS API
Virtual Phone UI: Web interface to simulate receiving SMS messages
Relay CLI: Command-line tools for managing your development workflow
Mock data: Realistic test data without real SMS charges
Prerequisites
Before you begin:
Node.js 16+ installed
A Relay account (for production API keys)
Terminal access
Quick Setup
1. Install Relay CLI
Code
npm install -g @relay/cli
2. Verify Installation
Code
relay --version# Should show version 0.0.1 or later
3. Start Development Environment
Code
relay dev
This command will:
Start the SMS-dev API server on port 4001
Launch the virtual phone UI on port 4000
Display connection details
Expected output:
Code
Starting the local development environment...SMS-dev Server API: http://localhost:4001 Virtual Phone UI: http://localhost:4000Development environment ready! Send test messages to: http://localhost:4001/v1/messages View virtual phones at: http://localhost:4000
Point your application to the local development server:
Code
// Use environment variable — RELAY_API_BASE_URL is the origin without /v1// (the SDK and route paths append /v1/ themselves).const API_BASE_URL = process.env.NODE_ENV === 'production' ? (process.env.RELAY_API_BASE_URL || 'https://api.relay.works') : 'http://localhost:4001';
2. Use Development API Key
SMS-dev accepts any API key for testing:
Code
// Any key works in developmentconst API_KEY = 'rly_dev_test_key_12345';// Or use a real key for testing against productionconst API_KEY = process.env.RELAY_API_KEY;
# Error: Port 4001 already in userelay dev --api-port 4101 --ui-port 4100
Can't Connect to SMS-dev
Check if SMS-dev is running: relay status
Verify correct ports in your app configuration
Check firewall settings
Webhooks Not Working
Verify webhook URL is correct
Check your app is running and accessible
Look at SMS-dev logs: relay dev --verbose
Virtual Phone UI Not Loading
Check UI port is not blocked: http://localhost:4000
Try different port: relay dev --ui-port 4100
Disable UI and use CLI: relay dev --no-ui
Getting Help
Code
# Show all available commandsrelay --help# Show SMS-dev specific helprelay sms-dev --help# Check system statusrelay status# Show current configurationrelay config show
REST Client - Test API endpoints directly in VS Code
DotENV - Syntax highlighting for .env files
Create REST Client File
Create api-test.http for testing:
Code
### Variables@baseUrl = http://localhost:4001/v1@apiKey = rly_dev_test_key@phoneNumber = +15559876543### Test ConnectionGET {{baseUrl}}/user/mex-api-key: {{apiKey}}### Send SMSPOST {{baseUrl}}/messagesx-api-key: {{apiKey}}Content-Type: application/json{ "to": "+15551234567", "message": "Hello from VS Code!"}### List MessagesGET {{baseUrl}}/messages?limit=5x-api-key: {{apiKey}}
Switch to production by changing @baseUrl to https://api.relay.works/v1 and using a real API key.
Troubleshooting
Port Already in Use
Problem: Error message "Port 4001 already in use"
Solutions:
Code
# Check what's using the portslsof -i :4001lsof -i :4000# Use different portsrelay dev --api-port 4101 --ui-port 4100
Can't Connect to SMS-dev
Problem: Application can't reach the local development server
Solutions:
Check if SMS-dev is running:
Code
relay status
Verify correct ports in your app configuration:
Code
const API_URL = 'http://localhost:4001/v1'; // Check port matches
Check firewall settings - ensure ports 4000 and 4001 are allowed
Restart SMS-dev with verbose logging:
Code
relay dev --verbose
Webhooks Not Working
Problem: Webhook events not reaching your application
Solutions:
Verify webhook URL is correct and accessible:
Code
# Test if your webhook endpoint is reachablecurl -X POST http://localhost:3000/webhook \ -H "Content-Type: application/json" \ -d '{"event":"test","data":{}}'
Check your app is running and listening on the correct port
View SMS-dev logs for webhook delivery attempts:
Code
relay dev --verbose
Ensure webhook handler responds with 200 status:
Code
app.post('/webhook', (req, res) => { console.log('Webhook received:', req.body); res.status(200).send('OK'); // Must respond with 200});