OptimoCMSDocs
SDK

TypeScript SDK — Installation

Install and configure the official OptimoCMS TypeScript SDK.

TypeScript SDK

The official TypeScript SDK provides a type-safe, ergonomic interface for the OptimoCMS API.

Installation

npm install @optimocms/sdk

Or with yarn/pnpm:

yarn add @optimocms/sdk
pnpm add @optimocms/sdk

Requirements

EnvironmentMinimum version
Node.js18.0+
TypeScript5.0+ (optional, but recommended)
BrowserAny with ES2020 module support (Chrome 80+, Firefox 80+, Safari 14+, Edge 80+)

Module formats

The SDK ships both ESM and CJS bundles:

// ESM (recommended)
import { OptimoCMS } from '@optimocms/sdk';

// CommonJS
const { OptimoCMS } = require('@optimocms/sdk');

Client setup

import { OptimoCMS } from '@optimocms/sdk';

const cms = new OptimoCMS({
  apiKey: process.env.OPTIMOCMS_API_KEY!,
});

Configuration options

const cms = new OptimoCMS({
  apiKey: process.env.OPTIMOCMS_API_KEY!,

  // Base URL (default: https://api.optimocms.com)
  baseUrl: 'https://api.optimocms.com',

  // Request timeout in ms (default: 30000)
  timeout: 30_000,

  // Automatic retry on 429/5xx (default: 3)
  maxRetries: 3,
});
OptionTypeDefaultDescription
apiKeystringRequired. Your API key
baseUrlstringhttps://api.optimocms.comAPI base URL
timeoutnumber30000Request timeout in milliseconds
maxRetriesnumber3Max retries on rate limit or server errors

Browser usage

The SDK also works in the browser. Never use your API key directly in client-side code — create a backend proxy:

// Backend (Node.js) — /api/sites.ts
import { OptimoCMS } from '@optimocms/sdk';

const cms = new OptimoCMS({ apiKey: process.env.OPTIMOCMS_API_KEY! });

export async function GET() {
  const sites = await cms.sites.list();
  return Response.json(sites);
}
// Frontend (browser)
const response = await fetch('/api/sites');
const sites = await response.json();

Available modules

After initialization you have access to all API modules:

cms.sites       // Manage sites
cms.pages       // Page CRUD
cms.media       // Upload and manage media
cms.analytics   // Retrieve analytics
cms.ai          // AI generation and translation
cms.booking     // Bookings
cms.reservation // Reservations
cms.shop        // Products, orders, coupons
cms.loyalty     // Loyalty points
cms.webhooks    // Webhook configuration
cms.forms       // Form submissions
cms.push        // Push notifications
cms.reviews     // Reviews
cms.recruitment // Job listings
cms.batch       // Bulk operations
cms.jobs        // Async job polling
cms.domains     // Domain registration and management
cms.mail        // Mailboxes and DNS records
cms.seo         // SEO configuration and design tokens
cms.chatbot     // Chatbot configuration

TypeScript types

All request and response types are fully typed and exported:

import type {
  Site,
  SiteSummary,
  Page,
  PageDetail,
  PageSummary,
  CreatePageInput,
  UpdatePageInput,
  MediaItem,
  AnalyticsSummary,
  Product,
  Booking,
  OptimoCMSError,
  PaginatedResponse,
} from '@optimocms/sdk';

Try it — curl equivalent:

# The SDK hides these details, but this is what happens under the hood
curl https://api.optimocms.com/v1/sites \
  -H "X-Api-Key: optimo_live_abc123def456"

Try it — MCP equivalent:

Use the list_sites tool.

AI generation with media

The cms.ai module supports AI-generated hero videos. Available for Professional and Agency plans.

Generate page with hero video

const result = await cms.ai.generatePage('site_abc123', {
  prompt: 'Landing page for a bakery in Amsterdam',
  language: 'en',
  style: 'minimalist',
  useHeroVideo: true,
  videoModelId: 'seedance-fast', // optional: seedance-fast | seedance-standard | kling-standard
});

console.log(result.jobId);
console.log(result.heroVideoGenerated); // true if video was successfully generated

Generate site with hero video

const result = await cms.ai.generateSite({
  name: 'The Golden Oven Bakery',
  prompt: 'A modern website for an artisan bakery',
  language: 'en',
  useHeroVideo: true,
  videoModelId: 'seedance-standard', // 2 credits, maximum quality
});

console.log(result.siteId);
console.log(result.heroVideoGenerated); // true if video was successfully generated
console.log(result.videoModel);         // 'seedance-standard'
console.log(result.videoCreditsUsed);   // 2

