TypeScript SDK
The @shiba/sdk package is a zero-runtime-dependency fetch client for Shiba’s public API. Types are generated from GET /api/v1/openapi.json on your Worker (apps/backend/src/v1/openapi.json in the repo).
Install (monorepo)
Section titled “Install (monorepo)”pnpm add @shiba/sdkWhen published, the package will ship as @shiba/sdk under the AGPL-3.0-only license (same as the rest of Shiba).
Authentication
Section titled “Authentication”Mint an org-scoped API key in Settings → API keys (shk_…). Pass it as a Bearer token:
import { Shiba } from "@shiba/sdk";
const shiba = new Shiba({ baseUrl: "https://your-worker.example.com", apiKey: process.env.SHIBA_API_KEY!,});baseUrl is the Worker origin without /api/v1; the client adds that prefix.
Threads
Section titled “Threads”// Idempotent create — requestId is generated when omittedconst receipt = await shiba.threads.create({ repoUrl: "https://github.com/acme/repo", task: "Fix the flaky test",});
const threads = await shiba.threads.list();const thread = await shiba.threads.get("run-id");
await shiba.threads.send("run-id", { text: "Also update the README", delivery: "queue", // or "interrupt"});Event stream (SSE)
Section titled “Event stream (SSE)”for await (const event of shiba.threads.stream(threadId)) { console.log(event.type, event.data);}The iterator reconnects with Last-Event-ID after transient disconnects. Pass { reconnect: false } to stop after the first connection.
Pull requests
Section titled “Pull requests”Read-only helpers wrap the thread-scoped PR routes:
const status = await shiba.pullRequests.status(threadId);const comments = await shiba.pullRequests.comments(threadId);const review = await shiba.pullRequests.review(threadId);Errors and retries
Section titled “Errors and retries”Failed responses throw ShibaApiError with status and a redacted body (API keys and bearer tokens are stripped). Idempotent requests (GET, thread create with requestId, and send with clientKey) retry on 408, 429, and 5xx with exponential backoff.
Regenerating types
Section titled “Regenerating types”When apps/backend/src/v1/openapi.json changes:
pnpm -C packages/sdk generate:typespnpm -C packages/sdk check:types # CI sync checkExamples
Section titled “Examples”Runnable samples live under packages/sdk/examples/ in the repository.
