JavaScript & TypeScript SDK

Type-safe client for Node.js and browsers with streaming support, automatic retries, and full IDE autocomplete.

View on GitHub

Installation

Install the SDK using your preferred package manager:

# npm
npm install taskforceai-sdk
# Bun
bun add taskforceai-sdk
# yarn
yarn add taskforceai-sdk

Quick Start

Initialize the client and run a task:

import
{ TaskForceAI }
from
'taskforceai-sdk'
;

const
client =
new
TaskForceAI({
apiKey:
'your-api-key'

});

// Submit a task and wait for the result

const
taskId =
await
client.submitTask(
'Analyze this repository'
);
const
result =
await
client.waitForCompletion( taskId);

console.log(result.result);

Basic Usage

Use runTask to submit and wait for completion in one call:

// Submit and wait for result in one call

const
result =
await
client.runTask(
'What is the capital of France?'

);
console.log(result.result);

// Or use options for more control

const
taskId =
await
client.submitTask(
'Complex analysis task'
,
{
modelId:
'xai/grok-4.1'
,
silent:
true

}
);

Streaming Status Updates

Stream task status updates in real-time:

// Stream status updates as task progresses

const
stream = client.runTaskStream(
'Analyze this codebase'
);

for await
(
const
status
of
stream) {
console.log(
`$
{status.status}
: $
{status.result ??
'...'
}
`
);
}

// Cancel locally if needed

// stream.cancel();

Configuration Options

OptionTypeDescription
apiKeystringYour TaskForceAI API key (required)
baseURLstringCustom API endpoint URL
timeoutnumberRequest timeout in milliseconds
maxRetriesnumberMaximum number of retry attempts
mockModebooleanEnable mock mode for local development (default: false)

Mock Mode

Build and test your integration without an API key using mock mode:

import
{ TaskForceAI }
from
'taskforceai-sdk'
;

// No API key required in mock mode

const
client =
new
TaskForceAI({
mockMode:
true

});

const
result =
await
client.runTask(
'Test your integration'
);
console.log(result.result);
// "This is a mock response. Configure your API key to get real results."

Mock mode simulates the full task lifecycle locally—no network requests are made.

TypeScript Support

The SDK is written in TypeScript and provides full type definitions. All methods and responses are fully typed for the best developer experience.

import
{ TaskForceAI, TaskSubmissionOptions }
from
'taskforceai-sdk'
;

const
options: TaskSubmissionOptions = {
modelId:
'xai/grok-4.1'
,
silent:
true

};

// Fully typed result

const
result =
await
client.runTask(
'Hello!'
, options);

Next Steps