TASKCLANQuickstart ↗

REFERENCE

SDK reference

Complete reference for @taskclan/sdk. TypeScript-first, works in Node 18+, edge runtimes, and any server environment.

Installation

npm install @taskclan/sdk

new Taskclan(options)

Creates a client. All requests inherit these defaults.

OptionTypeDefaultDescription
apiKeystring, Secret key (required). Server-side only.
baseUrlstringhttps://api.taskclan.comOverride the API host.
defaultProfileProfile"t1-flow"Profile used when a call omits one.
timeoutnumber60000Request timeout in ms.
maxRetriesnumber2Automatic 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.

ParamTypeDescription
goalstringWhat 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.
inputRecord<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.
toolsTool[]Typed tools the run may call. See Agents & tools.
verifybooleanRun the evaluation layer before returning.
maxTokensnumberUpper bound on generated tokens.
signalAbortSignalCancel an in-flight run.

RunResult

FieldTypeDescription
idstringRun identifier.
outputstringFinal text output.
dataunknownStructured output when produced.
stepsStepTrace[]Plan, tool calls and results.
usage{ inputTokens, outputTokens, costUsd }Usage & cost for the run.
modelstringThe model the profile routed to.

taskclan.run.stream(params)

Same params as run(), but returns an async iterable of StreamEvents.

Event typePayloadEmitted 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.

FieldTypeDescription
namestringUnique, snake_case identifier.
descriptionstringWhat the tool does (the model reads this).
inputZodSchemaInput 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);
  }
}
FieldTypeNotes
typestringCoarse class — one of authentication, insufficient_credits, invalid_request, rate_limit, api.
statusnumberHTTP status (402 for out-of-credits, 429 for rate limit, etc.).
balancenumber?Wallet balance at failure time (present on 402).
topUpUrlstring?Where to recharge (present on 402). Appended to err.message too.
requestIdstring?Correlate with server logs.
retryablebooleantrue 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.