SDKs and snippets
Updated
There's no official SDK yet, but the API is plain HTTPS and JSON, so a small helper is enough.
curl
curl
curl "https://chatterapi.com/v1/reddit/search?q=best+crm+for+small+business&time=year&limit=5" \
-H "Authorization: Bearer $CHATTERAPI_KEY"JavaScript
Here's a helper that reads error.code and retryable and backs off on retryable errors:
client.mjs
// A small client with retries. Node 18+ or any runtime with fetch.
const BASE = "https://api.chatterapi.com/v1";
export async function call(path, params = {}, { retries = 3 } = {}) {
const url = new URL(BASE + path);
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, String(v));
for (let attempt = 0; ; attempt++) {
const res = await fetch(url, { headers: { Authorization: `Bearer ${process.env.CHATTERAPI_KEY}` } });
const body = await res.json();
if (res.ok) return body; // { data, page?, credits, requestId, cached }
const { code, message, retryable } = body.error;
if (!retryable || attempt >= retries) throw new Error(`${code}: ${message} (${body.requestId})`);
const wait = Number(res.headers.get("retry-after")) * 1000 || 2 ** attempt * 500 + Math.random() * 250;
await new Promise((r) => setTimeout(r, wait));
}
}
// const { data, credits } = await call("/reddit/search", { q: "crm", limit: 10 });Python
client.py
# A small client with retries. Needs: pip install requests
import os, random, time, requests
BASE = "https://api.chatterapi.com/v1"
def call(path, params=None, retries=3):
for attempt in range(retries + 1):
r = requests.get(
BASE + path,
params=params or {},
headers={"Authorization": f"Bearer {os.environ['CHATTERAPI_KEY']}"},
timeout=30,
)
body = r.json()
if r.ok:
return body # { data, page?, credits, requestId, cached }
err = body["error"]
if not err["retryable"] or attempt == retries:
raise RuntimeError(f"{err['code']}: {err['message']} ({body['requestId']})")
wait = float(r.headers.get("retry-after") or (2 ** attempt) * 0.5 + random.random() / 4)
time.sleep(wait)
# body = call("/reddit/search", {"q": "crm", "limit": 10})Generate a client from OpenAPI
The spec at https://chatterapi.com/openapi.json describes every live tool, and you can point a generator at it:
TypeScript
npx @openapitools/openapi-generator-cli generate \
-i https://chatterapi.com/openapi.json -g typescript-fetch -o ./chatterapi-clientPython
pipx run openapi-python-client generate --url https://chatterapi.com/openapi.jsonWe don't support generated clients. If one behaves oddly, compare what it does with the raw HTTP call.