Skip to main content
The DialNexa API is reachable from any TypeScript or Node.js service using the standard fetch API (available natively in Node.js 18+ and on modern edge runtimes). There is no TypeScript-specific SDK package yet, the recommended pattern is a thin typed wrapper module in your own codebase that centralizes the base URL, authentication header, and error handling. The example below mirrors the operations published in /api-reference/openapi.json and is a good starting point for production server code.

When to use this

  • Server-side Node.js services that trigger outbound calls from CRM events, scheduled jobs, or upstream webhooks.
  • Edge runtimes (Cloudflare Workers, Vercel Edge Functions, Netlify Edge Functions) where you need a low-latency request path.
  • Internal tools and dashboards built with Next.js, Remix, or similar frameworks where DialNexa operations run in route handlers.
Do not call this directly from a browser bundle, the DIALNEXA_API_KEY must stay server-side. For browser-side voice call embedding, use the React SDK. For mobile apps, see the React Native SDK.

Triggering an outbound call

const API_KEY = process.env.DIALNEXA_API_KEY;
const BASE_URL = "https://api.dialnexa.com/v1";

type CreateCallRequest = {
  agent_id: string;
  to_phone_number: string;
  from_phone_number?: string;
  metadata?: Record<string, unknown>;
};

type CreateCallResponse = {
  id: string;
  status: string;
  agent_id: string;
  to_phone_number: string;
  from_phone_number?: string;
  duration_sec?: number;
  created_at: string;
};

export async function createCall(payload: CreateCallRequest): Promise<CreateCallResponse> {
  const response = await fetch(`${BASE_URL}/calls`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: `Bearer ${API_KEY}`,
    },
    body: JSON.stringify(payload),
  });

  if (!response.ok) {
    const errorBody = await response.text();
    throw new Error(`DialNexa createCall failed (${response.status}): ${errorBody}`);
  }

  return response.json() as Promise<CreateCallResponse>;
}
Example usage:
await createCall({
  agent_id: "agent_123",
  to_phone_number: "+14155550123",
  from_phone_number: "+14155559876",
  metadata: { campaign: "renewals", customer_name: "Priya Sharma" },
});
  • Type every request and response. The examples above declare explicit CreateCallRequest and CreateCallResponse types, keep this discipline so a wrong field name surfaces at compile time rather than at runtime.
  • Centralize the client. Wrap the snippet above in a single module (for example dialnexaClient.ts) and import it from every route handler and worker.
  • Use environment variables for the API key. Never inline keys in source. Make sure your bundler does not expose them to the client.
  • Set explicit timeouts. Pass an AbortSignal from AbortSignal.timeout(30_000) if your runtime supports it.
  • Retry on transient failures only. Retry HTTP 502/503/504 and network errors with exponential backoff. Do not retry 4xx responses, those indicate a payload that needs to be fixed. See Errors.
  • Validate webhook deliveries. For inbound events from DialNexa, verify the signing secret before trusting the payload. See Webhook secrets.
This example is generated from the currently published schema in /api-reference/openapi.json: agent_id and to_phone_number are required.