REFERENCE
SDK reference
Complete reference for @taskclan/sdk. TypeScript-first, works in Node 18+, edge runtimes, and any server environment.
Installation
npm install @taskclan/sdknew Taskclan(options)
Creates a client. All requests inherit these defaults.
| Option | Type | Default | Description |
|---|---|---|---|
apiKey | string | , | Secret key (required). Server-side only. |
baseUrl | string | https://api.taskclan.com | Override the API host. |
defaultProfile | Profile | "t1-flow" | Profile used when a call omits one. |
timeout | number | 60000 | Request timeout in ms. |
maxRetries | number | 2 | Automatic retries for transient errors. |
import { Taskclan } from "@taskclan/sdk";
const taskclan = new Taskclan({
apiKey: process.env.TASKCLAN_API_KEY,
defaultProfile: "t1-flow",
});taskclan.run(params)
Runs a goal to completion and resolves with a RunResult.
| Param | Type | Description |
|---|---|---|
goal | string | What you want done (required). |
profile | "t1-auto" | "t1-core" | "t1-flow" | "t1-max" | Intelligence profile. Defaults to the client default. Auto routes per prompt; Max is a strict superset of Flow. |
input | Record<string, unknown> | Structured input the goal can reference. |
images | { url } | { base64, mediaType }[] | Image references. Every tier supports vision. |
videos | { url } | { base64, mediaType }[] | Video references. Routes through Max via Gemini 2.5 Pro; forces the Auto router to Max. |
audios | { url, format? } | { base64, format? }[] | Audio references. Routes through Max via Gemini 2.5 Pro; forces the Auto router to Max. |
tools | Tool[] | Typed tools the run may call. See Agents & tools. |
verify | boolean | Run the evaluation layer before returning. |
maxTokens | number | Upper bound on generated tokens. |
signal | AbortSignal | Cancel an in-flight run. |
RunResult
| Field | Type | Description |
|---|---|---|
id | string | Run identifier. |
output | string | Final text output. |
data | unknown | Structured output when produced. |
steps | StepTrace[] | Plan, tool calls and results. |
usage | { inputTokens, outputTokens, costUsd } | Usage & cost for the run. |
model | string | The model the profile routed to. |
taskclan.run.stream(params)
Same params as run(), but returns an async iterable of StreamEvents.
Event type | Payload | Emitted when |
|---|---|---|
plan | { steps } | The run forms a plan. |
text | { delta } | A chunk of output text is ready. |
tool_call | { name, input } | A tool is about to run. |
tool_result | { name, output } | A tool returned. |
done | { result } | The run finished; carries the RunResult. |
error | { error } | The run failed. |
const stream = await taskclan.run.stream({ goal: "Write a haiku about the sea" });
for await (const event of stream) {
if (event.type === "text") process.stdout.write(event.delta);
if (event.type === "done") console.log("\n", event.result.usage);
}tool(definition)
Defines a typed tool. See Agents & tools for the full pattern.
| Field | Type | Description |
|---|---|---|
name | string | Unique, snake_case identifier. |
description | string | What the tool does (the model reads this). |
input | ZodSchema | Input schema; validated before run. |
run | (input) => Promise<unknown> | Your handler. |
Studio & Engine namespaces
taskclan.studio.generate() / edit(), multimodal creation. See the Studio guide.taskclan.engine.run(workflow, options), deterministic workflows. See the Engine guide.
Errors
All failures throw a TaskclanError with a type, code, status, requestId, and a boolean retryable. A 402 also carries balance (credits remaining) and topUpUrl (where to recharge). See Errors & rate limits.
import { TaskclanError } from "@taskclan/sdk";
try {
await taskclan.run({ goal: "..." });
} catch (err) {
// Duck-typed (cross-realm safe, no instanceof needed):
if (TaskclanError.isInsufficientCredits(err)) {
// err.balance === 0, err.topUpUrl points at platform.taskclan.com/billing/recharge
return promptTopUp(err.topUpUrl);
}
if (err instanceof TaskclanError) {
console.error(err.status, err.code, err.requestId);
}
}| Field | Type | Notes |
|---|---|---|
type | string | Coarse class — one of authentication, insufficient_credits, invalid_request, rate_limit, api. |
status | number | HTTP status (402 for out-of-credits, 429 for rate limit, etc.). |
balance | number? | Wallet balance at failure time (present on 402). |
topUpUrl | string? | Where to recharge (present on 402). Appended to err.message too. |
requestId | string? | Correlate with server logs. |
retryable | boolean | true for 429 + 5xx; false for 402 (retrying an empty wallet won't help). |
TaskclanError.isInsufficientCredits(err) is the recommended way to detect a 402 — it works on any thrown value (including plain { status: 402 } objects), so cross-realm and bundler splits don't break the check.
