description |
---|
Integrate MindStudio's AI Workers into your Node.js projects. |
The MindStudio NPM Package 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 Workers with ease and confidence.
npm install mindstudio
- Go to MindStudio Developer Settings
- Create a new API key
**// 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);
}**
**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"
}
});**
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
}
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 a workflow from the command line:
npx mindstudio test --worker myWorker --workflow generateText --input '{"prompt":"Hello"}'
List available workers and workflows:
# List from existing configuration
npx mindstudio list
# List from API (if no configuration exists)
npx mindstudio list --key your-api-key
**npx mindstudio sync
git add .mindstudio.json
git commit -m "Add MindStudio configuration"**
**npm install
npx mindstudio sync --offline**
{
"scripts": {
"postinstall": "npx mindstudio sync --offline"
}
}
MindStudio requires an API key for authentication. You can provide it in several ways:
export MINDSTUDIO_KEY=your-api-key
MINDSTUDIO_KEY=your-api-key
MINDSTUDIO_BASE_URL=https://custom-api-endpoint.com
npx mindstudio sync --key your-api-k
- Never commit API keys to version control
- Add
.env
to your.gitignore
- Use environment variables in CI/CD environments
{
"compilerOptions": {
"esModuleInterop": true,
"resolveJsonModule": true
}
}
// 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);
}
}
Run npx mindstudio sync
to generate type definitions
Ensure MINDSTUDIO_KEY
is set in your environment or passed to the constructor
Run npx mindstudio sync
to create initial configuration
- 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
- Use the type-safe pattern when possible
- Commit
.mindstudio.json
to version control - Run
sync
after pulling changes
- Always check
success
before usingresult
- Implement proper error handling
- Use TypeScript for better type safety
MIT