TypeScript SDK Examples
Complete End-to-End Example
This example shows the full workflow: creating an agent, running a job, and getting results.Copy
import { RoeClient } from 'roe-ai';
// Set your credentials as environment variables:
// export ROE_API_KEY="your-api-key-here"
// export ROE_ORGANIZATION_ID="your-organization-uuid"
async function main() {
// Initialize the client
const client = new RoeClient();
// Step 1: Create an agent
console.log('Creating agent...');
const agent = await client.agents.create({
name: 'Document Analyzer',
engineClassId: 'MultimodalExtractionEngine',
inputDefinitions: [
{
key: 'text',
data_type: 'text/plain',
description: 'Text to analyze',
},
],
engineConfig: {
model: 'gpt-5.2-2025-12-11',
instruction: 'Analyze the provided text and extract key insights.',
output_schema: {
type: 'object',
properties: {
summary: {
type: 'string',
description: 'Brief summary of the text',
},
key_insights: {
type: 'array',
items: { type: 'string' },
description: 'Key insights from the analysis',
},
sentiment: {
type: 'string',
description: 'Overall sentiment (positive/negative/neutral)',
},
},
required: ['summary', 'key_insights', 'sentiment'],
},
},
versionName: 'v1',
description: 'Initial version of document analyzer',
});
console.log(`✓ Created agent: ${agent.name}`);
console.log(` Agent ID: ${agent.id}`);
console.log(` Version ID: ${agent.current_version_id}`);
// Step 2: Run the agent with sample input
console.log('\nRunning agent job...');
const job = await client.agents.run({
agentId: agent.id,
inputs: {
text: 'Artificial intelligence is transforming industries worldwide. ' +
'Companies are leveraging AI to improve efficiency, reduce costs, ' +
'and create innovative products. However, ethical considerations ' +
'around data privacy and bias remain critical challenges.',
},
});
console.log(` Job ID: ${job.id}`);
// Step 3: Wait for results
console.log(' Waiting for results...');
const result = await job.wait();
// Step 4: Display results
console.log('\n✓ Job completed successfully!');
console.log('\nResults:');
result.outputs.forEach((output) => {
console.log(` ${output.key}: ${output.value}`);
});
console.log(`\n✓ Job completed in ${result.duration_seconds.toFixed(2)} seconds`);
}
main().catch((error) => {
console.error('Error:', error);
process.exit(1);
});
Authentication
Set credentials as environment variables:Copy
export ROE_API_KEY="your-api-key-here"
export ROE_ORGANIZATION_ID="your-organization-uuid"
Quick Start
Copy
import { RoeClient } from 'roe-ai';
const client = new RoeClient();
// List agents
const agents = await client.agents.listBaseAgents();
// Run an agent
const job = await client.agents.run({
agentId: 'your-agent-uuid',
inputs: { text: 'Hello world' }
});
const result = await job.wait();
result.outputs.forEach(output => {
console.log(`${output.key}: ${output.value}`);
});
Batch Processing
Copy
const batch = await client.agents.runMany({
agentId: 'agent-uuid',
inputsList: [
{ text: 'Analyze sentiment: I love this!' },
{ text: 'Analyze sentiment: This is terrible.' }
]
});
const results = await batch.wait();
results.forEach(result => {
console.log(result.outputs);
});
File Uploads
Copy
// File path (auto-upload)
const job = await client.agents.run({
agentId: 'agent-uuid',
document: 'path/to/file.pdf',
inputs: { text: 'Analyze this document' }
});
// Existing Roe file ID
const job2 = await client.agents.run({
agentId: 'agent-uuid',
document: 'file-uuid-here',
inputs: { text: 'Analyze this document' }
});