Skip to main content
@fonoster/sdk manages a workspace from Node.js or the browser: applications, numbers, trunks, SIP agents, calls, call records, webhooks, providers and keys. It wraps Fonoster’s gRPC API. To answer calls with your own code, use the Voice SDK instead.

Install

The package works in Node.js and in browsers. In the browser it talks grpc-web to the same endpoint.

Create a client and sign in

Create a client with your workspace’s access key ID, then sign in with an API key:
The client’s accessKeyId selects the workspace: every request goes to the workspace whose access key ID starts with WO. The API key ID (AP…) and its secret prove who you are. See API keys and access for where to find each value.

Client options (Node.js)

string
required
The workspace’s access key ID (WO and 32 characters). Every request acts on this workspace.
string
default:"api.fonoster.ai"
The gRPC endpoint, as host or host:port. Set it to your install’s address when you self-host.
boolean
default:"false"
Connect without TLS. Use it only for a local install on plain HTTP.
string
The base URL of the HTTP routes (call records and regions). Default https:// plus the endpoint’s host, without the port.
boolean
default:"false"
Turn off automatic token renewal.

WebClient options (browser)

The browser build exports WebClient instead of Client. It takes url (default https://api.fonoster.ai) and accessKeyId, and has the same sign-in methods.

Sign-in and session methods

These are methods of Client and WebClient. Each sign-in method stores the tokens on the client; the client renews the access token before a request when it has expired.

Conventions

  • Every method returns a promise. A rejected gRPC call rejects with the gRPC error.
  • Refs are UUIDs, such as 3f8b2c71-9d4e-4a6b-8c25-7e1f0a9b4d62. create*, update* and delete* methods resolve to { ref } unless noted.
  • List methods take { pageSize, pageToken } and resolve to { items, nextPageToken }. Pass nextPageToken back as pageToken to get the next page.
  • Dates are Date objects unless noted.
  • CallRecords and Regions use HTTP. They reject with CallRecordsError or RegionsError, which carry status (the HTTP status) and code (the error code from the body).

Applications

An application is a stream (STREAM) or an Autopilot agent (AUTOPILOT). new SDK.Applications(client). The request for createApplication:
string
required
A name for the application.
"STREAM" | "AUTOPILOT"
required
A stream runs your WebSocket server. An Autopilot agent runs on Fonoster.
string
Streams: the ws:// or wss:// address Fonoster dials for each call.
"fonoster" | "twilio"
default:"fonoster"
The stream’s wire protocol: the session protocol or Twilio Media Streams.
object
Speech defaults. Voices and models are catalog ids, such as deepgram/aura-2-thalia-en.
object
Audio format for fonoster streams: { codec: "pcm16" | "pcmu", rate }.
string
Another application to take the call when this one can’t be reached.
string
Text spoken before hanging up when the application can’t be reached.
object[]
Listen-only WebSockets: { url, tracks: "inbound" | "outbound" | "both" }. Up to 4 are dialed.
"off" | "on" | "consent" | ""
Recording policy. Empty inherits the workspace’s policy. See Recording.
object
Answering-machine detection: { enabled, windowMs }. windowMs defaults to 4000 (500 to 15000). Off when unset. See Answering-machine detection.
object
Autopilot agents: { config }, the agent’s configuration. See Autopilot configuration.
An Application has the same fields, plus ref, signingSecretHint (the secret’s last characters), createdAt and updatedAt.

Numbers

Phone numbers and where their calls go. new SDK.Numbers(client). telUrl, city, country and countryIsoCode can’t change after creation.

Trunks

SIP connections to your carriers. new SDK.Trunks(client). Each entry in uris is the carrier’s address for outbound calls: { host, port, transport, user, weight, priority, enabled }. transport is one of UDP, TCP, TLS, SCTP, WS, WSS.

Domains

SIP domains that SIP agents register to. new SDK.Domains(client). domainUri can’t change after creation. Names are one label under your install’s roots: <label>.sip.<domain> for a domain and <label>.pstn.<domain> for a trunk’s inboundUri (self-hosted installs can allow any host).

Agents (SIP agents)

SIP endpoints, such as softphones, that register to a domain. The class is Agents; the docs call them SIP agents. new SDK.Agents(client).

Credentials

Usernames and passwords for SIP agents and trunks. new SDK.Credentials(client).

Acls

Access control lists of IP addresses and networks. new SDK.Acls(client).

Calls

Start outbound calls and read call history. new SDK.Calls(client). statusStream is an async iterator of { status } while the call is dialed. status is one of TRYING, PROGRESS, ANSWER, BUSY, CANCEL, FAILED or ERROR (no answer). metadata reaches the application in session.start. A CallDetailRecord has ref, accessKeyId, status, type (SIP_ORIGINATED, API_ORIGINATED), from, to, duration, direction (FROM_PSTN, TO_PSTN, INTRA_NETWORK), startedAt, endedAt and appRef (the app that handled the call; absent when none did). When answering-machine detection ran, it also has amdStatus, amdConfidence, amdDetector, amdLatencyMs and amdCause.

CallRecords

Signed call records (vCon) over HTTP. new SDK.CallRecords(client, { baseUrl?, fetch? }); baseUrl defaults to the client’s httpUrl. See Call records. A record summary has callRef, appRef, from, to, direction, status, endReason, failureReason, sipStatus, startedAt, endedAt, durationSeconds, region, version, size and parts.

Webhooks

Endpoints that receive workspace events. new SDK.Webhooks(client). See Webhook events. A WebhookDelivery has ref, webhookRef, eventId, eventType, status (pending, succeeded, failed), attempts, lastStatus (HTTP status of the last attempt, 0 for no response), lastAttemptAt, nextAttemptAt and createdAt.

Providers

The catalog of speech and language providers, and your own vendor keys. new SDK.Providers(client). See Providers and models. A CatalogItem has id (such as deepgram/nova-3), kind, state (active, deprecated), providerId, and when they apply type, capabilities, languages, features, models, gender, replacement and retireOn.

Usage

What the workspace consumed, in quantities, never money. new SDK.Usage(client). A UsageRow has meter, unit and quantity, plus the dimensions you grouped by. Meters: call.seconds (from answer to hangup), stt.seconds, tts.characters, llm.tokens.in, llm.tokens.out, llm.tokens.cached, embedding.tokens, nc.seconds (noise cancelling), amd.detections, amd.seconds, recording.seconds and storage.bytes (the peak in the range, or the day’s reading when grouped by day). keySource says whether a vendor was called with your own key (workspace) or the platform’s (platform); origin tells calls (call) from browser tests (browser_test) and evals (eval).

Secrets

Named secret values stored in the workspace. new SDK.Secrets(client).

ApiKeys

API keys for the workspace. new SDK.ApiKeys(client). See API keys and access. expiresAt, createdAt and updatedAt of a key are seconds since the epoch.

Workspaces

Workspaces you belong to, and their members. new SDK.Workspaces(client). The workspace selected by the client’s accessKeyId is the one these methods act on, except createWorkspace and listWorkspaces. role is WORKSPACE_OWNER, WORKSPACE_ADMIN or WORKSPACE_MEMBER; status is PENDING or ACTIVE.

Regions

The regions a new workspace can use, over HTTP. new SDK.Regions(client, { baseUrl?, fetch? }). Pass a region’s id to createWorkspace({ name, region }). Creating and enrolling private regions is covered under Private regions.