Use the TypeScript or Python SDK
Install the official TypeScript or Python SDK to discover tools, inspect prices and run tasks with built-in retries and spending guards.
View as MarkdownInstall the SDK
Both SDKs read PURRKEY_API_KEY from the environment by default and generate their types from the public Purrkey OpenAPI contract. The TypeScript package runs in Node.js 20+, Bun, Deno and modern browsers. The Python package requires Python 3.10+ and includes both sync and async clients.
Shell
# TypeScript / JavaScript
npm install @purrkey/sdk
# Python
pip install purrkeyTypeScript quickstart
discover() and inspect() are free. run() inspects the tool, submits the Run with an idempotency key and spending cap, and waits for a final status.
TypeScript
import { Purrkey } from "@purrkey/sdk";
const purrkey = new Purrkey(); // reads PURRKEY_API_KEY
// 1. Find a tool (free)
const { candidates } = await purrkey.discover({ query: "tiktok video search" });
// 2. Read its schema and price (free)
const tool = await purrkey.inspect({
toolId: "tikhub.tiktok.app.v3.fetch_video_search_result",
});
console.log(tool.tool.price);
// 3. Run it and wait for the result
const run = await purrkey.run({
toolId: "tikhub.tiktok.app.v3.fetch_video_search_result",
input: { query: { keyword: "matcha latte", count: 10 } },
});
console.log(run.status, run.billing.chargedMicros);
console.log(run.result.output);Python quickstart
Use Purrkey for synchronous code or AsyncPurrkey with asyncio. Responses are plain dictionaries typed with TypedDicts from purrkey.types.
Python
from purrkey import Purrkey
with Purrkey() as purrkey: # reads PURRKEY_API_KEY
# 1. Find a tool (free)
candidates = purrkey.discover("google maps reviews")["candidates"]
# 2. Read its schema and price (free)
tool = purrkey.inspect("tikhub.tiktok.app.v3.fetch_video_search_result")
print(tool["tool"]["price"])
# 3. Run it and wait for the result
run = purrkey.run(
"tikhub.tiktok.app.v3.fetch_video_search_result",
{"query": {"keyword": "matcha latte", "count": 10}},
)
print(run["status"], run["billing"]["chargedMicros"])
print(run["result"]["output"])Spending caps, retries and errors
| Rule | How the SDK handles it |
|---|---|
| Spending cap | For per-call tools, run() sets maxChargeMicros / max_charge_micros from the inspected unit price. For input-dependent pricing (per result, per URL, per credit), you must pass the cap explicitly or run() raises max_charge_required before charging. |
| Idempotency | Network errors, 429 and 5xx responses retry with the same idempotencyKey / idempotency_key so a task is not charged twice. Pass your own key to make retries safe across processes. |
| UNKNOWN outcomes | When a Run reports UNKNOWN, run() stops waiting and returns it without resubmitting. Check it later with getRun() / get_run(). |
| Errors | API and validation errors raise PurrkeyError with status, code, message and requestId / request_id. |