TypeScript SDK
Reference for the samva TypeScript SDK — client config, email send methods, services, and error shapes.
The samva package is the official TypeScript/JavaScript SDK for the Samva email API. It is generated from the OpenAPI specification, so its surface mirrors the REST API exactly.
This page is a reference. For a step-by-step walkthrough of sending your first email, see Send an email.
Email first. Samva is launching with email. SMS, WhatsApp, and voice are staged and will be documented as they ship.
Installation
npm install samvabash npm install samva bash yarn add samva bash pnpm add samva bash bun add samva Client
createClient(config)
Creates a configured client instance. The organization context is derived from the API key — no organization slug or ID is required.
import { createClient } from "samva";
const samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });Config options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | One of apiKey / authToken | — | API key. Sent as the X-API-Key header. |
authToken | string | One of apiKey / authToken | — | OAuth bearer token (e.g. from samva login). Sent as Authorization: Bearer. |
baseUrl | string | No | https://api.samva.app | API base URL. Override for testing or self-hosting. |
Pass exactly one of apiKey or authToken. Use apiKey for servers (the organization is derived from the key); use authToken for first-party or OAuth tooling, where the session is user-scoped — pass the active organization with headers: { "x-org-slug": "<slug>" }. See API keys and OAuth sessions.
Additional fields from the underlying generated HTTP client Config (such as headers and fetch) are also accepted.
Return shape
createClient returns a SamvaClient exposing the live services below plus client, the underlying HTTP client.
| Property | Description |
|---|---|
email | Email send helper plus domain, sender, and template methods |
messages | Unified message send and retrieval |
contacts | Contact records |
conversations | Threaded message grouping |
webhooks | Event delivery configuration |
apiKeys | Programmatic access management |
organizations | Organization settings |
scheduled | Scheduled messages |
client | Underlying HTTP client |
Calling convention
Methods take flat request parameters as the first argument. Request options such as throwOnError, headers, and signal are passed as an optional second argument.
Every method resolves to a result object:
| Field | Description |
|---|---|
data | The response payload on success (for example, data.id) |
error | The error payload on failure; undefined on success |
const result = await samva.email.send({
to: "ada@example.com",
subject: "Welcome to Samva",
html: "<h1>Welcome!</h1>",
});
if (result.error) {
console.error("Send failed:", result.error);
} else {
console.log("Sent:", result.data?.id);
}samva.email
The canonical surface for email.
email.send(input, options?)
The simplest way to send email. It is an SDK-only ergonomic wrapper over messages.send() — there is no email.send REST endpoint. Email fields are flattened directly into the input object (not nested under an email key).
const result = await samva.email.send({
to: "ada@example.com",
subject: "Welcome to Samva",
html: "<h1>Welcome!</h1>",
});Input fields
| Field | Type | Required | Description |
|---|---|---|---|
to | recipient or recipient array | Yes | Recipient(s). See Recipients. |
subject | string | — | Email subject line. |
html | string | — | HTML body. Provide html, text, or both. |
text | string | — | Plain-text body. |
attachments | array | — | File attachments. |
templateId | string | — | Template to render instead of inline html/text. |
templateData | object | — | Variables passed to the template. |
conversationId | string | — | Attach the message to an existing conversation. |
inReplyToMessageId | string | — | Thread the message as a reply to a prior message. |
unsubscribeGroupId | string | — | Unsubscribe group to associate with the message. |
metadata | object | — | Arbitrary key/value metadata to attach to the message. |
Recipients
to accepts a single value or an array of any of:
| Form | Example |
|---|---|
| Email string | "ada@example.com" |
| Email object | { email: "ada@example.com" } |
| Contact reference | { contactId: "contact_123" } |
| Contact object | { id: "contact_123" } (an object with id is treated as a contact) |
Email helper methods
The email service also exposes domain, sender, and template management. All take the standard options object and return { data, error }.
| Method | Purpose |
|---|---|
listTemplates(options?) | List email templates. |
createTemplate(options) | Create a template with a variable schema. |
getStats(options?) | Email sending statistics. |
addDomain(options) | Add a sending domain; returns the DNS records to set. |
listDomains(options?) | List sending domains. |
verifyDomain(options) | Trigger verification for a domain. |
checkDomainVerification(options) | Check verification status. |
getDomainStatus(options) | Current domain status. |
getDomainById(options) | Fetch a domain by ID. |
removeDomain(options) | Remove a domain. |
addSender(options) | Add a verified sender address. |
listSenders(options?) | List sender addresses. |
checkSenderVerification(options) | Check sender verification status. |
removeSender(options) | Remove a sender. |
For domain verification steps, see Verify your domain.
samva.messages
The unified send and retrieval API. email.send() delegates to messages.send(); reach for messages.send() directly when you want the explicit nested shape, for example to address contacts by contactId, send to multiple recipients, or thread a reply.
messages.send(input, options?)
const result = await samva.messages.send({
to: [{ contactId: "contact_123" }],
channel: "email",
email: {
subject: "Welcome to Samva",
html: "<h1>Welcome!</h1>",
},
});Input fields
| Field | Type | Required | Description |
|---|---|---|---|
to | recipient array | Yes | Recipients. Always an array. See Recipients. |
channel | "email" | Yes | Send channel. Email-only at launch. |
email | object | Yes | Nested email content (see below). |
conversationId | string | — | Attach to an existing conversation. |
metadata | object | — | Arbitrary key/value metadata. |
The nested email object carries subject, html, text, attachments, templateId, templateData, inReplyToMessageId, and unsubscribeGroupId — the same content fields that email.send() flattens into body.
Other message methods
| Method | Purpose |
|---|---|
list(options?) | List messages. |
get(options) | Get a message by ID. |
getStatus(options) | Get delivery status for a message. |
getEvents(options) | Get the event log for a message. |
remove(options) | Delete a message. |
const messages = await samva.messages.list({ channel: "email", limit: "20" });
const message = await samva.messages.get({ id: "msg_123" });
const events = await samva.messages.getEvents({ id: "msg_123" });Other services
All services follow the same calling convention and result shape.
samva.contacts
| Method | Purpose |
|---|---|
create, update, remove | Manage a contact record. |
get, find, list | Fetch and list contacts. |
findOrCreate | Look up a contact or create it if absent. |
bulkImport, bulkDelete | Bulk create or delete. |
bulkUpdateStatus, bulkUpdateTags | Bulk attribute updates. |
export | Export contacts. |
getActivityTimeline, getEngagement, getGroupMemberships | Contact activity and grouping. |
samva.conversations
| Method | Purpose |
|---|---|
create, update | Manage a conversation. |
getById, list | Fetch and list conversations. |
addContacts, removeContacts | Manage conversation participants. |
samva.webhooks
| Method | Purpose |
|---|---|
create, update, remove | Manage a webhook endpoint. |
get, list | Fetch and list endpoints. |
getStats, getLogs | Delivery statistics and logs. |
test, retryDelivery | Send a test event or retry a delivery. |
regenerateSecret | Rotate the signing secret. |
For receiving and verifying webhook events, see Receive webhooks.
samva.apiKeys
| Method | Purpose |
|---|---|
create, update, remove | Manage an API key. |
get, list | Fetch and list keys. |
revoke, rotate | Revoke or rotate a key. |
getStats, getActivity | Usage statistics and activity. |
samva.organizations
| Method | Purpose |
|---|---|
get, update | Read and update organization settings. |
getUsage | Usage figures for the organization. |
samva.scheduled
| Method | Purpose |
|---|---|
create, get, list | Manage scheduled messages. |
cancel | Cancel a scheduled message. |
Error handling
Methods do not throw on API errors by default. Inspect the result instead:
const result = await samva.email.send({
to: "ada@example.com",
subject: "Test",
text: "Hello",
});
if (result.error) {
// result.error holds the error payload
console.error(result.error);
} else {
console.log(result.data?.id);
}Environment variables
Store the API key in an environment variable rather than hard-coding it.
# .env
SAMVA_API_KEY=sk_sm_your_api_key_hereconst samva = createClient({ apiKey: process.env.SAMVA_API_KEY! });Key format
Every Samva API key starts with sk_sm_. There is no separate live and test key — pass your key into the client as apiKey.
const samva = createClient({ apiKey: "sk_sm_..." });See Authentication for key format and details.
Support matrix
| SDK | Package | API version | Runtime |
|---|---|---|---|
| TypeScript | samva | v1 | Modern Node.js, Bun, and Deno (ESM) |
| REST API | — | v1 | Any HTTP client |
The SDK is generated from the Samva OpenAPI specification using @hey-api/openapi-ts, so it stays in sync with the REST API. For other languages, use the REST API with your language's HTTP client.
See also
Authentication
API key reference for the Samva email API — key format, the X-API-Key header, rate limiting, and authentication errors.
REST API
REST conventions for the Samva email API — base URL, authentication, request and response shapes, status codes, rate limits, pagination, idempotency, and errors.