Skip to main content
This guide will walk you through installing the SDK, initializing a client, and sending your first message.

Installation

1

Install the package

Choose your preferred package manager:
npm install contiguity
2

Get your API token

Sign up and get your API token from the Contiguity Console. Your token will start with contiguity_sk_.
Keep your API token secure and never commit it to version control. Use environment variables in production.
3

Set up environment variables (optional)

Create a .env file in your project root:
.env
CONTIGUITY_API_KEY=contiguity_sk_your_token_here
Or alternatively:
.env
CONTIGUITY_TOKEN=contiguity_sk_your_token_here
The SDK automatically reads from CONTIGUITY_API_KEY or CONTIGUITY_TOKEN environment variables if no token is provided to the constructor.

Initialize the Client

Import and create a new Contiguity client instance:
import { Contiguity } from 'contiguity';

// Option 1: Pass token directly
const contiguity = new Contiguity('contiguity_sk_your_token_here');

// Option 2: Use environment variable
const contiguity = new Contiguity();

// Option 3: With debug mode enabled
const contiguity = new Contiguity('contiguity_sk_your_token_here', {
  debug: true
});
The constructor will throw an error if:
  • No token is provided and no environment variable is set
  • The token doesn’t start with contiguity_sk_

Send Your First Message

Send a text message to any phone number:
const response = await contiguity.text.send({
  to: "+1234567890",
  message: "Hello from Contiguity!"
});

console.log('Message sent:', response.message_id);
Response:
{
  "message_id": "msg_abc123...",
  "metadata": {
    "id": "req_...",
    "timestamp": "1234567890",
    "api_version": "v1",
    "object": "text_message"
  }
}

Error Handling

All SDK methods can throw errors. Use try-catch blocks to handle them:
import { Contiguity, ContiguityError } from 'contiguity';

const contiguity = new Contiguity();

try {
  const response = await contiguity.text.send({
    to: "+1234567890",
    message: "Hello!"
  });
  console.log('Success:', response.data);
} catch (error) {
  if (error instanceof ContiguityError) {
    console.error('API Error:', error.message);
    console.error('Status:', error.status);
  } else {
    console.error('Unexpected error:', error);
  }
}

Next Steps

Installation Guide

Learn more about environment setup and configuration

Text Messages

Explore text messaging features and options

Email

Send emails with React templates and attachments

Webhooks

Handle incoming messages and events

Build docs developers (and LLMs) love