Skip to main content
Developer-friendly & type-safe TypeScript SDK for the Marble API. Built with automatic retries, pagination helpers, and full TypeScript support.

Installation

npm install @usemarble/sdk
This package is published with CommonJS and ES Modules (ESM) support.

Quick Start

import { Marble } from "@usemarble/sdk";

const marble = new Marble({
  apiKey: process.env["MARBLE_API_KEY"] ?? "",
});

async function run() {
  const result = await marble.posts.list({
    limit: 10,
    page: 1,
  });

  for await (const page of result) {
    console.log(page);
  }
}

run();

Authentication

The SDK uses API key authentication. Pass your API key when initializing the client:
import { Marble } from "@usemarble/sdk";

const marble = new Marble({
  apiKey: process.env["MARBLE_API_KEY"] ?? "",
});
Set the MARBLE_API_KEY environment variable and the SDK will automatically use it.

Available Resources

Posts

  • List all posts
  • Get a single post

Categories

  • List all categories
  • Get a single category

Tags

  • List all tags
  • Get a single tag

Authors

  • List all authors
  • Get a single author

Filtering Posts

Filter posts by categories, tags, or featured status:
const result = await marble.posts.list({
  featured: "true",
  categories: "tech,news",
  excludeCategories: "drafts",
  tags: "javascript,react",
  excludeTags: "outdated",
});
For a complete guide on filtering options and behavior, see the Filtering documentation.

Pagination

Paginated endpoints return an async iterable. Use for await...of to iterate through pages:
const result = await marble.posts.list({
  limit: 10,
  page: 1,
});

for await (const page of result) {
  console.log(page.posts);
  console.log(page.pagination);
}
For full pagination details and response fields, see the Pagination documentation.

Error Handling

The SDK provides typed error classes for different error scenarios:
import { Marble } from "@usemarble/sdk";
import * as errors from "@usemarble/sdk/models/errors";

const marble = new Marble({
  apiKey: process.env["MARBLE_API_KEY"] ?? "",
});

try {
  const result = await marble.posts.get("non-existent-slug");
} catch (error) {
  if (error instanceof errors.NotFoundError) {
    console.log("Post not found");
  } else if (error instanceof errors.MarbleError) {
    console.log(error.message);
    console.log(error.statusCode);
  }
}

Retries

The SDK automatically retries failed requests. You can customize retry behavior:
const marble = new Marble({
  apiKey: process.env["MARBLE_API_KEY"] ?? "",
  retryConfig: {
    strategy: "backoff",
    backoff: {
      initialInterval: 1,
      maxInterval: 50,
      exponent: 1.1,
      maxElapsedTime: 100,
    },
    retryConnectionErrors: false,
  },
});

Framework Guides

Additional Resources