TypeScript SDK
Use @ody-co/sdk from Node.js, Deno, Bun or the browser: setup, pagination, errors, idempotency and webhook verification.
#Setup
npm install @ody-co/sdkPublished on npm as @ody-co/sdk (MIT, zero dependencies, ESM, Node 18+). Releases are built from the public source tree by GitHub Actions.
import { Ody } from "@ody-co/sdk";
const ody = new Ody(process.env.ODY_API_KEY!);
// Options: new Ody(key, { baseUrl: "https://api.ody.co" })The client is ESM, has no dependencies, and runs anywhere fetch exists (Node.js 18+, Deno, Bun, Cloudflare Workers, browsers). Never ship a live key to a browser. Keys act as a workspace member, so call Ody from your server.
#Usage
// Contacts
const contact = await ody.contacts.create({ firstName: "Ada", phone: "+15125550123", tags: ["vip"] });
for await (const c of ody.contacts.listAll({ q: "ada" })) console.log(c.id);
// Conversations
const { conversations } = await ody.conversations.list({ status: "open", limit: 25 });
const { conversation, activities } = await ody.conversations.get(conversations[0].id);
await ody.conversations.setStatus(conversation.id, "done");
// Messages
const sent = await ody.messages.send({ to: "+15125550123", body: "Hi!", idempotencyKey: "welcome-ada" });
const hits = await ody.messages.search("refund", { limit: 10 });
// Calls
const calls = await ody.calls.list({ limit: 20 });
await ody.calls.place({ to: "+15125550123" });
// Numbers, 10DLC, agent
const available = await ody.numbers.searchAvailable({ startsWith: "512" });
await ody.numbers.buy({ phoneNumber: available[0].phone_number, idempotencyKey: "main-line" });
const status = await ody.messaging.status();
await ody.agent.update({ greeting: "Thanks for calling!" });
await ody.agent.publish();
// Several AI agents (Growth 3 · Enterprise 10): a second receptionist on a menu key of the only line
const sales = await ody.agents.create({ name: "Sales", voice: "luna" });
await ody.agents.attach(sales.id, "+15125550188", "menu"); // "Press 1 for Astra, press 2 for Sales"
await ody.agents.publish(sales.id);
const { agents, limit } = await ody.agents.list(); // each with reach.numbers / menuNumbers / flowNumbers / textingNumbers
// Business AI Texting: the agent answers the line's texts from the knowledge base
await ody.numbers.setTextingAgent("+15125550188", sales.id);
await ody.agents.setTexting(sales.id, true); // no publish needed
const t = await ody.agents.texting(sales.id); // { live, links, textingReady, runs, … }
await ody.conversations.setAiTexting(conversationId, true); // a human takes this thread over
const runs = await ody.conversations.aiTextingRuns(conversationId); // why it did / didn't reply
// Link tracking: every URL your team, your AI or this SDK texts becomes link.ody.co/<code>
await ody.linkTracking.update({ enabled: true }); // clicks → thread, Analytics, link.clicked webhook
const { settings } = await ody.linkTracking.get();
// Hosted files: every photo, video or PDF goes out as a branded link.ody.co/m/… page (on by default, no per-send flag)
await ody.hostedMedia.update({ displayName: "Glow Salon", accent: "#1c6bff", websiteUrl: "https://glowsalon.com" });
const sent = await ody.messages.send({ conversationId, body: "Your new colour ✨", mediaUrls: [p1, p2, p3] });
console.log(sent.message.hostedMedia?.[0]?.title, sent.message.media?.[0]?.hostedUrl); // "3 photos", "https://link.ody.co/m/…"
// Knowledge base (shared by every AI agent + suggested replies)
const { consumers } = await ody.knowledge.get();
const folder = await ody.knowledge.createFolder({ name: "Policies" });
await ody.knowledge.createArticle({
title: "Cancellation policy",
content: "Free up to 24 hours before; $25 after that.",
folderId: folder.id,
audience: "selected",
consumers: consumers.filter((c) => c.kind === "agent").map((c) => c.key),
});
const hits = await ody.knowledge.search("cancellation fee", { consumer: "texting" });#Errors
Every non-2xx response throws OdyError:
import { OdyError } from "@ody-co/sdk";
try {
await ody.messages.send({ to: "+15125550123", body: "Hi" });
} catch (err) {
if (err instanceof OdyError) {
switch (err.code) {
case "failed_precondition": /* e.g. 10DLC not approved yet: show err.message */ break;
case "resource_exhausted": await sleep((err.retryAfter ?? 1) * 1000); break;
case "unauthenticated": /* key revoked */ break;
}
console.error(err.status, err.code, err.message, err.requestId);
} else {
throw err; // network error
}
}The codes are listed in Errors.
#Webhook verification
import { verifyWebhookSignature } from "@ody-co/sdk";
const ok = verifyWebhookSignature(secret, headers, rawBody); // rawBody: string | Uint8ArrayIt checks the v1 HMAC-SHA256 signature in constant time and rejects timestamps more than 5 minutes off. It uses node:crypto, so it's server-side only. Full examples are in Verifying signatures.
#Webhooks
parseWebhookEvent verifies and parses in one step, and returns a WebhookEvent whose data is typed by event.type. It throws WebhookVerificationError on a bad or stale signature, so a handler is a try around one call:
import express from "express";
import { parseWebhookEvent, WebhookVerificationError } from "@ody-co/sdk";
app.post("/ody-webhook", express.raw({ type: "application/json" }), (req, res) => {
let event;
try {
event = parseWebhookEvent(process.env.ODY_WEBHOOK_SECRET!, req.headers, req.body);
} catch (err) {
if (err instanceof WebhookVerificationError) return res.status(401).end();
throw err;
}
switch (event.type) {
case "call.ringing":
screenPop(event.data.from, event.data.callerName); // typed as CallRingingData
break;
case "call.answered":
if (event.data.answeredBy === "member") assign(event.data.memberUid);
break;
case "contact.updated":
case "contact.deleted":
void syncContact(event.data.contactId); // ContactEventData
break;
}
res.status(200).end();
});WEBHOOK_EVENT_TYPES is the catalog as a readonly tuple (WebhookEventType is its union), and isKnownWebhookEventType(type) tells you whether a delivery's type is one this SDK version knows, so a subscription to ["*"] can log new types instead of crashing. Each event's fields are described in Event types.
#Types
Everything is exported: Contact, ContactSummary, ContactInput, ConversationSummary, Activity, PhoneNumber, MessagingStatus, Agent, AgentInput, KnowledgeArticle, KnowledgeArticleSummary, KnowledgeFolder, KnowledgeConsumer, KnowledgeSearchHit, Webhook, WebhookDelivery, OdyErrorCode, and for webhooks WebhookEvent, WebhookEnvelope, WebhookEventDataMap, CallRingingData, CallAnsweredData, CallForwardedData, ContactEventData and more. They mirror the OpenAPI spec and the event catalog.