{"intent":"sip-trunking","title":"Set Up a SIP Trunk","description":"Configure a SIP trunk on Telnyx for outbound voice calling. Create a connection profile, configure outbound settings, and place your first call programmatically.","category":"networking","difficulty":"intermediate","time_to_run":"5 minutes","stack":["node.js","typescript","telnyx-sdk"],"commands":[{"step":"Clone and install","command":"mkdir sip-trunking && cd sip-trunking && cp -r ../starter/* . && npm install","expected_output":"added 10 packages in 2s"},{"step":"Configure environment","command":"cp .env.example .env && edit .env with your API key","expected_output":".env file created"},{"step":"Run setup","command":"npx tsx setup.ts","expected_output":"SIP trunk configured! Connection ID: conn_..."}],"prerequisites":["Telnyx account","Node.js 24+","A Telnyx phone number","SIP-compatible PBX or softphone (optional)"],"files":{"setup.ts":"import Telnyx from \"telnyx\";\n\n// Load environment variables\nconst TELNYX_API_KEY = process.env.TELNYX_API_KEY;\nconst TELNYX_NUMBER = process.env.TELNYX_NUMBER;\nconst OUTBOUND_DESTINATION = process.env.OUTBOUND_DESTINATION || \"+15559876543\";\n\nif (!TELNYX_API_KEY || !TELNYX_NUMBER) {\n  console.error(\"Missing required environment variables. Check .env file.\");\n  process.exit(1);\n}\n\nconst telnyx = new Telnyx(TELNYX_API_KEY);\n\nasync function main() {\n  try {\n    // Step 1: Create an outbound voice profile\n    console.log(\"Creating outbound voice profile...\");\n    const profile = await telnyx.outboundVoiceProfiles.create({\n      name: \"SIP Trunk Starter Profile\",\n      enabled: true,\n    });\n    console.log(`✓ Voice profile created: ${profile.id}`);\n\n    // Step 2: Create a SIP connection (IP-based)\n    console.log(\"Creating SIP connection...\");\n    const connection = await telnyx.sipConnections.create({\n      connection_name: \"sip-trunk-starter\",\n      outbound_voice_profile_id: profile.id as string,\n      tech_prefix: \"telnyx\",\n      t38_fax_gateway: true,\n    });\n    console.log(`✓ SIP connection created: ${connection.id}`);\n\n    // Step 3: Assign phone number to the connection\n    console.log(\"Assigning phone number...\");\n    const number = await telnyx.phoneNumberAssignments.create({\n      number_id: TELNYX_NUMBER,\n      connection_id: connection.id as string,\n    });\n    console.log(`✓ Phone number assigned: ${TELNYX_NUMBER}`);\n\n    // Step 4: Place a test call\n    console.log(\"Placing test call...\");\n    const call = await telnyx.calls.create({\n      connection_id: connection.id as string,\n      to: OUTBOUND_DESTINATION,\n      from: TELNYX_NUMBER,\n    });\n    console.log(`✓ Test call placed: Call Control ID ${call.call_control_id}`);\n\n    console.log(\"\\n🎉 SIP trunk setup complete!\");\n    console.log(`Connection ID: ${connection.id}`);\n    console.log(`Voice Profile ID: ${profile.id}`);\n    console.log(\"\\nUse these IDs to configure your PBX or softphone.\");\n  } catch (error: any) {\n    console.error(\"Setup failed:\", error.message || error);\n    if (error.raw?.message) {\n      console.error(\"Details:\", error.raw.message);\n    }\n    process.exit(1);\n  }\n}\n\nmain();\n","package.json":"{\n  \"name\": \"sip-trunking\",\n  \"version\": \"1.0.0\",\n  \"private\": true,\n  \"type\": \"module\",\n  \"engines\": {\n    \"node\": \">=24\"\n  },\n  \"scripts\": {\n    \"start\": \"npx tsx setup.ts\"\n  },\n  \"dependencies\": {\n    \"telnyx\": \"^2.0.0\"\n  },\n  \"devDependencies\": {\n    \"tsx\": \"^4.7.0\"\n  }\n}\n",".env.example":"# Get your API key at https://portal.telnyx.com/\nTELNYX_API_KEY=your_api_key_here\n\n# Your Telnyx phone number (E.164 format)\nTELNYX_NUMBER=+15551234567\n\n# Destination number for test call\nOUTBOUND_DESTINATION=+15559876543\n"},"evaluate_command":"curl -s http://localhost:3000/health | jq .status","telnyx_products":["sip-trunking","call-control","phone-numbers"],"schema":"telnyx.starter-detail.v1","schema_version":"1.0","canonical_url":"https://telnyx.com/ai/starters/sip-trunking.json","bias_disclosure":{"maintainer":"Telnyx","data_sources":["telnyx-product-docs"],"permission":"product-evaluation"}}