# Social media TypeScript SDK
URL: https://skedcast.com/developers/sdk

@skedcast/sdk is SkedCast's social media TypeScript SDK: a typed, fetch-based client over the REST API, and the same client that powers the SkedCast console. A public npm package is on the way; until then, the REST API and OpenAPI spec are the supported external interface.

## Status: first-party social media TypeScript SDK (public npm package coming soon)
The SDK is currently used internally by SkedCast's own apps. External developers should integrate via the REST API (any language) or the OpenAPI spec today; the published npm package will follow.

## Construct the social media TypeScript SDK client
Create one client with `createSkedcast()`. It supports three auth modes — a cookie session (first-party browser), an OAuth bearer token, or a Developer API key — all over an injectable `fetch`.

## API-key mode (server-side).
```ts
import { createSkedcast } from "@skedcast/sdk";

const sk = createSkedcast({
  baseUrl: "https://api.skedcast.com/v1",
  apiKey: process.env.SKEDCAST_API_KEY, // sent as Authorization: Bearer sked_…
});

const { data } = await sk.clients.list({ limit: 10 });
```

## Resources & errors
Every resource exposes typed methods (`sk.posts.list()`, `sk.analytics.overview()`, …) returning `{ data }` (single) or `{ data, page }` (list). Non-2xx responses throw a typed `SkedcastApiError` carrying `status`, `code`, `category`, `detail`, and `correlationId`, plus predicates like `err.isRateLimited` and `err.isForbidden`.

## Example
```ts
import { SkedcastApiError } from "@skedcast/sdk";

try {
  await sk.posts.create({ clientId, content, targets, schedule });
} catch (err) {
  if (err instanceof SkedcastApiError && err.isRateLimited) {
    await wait(err.retryAfterSeconds ?? 1);
  } else throw err;
}
```

## FAQ
**Q: Can I install @skedcast/sdk from npm today?**
A: Not yet — it's a first-party package right now. Build against the REST API and OpenAPI spec in the meantime; the public npm release is planned.
