# 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. ## Install 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. ``` # TypeScript / JavaScript npm install @purrkey/sdk # Python pip install purrkey ``` - [Create an API key](/keys): Create a key and export it as PURRKEY_API_KEY in your environment. - [@purrkey/sdk on npm](https://www.npmjs.com/package/@purrkey/sdk): Official TypeScript and JavaScript package. - [purrkey on PyPI](https://pypi.org/project/purrkey/): Official Python package with sync and async clients. ## TypeScript 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. ``` 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); ``` - [purrkey/purrkey-js on GitHub](https://github.com/purrkey/purrkey-js): Source code, full method list and TypeScript types. ## Python quickstart Use Purrkey for synchronous code or AsyncPurrkey with asyncio. Responses are plain dictionaries typed with TypedDicts from purrkey.types. > For async code, import AsyncPurrkey and use async with AsyncPurrkey() as purrkey: await purrkey.run(...). ``` 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"]) ``` - [purrkey/purrkey-python on GitHub](https://github.com/purrkey/purrkey-python): Source code, async examples and Python type definitions. ## 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. | - [Pricing and spending limits](/docs/guides/billing): Understand pricing units, caps and held funds. - [Runs, retries and cancellation](/docs/guides/runs): Recover interrupted calls without duplicate charges. - [API reference](/docs/api/overview): Underlying HTTP endpoints and response schemas.