ComposioHQ/composio · error · Error

Composio client is not initialized. Please initialize it fir

Error message

Composio client is not initialized. Please initialize it first.

What it means

Composio.getClient() returns the ComposioClient, but the client is only set after initialization succeeds (e.g. via an init/initialize flow or first authenticated request). Calling getClient() before that throws this error — it guards against a half-constructed Composio instance.

Source

Thrown at ts/packages/core/src/composio.ts:411

    // instrument the provider since we are not using the provider class directly
    telemetry.instrument(
      this.provider,
      this.provider.name ?? this.provider.constructor.name ?? 'unknown'
    );

    // Check for the latest version of the Composio SDK from NPM.
    if (!this.config.disableVersionCheck) {
      checkForLatestVersionFromNPM(version);
    }
  }

  /**
   * Get the Composio SDK client.
   * @returns {ComposioClient} The Composio API client.
   */
  getClient(): ComposioClient {
    if (!this.client) {
      throw new Error('Composio client is not initialized. Please initialize it first.');
    }
    return this.client;
  }

  /**
   * Get the configuration SDK is initialized with.
   *
   * Returns a frozen shallow clone — the SDK has already snapshotted
   * configuration values such as `dangerouslyAllowAutoUploadDownloadFiles`,
   * `fileUploadDirs`, and `fileDownloadDir` into its internal models, so
   * mutating the live config object would silently no-op. Freezing makes
   * that contract visible at the call site instead of letting the mutation
   * appear successful.
   *
   * @returns {Readonly<ComposioConfig<TProvider>>} The frozen configuration
   *   the SDK is initialized with.
   */
  getConfig(): Readonly<ComposioConfig<TProvider>> {

View on GitHub (pinned to 64b1b85502)

Solutions

  1. Await the initialization flow before calling getClient()
  2. Check initialization state (e.g. a isInitialized flag or that init didn't throw) before access
  3. Re-run init with a valid API key if it previously failed
  4. Store the client returned by init rather than re-fetching it eagerly

Example fix

// before
const composio = new Composio({ apiKey });
const client = composio.getClient(); // may throw
// after
const composio = new Composio({ apiKey });
await composio.init(); // complete initialization first
const client = composio.getClient();
Defensive patterns

Strategy: validation

Validate before calling

if (!composio.isInitialized) await composio.init(); // or await whatever init flow you use
const client = composio.getClient();

Type guard

const ready = (c: Composio): boolean => (c as any).client != null;

Try / catch

try { composio.getClient(); } catch (e) { if (e.message.includes('not initialized')) await initThenRetry(); }

Prevention

When it happens

Trigger: Calling composio.getClient() immediately after constructing Composio without awaiting initialization; using the instance in code that runs before async init completes; accessing getClient() after a failed init left client null.

Common situations: Top-level code executing before await init; race conditions in app startup; init failed silently earlier and later code assumes success.

Related errors


AI-assisted analysis of ComposioHQ/composio@64b1b85502 (2026-08-28). Data as JSON: /api/errors/cff61757ec707a8b. Report an issue: GitHub.