JavaScript SDK
The official JavaScript SDK for integrating Bleu AI workflows into Node.js applications.
Installation
npm install @bleuai/sdk
Quick Start
const { BleuAI } = require('@bleuai/sdk');
// Initialize client with your API key
const client = new BleuAI(process.env.BLEU_API_KEY);
// Run a workflow
const result = await client.runWorkflow('workflow-id', {
'Input Name': 'value' // Your workflow inputs
});
console.log(result.outputs);
Authentication
Getting Your API Key
- Visit buildbleu.com/api-keys
- Click "Create Key" and name it
- Copy immediately - it won't be shown again
Using Environment Variables
// .env file
BLEU_API_KEY=bleu_xxxxxxxxxxxxxxxxxxxxx
// In your code
require('dotenv').config();
const client = new BleuAI(process.env.BLEU_API_KEY);
Security Warning
Never commit API keys to version control! If a key is leaked, revoke it immediately at buildbleu.com/api-keys
Error Handling
Status | Error Type | Description |
---|---|---|
401 | Authentication Error | Invalid or missing API key |
404 | Not Found | Workflow ID doesn't exist |
429 | Rate Limit | Too many requests |
500 | Server Error | Internal server error |
Example error handling:
try {
const result = await client.runWorkflow('workflow-id', inputs);
} catch (error) {
console.error(`Error ${error.status}: ${error.message}`);
}
TypeScript Support
import { BleuAI } from '@bleuai/sdk';
const client: BleuAI = new BleuAI(process.env.BLEU_API_KEY);
API Reference
Class: BleuAI
Main client for interacting with the Bleu AI API.
Constructor
new BleuAI(apiKey)
Creates a new Bleu AI client instance.
Parameters:
apiKey
(string, required): Your Bleu AI API key
Returns:
- BleuAI client instance
Example:
const client = new BleuAI('bleu_xxxxxxxxxxxxxxxxxxxxx');
Methods
runWorkflow(workflowId, inputs)
Executes a workflow with provided inputs.
Parameters:
workflowId
(string, required): The UUID of the workflow to executeinputs
(object, optional): Input parameters required by the workflow. Keys must match the workflow's input field names.
Returns:
Promise<WorkflowResult>
: Resolves to result object
Result Object Structure:
{
outputs: any, // Workflow outputs (structure depends on workflow)
status: string, // Execution status ('success', 'error')
executionTime: number // Execution time in milliseconds
}
Example:
const result = await client.runWorkflow('abc-123', {
'Text Input': 'Hello world',
'Count': 5
});
Throws:
- Error with
status
property for API errors - Network errors for connectivity issues
Best Practices
- Store API keys in environment variables
- Implement retry logic for transient errors
- Validate inputs before API calls
- Use try-catch blocks for all API operations
- Set appropriate timeouts for long-running workflows