# SDKs

Two official clients, with no runtime dependencies: `@wyroapi/sdk` (Node.js 18+, TypeScript, ESM and CommonJS) and `wyro` (Python 3.9+).

```
npm install @wyroapi/sdk
pip install wyro
```

## Node.js / TypeScript

```ts
import { Wyro } from "@wyroapi/sdk";

const wyro = new Wyro({ apiKey: process.env.WYRO_API_KEY });

const post = await wyro.posts.create(
  { text: "…", platforms: ["instagram"], media: [{ url: "https://…/a.jpg" }] },
  { idempotencyKey: crypto.randomUUID() },
);
console.log(post.status, post.preview_url);

for await (const p of wyro.posts.iterate()) console.log(p.id, p.status);
```

## Python

```python
import os, uuid
from wyro import Wyro

wyro = Wyro(api_key=os.environ["WYRO_API_KEY"])

post = wyro.posts.create(
    {"text": "…", "platforms": ["instagram"], "media": [{"url": "https://…/a.jpg"}]},
    idempotency_key=str(uuid.uuid4()),
)
print(post["status"], post["preview_url"])

for p in wyro.posts.iterate():
    print(p["id"], p["status"])
```

## What they include

- **Posts**: create, get, list (with `next_cursor` pagination or an iterator), reschedule, cancel, and `bulk(csv, { dryRun })` for a CSV. **Queue**: get, set and next free slots. **Limited keys**: create, list and revoke.
- **Accounts**: list and disconnect. **Connect**: the link to connect a real account.
- **Metrics**: `posts.metrics(id)`, `accounts.metrics(id, range)` and `analytics.overview(range)`.
- **Media**: direct upload (up to 4 MB) and a helper for the presigned upload of larger files.
- **Webhooks**: set, get, delete, and `verifySignature(secret, timestamp, body, signature)`.
- **Partners**: create, list, get and delete client workspaces, rotate their key, and `forClient(externalId)` to act for a client with your partner token:

```ts
const client = wyro.forClient("client-123"); // partner token + X-Wyro-External-Id
await client.posts.create({ text: "…", platforms: ["linkedin"] });
```

- **Errors** as a typed exception (`WyroError`) with `code`, `message`, `fix`, `status` and `details` ([catalog](https://wyroapi.com/en/docs/errors)).
- **Retries** on `429` and `5xx`, honoring `Retry-After` ([limits](https://wyroapi.com/en/docs/limits)); creates are retried only when you pass an `idempotencyKey` ([idempotency](https://wyroapi.com/en/docs/idempotency)).

## Verify a webhook

```ts
import { verifySignature } from "@wyroapi/sdk";

const ok = verifySignature(secret, req.headers["x-wyro-timestamp"], rawBody, req.headers["x-wyro-signature"]);
```