Available video models

Model IDNameCreditsDescription
seedance-fastFast1Quick generation, top-tier quality (default)
seedance-standardHigh quality2Maximum quality, longer generation time
kling-standardBudget1Good quality, lowest cost

Note: When useHeroVideo is omitted or set to false, no video is generated. Existing behavior (stock photos) remains unchanged. On lower plans (Free, Starter), the parameter is ignored. Without videoModelId, seedance-fast is used by default.

Domains

The cms.domains module provides domain registration, transfers, and status checks.

Check domain availability

const result = await cms.domains.checkAvailability('bakery-amsterdam.nl');

console.log(result.available);    // true
console.log(result.priceCents);   // 999 (€9.99)
console.log(result.freeWithPlan); // true if free with current plan

Register a domain

const domain = await cms.domains.register({
  domain: 'bakery-amsterdam.nl',
  siteId: 'site_abc123',
  registrant: {
    firstName: 'John',
    lastName: 'Smith',
    email: 'john@example.com',
    phone: '+31612345678',
    address: 'Keizersgracht 1',
    city: 'Amsterdam',
    postalCode: '1015AA',
    country: 'NL',
  },
});

console.log(domain.status);      // 'registered'
console.log(domain.nameservers); // ['ns1.cloudflare.com', ...]

List domains

const domains = await cms.domains.list();

for await (const domain of domains) {
  console.log(domain.domain, domain.status, domain.expiresAt);
}

Email

The cms.mail module provides mailbox management and DNS record information.

Create a mailbox

const mailbox = await cms.mail.createMailbox('site_abc123', {
  localPart: 'info',
  displayName: 'Info Bakery',
});

console.log(mailbox.email);    // 'info@bakery-amsterdam.nl'
console.log(mailbox.password); // one-time password — store it securely!
console.log(mailbox.imapHost); // IMAP server
console.log(mailbox.smtpHost); // SMTP server

List mailboxes

const mailboxes = await cms.mail.list('site_abc123');

for await (const mb of mailboxes) {
  console.log(mb.email, mb.active, mb.storageMb);
}

Get DNS records

const records = await cms.mail.getDnsRecords('site_abc123');

for (const record of records) {
  console.log(record.type, record.name, record.value, record.status);
}

SEO & Design Tokens

The cms.seo module provides tools to update SEO settings and design tokens.

Update site SEO

await cms.seo.updateSiteSeo('site_abc123', {
  siteTitle: 'Amsterdam Bakery — Fresh pastries every day',
  siteDescription: 'The best bakery in Amsterdam. Order online or visit us.',
  ogImage: 'https://cdn.example.com/og-bakery.jpg',
  robotsDirective: 'index,follow',
});

Update page SEO

await cms.seo.updatePageSeo('site_abc123', 'page_xyz789', {
  title: 'Sandwiches — Amsterdam Bakery',
  description: 'Discover our selection of fresh sandwiches.',
  canonicalUrl: 'https://bakery-amsterdam.nl/sandwiches',
});

Update design tokens

await cms.seo.updateDesignTokens('site_abc123', {
  colorPrimary: '#ff6600',
  fontHeading: 'Inter',
  radiusCard: '16px',
});

Push Notifications

await cms.push.sendCampaign('site_abc123', {
  title: 'Summer Sale 20%!',
  body: 'Order today and get 20% off everything.',
  url: 'https://bakery-amsterdam.nl/deals',
});

Webhooks

Create a webhook

const webhook = await cms.webhooks.create('site_abc123', {
  url: 'https://my-crm.com/hook',
  events: ['order.created', 'booking.created'],
  secret: 'my-secret-token',
});

console.log(webhook.id);     // webhook ID
console.log(webhook.events); // ['order.created', 'booking.created']

List webhooks

const webhooks = await cms.webhooks.list('site_abc123');

for await (const wh of webhooks) {
  console.log(wh.id, wh.url, wh.events);
}

Chatbot

Configure chatbot

await cms.chatbot.configure('site_abc123', {
  enabled: true,
  greeting: 'Hello! How can I help you?',
  primaryColor: '#2563eb',
  language: 'en',
});

Get chatbot configuration

const config = await cms.chatbot.getConfig('site_abc123');

console.log(config.enabled);      // true
console.log(config.greeting);     // 'Hello! How can I help you?'
console.log(config.primaryColor); // '#2563eb'
console.log(config.language);     // 'en'

Next steps

On this page