Installing the SDK
Initialize the Client
import { Contiguity } from "contiguity";
const contiguity = new Contiguity("contiguity_sk_...your_key...");
import { Contiguity } from "contiguity";
// Reads CONTIGUITY_API_KEY or CONTIGUITY_TOKEN
const contiguity = new Contiguity();
Initialization
The SDK accepts a token and optional configuration:
import { Contiguity } from "contiguity";
// With API key
const contiguity = new Contiguity("contiguity_sk_...your_key...");
// Omit key: SDK reads CONTIGUITY_API_KEY or CONTIGUITY_TOKEN from env
const contiguity = new Contiguity();
// With options
const contiguity = new Contiguity("contiguity_sk_...", {
debug: true // request logging (default: false)
});
Config
When true, enables request logging for debugging.
Quick Start
Once initialized, you can start using the SDK immediately:
// Send a text message
await contiguity.text.send({
to: "+1234567890",
message: "Hello from Contiguity!"
});
// Send an email
await contiguity.email.send({
to: "user@example.com",
from: "Your App <no-reply@yourapp.com>",
subject: "Welcome!",
text: "Welcome to our platform!"
});
All API responses are normalized to a single shape:
- Top level: method-specific fields (e.g.
message_id, email_id, domains, metadata).
metadata: { id, timestamp, api_version, object } on every response.
Clean responses with metadata separate from the main data:
{
message_id?: string,
email_id?: string,
otp_id?: string,
// ... other method-specific fields
metadata: {
id: string,
timestamp: string,
api_version: string,
object: string,
}
}
Errors
On API errors the SDK throws ContiguityError (subclass of Error) with message, status (HTTP status), and optional code.
import { ContiguityError } from "contiguity";
try {
await contiguity.text.send({ to: "+1234567890", message: "Hi" });
} catch (e) {
if (e instanceof ContiguityError) {
console.error(e.status, e.message);
}
}
Webhooks
To verify and parse webhook payloads, use contiguity.webhook.verify() and contiguity.webhook.parse(). See Webhooks for the full reference.
