Skip to content

TypeScript Client Configuration Reference

This is the complete reference for all configuration options available in the runcycles TypeScript client.

CyclesConfig

All configuration is provided through the CyclesConfig constructor.

Required fields

FieldTypeDescription
baseUrlstringBase URL of the Cycles server (e.g., http://localhost:7878)
apiKeystringAPI key for authentication

Subject defaults

These fields set default values for the Subject used in withCycles calls. They apply to all guarded functions unless overridden at the HOF level.

FieldTypeDefaultDescription
tenantstring | undefinedundefinedDefault tenant
workspacestring | undefinedundefinedDefault workspace
appstring | undefinedundefinedDefault application name
workflowstring | undefinedundefinedDefault workflow
agentstring | undefinedundefinedDefault agent
toolsetstring | undefinedundefinedDefault toolset

HTTP timeouts

FieldTypeDefaultDescription
connectTimeoutnumber2000Connection timeout in milliseconds
readTimeoutnumber5000Read timeout in milliseconds

Note: Node's built-in fetch does not distinguish connection timeout from read timeout. connectTimeout and readTimeout are summed into a single AbortSignal.timeout() value (default: 7000ms total) that caps the entire request duration.

Retry configuration

Controls the commit retry engine for transient failures.

FieldTypeDefaultDescription
retryEnabledbooleantrueEnable automatic commit retries
retryMaxAttemptsnumber5Maximum number of retry attempts
retryInitialDelaynumber500Delay before the first retry (milliseconds)
retryMultipliernumber2.0Backoff multiplier between retries
retryMaxDelaynumber30000Maximum delay between retries (milliseconds)

How retry works

When a commit fails with a transport error or 5xx response, the retry engine schedules a retry using exponential backoff:

Attempt 1: wait 500ms
Attempt 2: wait 1000ms
Attempt 3: wait 2000ms
Attempt 4: wait 4000ms
Attempt 5: wait 8000ms (capped at retryMaxDelay)

Non-retryable errors (4xx responses) are not retried. Retries are fire-and-forget — the guarded function returns immediately while the commit is retried in the background.

Programmatic configuration

typescript
import { CyclesConfig } from "runcycles";

const config = new CyclesConfig({
  // Required
  baseUrl: "http://localhost:7878",
  apiKey: "cyc_live_...",

  // Subject defaults
  tenant: "acme",
  workspace: "production",
  app: "support-bot",

  // HTTP settings (milliseconds)
  connectTimeout: 2000,
  readTimeout: 5000,

  // Commit retry
  retryEnabled: true,
  retryMaxAttempts: 5,
  retryInitialDelay: 500,
  retryMultiplier: 2.0,
  retryMaxDelay: 30000,
});

Environment variable configuration

Use CyclesConfig.fromEnv() to load configuration from environment variables. The default prefix is CYCLES_:

typescript
const config = CyclesConfig.fromEnv();
Environment variableMaps toRequired
CYCLES_BASE_URLbaseUrlYes
CYCLES_API_KEYapiKeyYes
CYCLES_TENANTtenantNo
CYCLES_WORKSPACEworkspaceNo
CYCLES_APPappNo
CYCLES_WORKFLOWworkflowNo
CYCLES_AGENTagentNo
CYCLES_TOOLSETtoolsetNo
CYCLES_CONNECT_TIMEOUTconnectTimeoutNo
CYCLES_READ_TIMEOUTreadTimeoutNo
CYCLES_RETRY_ENABLEDretryEnabledNo
CYCLES_RETRY_MAX_ATTEMPTSretryMaxAttemptsNo
CYCLES_RETRY_INITIAL_DELAYretryInitialDelayNo
CYCLES_RETRY_MULTIPLIERretryMultiplierNo
CYCLES_RETRY_MAX_DELAYretryMaxDelayNo

A custom prefix can be passed: CyclesConfig.fromEnv("MY_PREFIX_") reads MY_PREFIX_BASE_URL, MY_PREFIX_API_KEY, etc.

Setting a default client

Instead of passing client to every withCycles call, set a module-level default:

typescript
import { CyclesClient, CyclesConfig, setDefaultClient, setDefaultConfig } from "runcycles";

// Option 1: Set a config (client created lazily on first invocation)
setDefaultConfig(new CyclesConfig({
  baseUrl: "http://localhost:7878",
  apiKey: "cyc_live_...",
  tenant: "acme",
}));

// Option 2: Set an explicit client
setDefaultClient(new CyclesClient(new CyclesConfig({
  baseUrl: "http://localhost:7878",
  apiKey: "cyc_live_...",
})));

Client resolution is deferred to the first invocation and then cached — the wrapper binds permanently to the resolved client after its first call. A later setDefaultClient() call will not affect already-invoked wrappers.

Resolution order

For each Subject field, the HOF resolves the value using this priority:

  1. HOF parameter — if set in the withCycles options, it wins
  2. Config default — if set on the CyclesConfig instance

If neither provides a value, the field is omitted from the request.

Disabling retry

typescript
const config = new CyclesConfig({
  baseUrl: "http://localhost:7878",
  apiKey: "cyc_live_...",
  retryEnabled: false,
});

Aggressive retry for critical commits

typescript
const config = new CyclesConfig({
  baseUrl: "http://localhost:7878",
  apiKey: "cyc_live_...",
  retryMaxAttempts: 10,
  retryInitialDelay: 200,
  retryMultiplier: 1.5,
  retryMaxDelay: 60000,
});

Next steps