The @socialrouter/sdk package provides a typed client for the SocialRouter API. It handles authentication and error mapping, and types every call against the live service catalogue.

Installation

Quick example

What’s included

  • run(service, input): one generic entry point, typed per service
  • Typed per-service methods, grouped by platform: sr.reddit.subredditPosts({ … })
  • Correlated input types: a URL service takes url/urls, a query service takes query/queries, and mixing them is a compile error
  • Typed options per service: options: { sort: "top" } on reddit/subreddit.posts, and a compile error on a service that declares none
  • Catalogue access: listServices(), getService(), listSources()
  • Error classes per HTTP status (AuthenticationError, InsufficientCreditsError, RateLimitError)
  • Uses native fetch(), so Node.js 18+ is required
The service map is generated from the live registry at release time, so the SDK only offers services that are actually served.

Typed methods

sr.reddit.subredditPosts(input) and sr.run("reddit/subreddit.posts", input) are the same call.

Next steps

Client reference

All methods, parameters, and return types.

Error handling

Error classes and how to handle failures.