MindStudio Docs
  • Get Started
    • Overview
    • MindStudio Chrome Extension
    • Quickstart Guide
    • What is an AI Agent?
    • AI Agent Use Cases
  • Free vs. Paid AI Agents
  • Building AI Agents
    • Editor Overview
    • Workflow Generator
    • Writing Prompts
      • Templating
    • AI Models
    • Variables
      • Working with JSON
      • Using Handlebars Templating
    • Dynamic Variables
    • Data Sources
    • Automations
      • Start Block
      • Generate Text Block
      • Generate Image Block
      • Generate Chart Block
      • Generate Asset Block
      • Display Content Block
      • Text to Speech Block
      • Analyze Image Block
      • User Input Block
      • User Context Block
      • Query Data Block
      • Run Function Block
      • Scrape URL Block
      • Extract Text from File Block
      • Post to Slack Block
      • Menu Block
      • Logic Block
      • Checkpoint Block
      • Jump Block
      • Run Workflow Block
      • Terminator Block
    • Integrations
      • Search Bluesky Posts
      • Scrape Facebook Page
      • Scrape Meta Threads Profile
      • Scrape Instagram Comments
      • Scrape Instagram Mentions
      • Scrape Instagram Posts
      • Scrape Instagram Profile
      • Scrape Instagram Reels
      • Create LinkedIn Post
      • Create X Post
      • Search X Posts
      • Search Google
      • Search Google Images
      • Search Google Trends
      • Search Google News
      • Create Google Doc
      • Fetch Google Doc
      • Update Google Doc
      • Create Google Sheet
      • Fetch Google Sheet
      • Update Google Sheet
      • Enrich Company via Domain
      • Find Contact Email for Website
      • Find Email
      • Verify Email
      • Enrich Person via Email
      • Fetch YouTube Captions
      • Fetch YouTube Channel
      • Fetch YouTube Comments
      • Fetch YouTube Video
      • Search YouTube
      • Search YouTube Trends
      • Create Notion Page
      • Update Notion Page
      • Apify
      • Run Scenario
      • Post to Slack
      • HTTP Request
      • Run Node
      • Create Contact
      • Add Note
      • Send Email
      • Send SMS
    • Packaged Workflows
    • Publishing & Versioning
  • Embedding AI Agents
  • Using Webhooks
  • Workspace Management
    • Workspace Overview
    • Workspace Settings
    • Usage Explorer
    • Billing Settings
    • Account Settings
    • Team Settings & Access Controls
  • Test & Evaluate
    • Testing Suite Overview
    • Evaluations
    • Profiler
    • Debugger
  • Integration Guides
    • Zapier + MindStudio
    • Make.com + MindStudio
    • n8n + MindStudio
  • Developers
    • API Reference
    • NPM Package
    • Custom Workflow Functions
  • Additional Resources
    • Glossary
    • Allowing Access to Mindstudio From Your Network
  • Solutions
    • MindStudio Solutions Partners
    • MindStudio For Developers
    • MindStudio for Enterprises
Powered by GitBook
On this page
  • Quick Start
  • 1. Install the Package
  • 2. Get Your API Key
  • 3. Choose Your Usage Pattern
  • Response Format
  • CLI Commands
  • sync
  • test
  • list
  • Team Usage
  • 1. Project Owner:
  • 2. Team Members:
  • Optional: Add to package.json for automatic type generation:
  • Installation & Setup
  • Environment Variables
  • TypeScript Configuration
  • Error Handling
  • Common Issues
  • Best Practices
  • 1. API Key Security
  • 2. Type Safety
  • 3. Error Handling
Export as PDF
  1. Developers

NPM Package

Integrate MindStudio's AI Agents into your Node.js projects.

Last updated 2 months ago

The is your toolkit for integrating AI-powered workflows seamlessly into any application. This client library offers type-safe interfaces to help you execute MindStudio AI Agents with ease and confidence.

Quick Start

1. Install the Package

npm install mindstudio

2. Get Your API Key

  • Go to

  • Create a new API key

3. Choose Your Usage Pattern

Option A: Type-Safe Usage (Recommended)

**// Initialize the client
const client = new MindStudio(process.env.MINDSTUDIO_KEY);

// Execute a workflow
const { success, result } = await client.workers.myWorker.generateText({
  prompt: "Write a story about a space cat"
});

// Handle the response
if (success) {
  console.log(result);
}**

Option B: Direct Usage

**import { MindStudio } from 'mindstudio';

const client = new MindStudio(process.env.MINDSTUDIO_KEY);
const { success, result } = await client.run({
  workerId: "your-worker-id",
  workflow: "generateText",
  variables: {
    prompt: "Write a story about a space cat"
  }
});**

Response Format

All workflow executions return a consistent response type:

interface WorkflowResponse<T> {
  success: boolean;
  result?: T;          // The workflow result when success is true
  error?: Error;       // Error details when success is false
  billingCost?: string // Execution cost in credits
}

CLI Commands

sync

Generate type definitions for type-safe usage:

# With API key in environment
npx mindstudio sync

# With explicit API key
npx mindstudio sync --key your-api-key

# From existing config (CI environments)
npx mindstudio sync --offline

test

Test a workflow from the command line:

npx mindstudio test --worker myWorker --workflow generateText --input '{"prompt":"Hello"}'

list

List available Agents and workflows:

# List from existing configuration
npx mindstudio list

# List from API (if no configuration exists)
npx mindstudio list --key your-api-key

Team Usage

1. Project Owner:

**npx mindstudio sync
git add .mindstudio.json
git commit -m "Add MindStudio configuration"**

2. Team Members:

**npm install
npx mindstudio sync --offline**

Optional: Add to package.json for automatic type generation:

{
  "scripts": {
    "postinstall": "npx mindstudio sync --offline"
  }
}

Installation & Setup

Environment Variables

MindStudio requires an API key for authentication. You can provide it in several ways:

Option 1: In your shell

export MINDSTUDIO_KEY=your-api-key

Option 2: In your .env file

MINDSTUDIO_KEY=your-api-key
MINDSTUDIO_BASE_URL=https://custom-api-endpoint.com

Option 3: Pass directly to your CLI commands

npx mindstudio sync --key your-api-k

For security best practices:

  • Never commit API keys to version control

  • Add .env to your .gitignore

  • Use environment variables in CI/CD environments

TypeScript Configuration

{
  "compilerOptions": {
    "esModuleInterop": true,
    "resolveJsonModule": true
  }
}

Error Handling

// Workflow errors
const { success, result, error } = await client.workers.myWorker.generateText({
  prompt: "Hello"
});

if (!success) {
  console.error('Workflow failed:', error);
  return;
}

// Client errors
try {
  const client = new MindStudio('invalid-key');
} catch (error) {
  if (error instanceof MindStudioError) {
    console.error('Client error:', error.message);
  }
}

Common Issues

"Type-safe workers not available"

Run npx mindstudio sync to generate type definitions

"API key is required"

Ensure MINDSTUDIO_KEY is set in your environment or passed to the constructor

"Failed to load configuration"

Run npx mindstudio sync to create initial configuration


Best Practices

1. API Key Security

  • Store API keys in environment variables

  • Use .env files only for local development

  • Never commit API keys to version control

  • Use secure environment variables in CI/CD

2. Type Safety

  • Use the type-safe pattern when possible

  • Commit .mindstudio.json to version control

  • Run sync after pulling changes

3. Error Handling

  • Always check success before using result

  • Implement proper error handling

  • Use TypeScript for better type safety


License

MIT

MindStudio NPM Package
MindStudio Developer Settings