Send multiple traces in a single call using sendBatch().

Basic Usage

import { InfiniumClient } from 'infinium-o2';

const client = new InfiniumClient({ agentId: '...', agentSecret: '...' });

const tasks = documents.map((doc) => ({
  name: `Summarize: ${doc.title.slice(0, 60)}`,
  description: `2-sentence summary of '${doc.title}'`,
  currentDatetime: client.getCurrentIsoDatetime(),
  duration: doc.duration,
  inputSummary: `Document: ${doc.title}`,
  outputSummary: doc.summary,
  llmUsage: {
    model: 'gpt-4o',
    provider: 'openai',
    promptTokens: doc.usage.prompt_tokens,
    completionTokens: doc.usage.completion_tokens,
    apiCallsCount: 1,
  },
}));

const result = await client.sendBatch(tasks);
console.log(`Sent ${result.successfulTasks}/${result.totalTasks} traces`);

Batch Limits

Maximum 100 tasks per batch call.

InfiniumClient.sendBatch()

Processes tasks sequentially:

const result = await client.sendBatch(tasks);
ParameterTypeDescription
tasksTaskData[]Array of tasks (max 100)

AsyncInfiniumClient.sendBatch()

Processes tasks concurrently via Promise.all():

const asyncClient = new AsyncInfiniumClient({ agentId: '...', agentSecret: '...' });
const result = await asyncClient.sendBatch(tasks);

Rate limiting is applied per-request via the built-in rate limiter.

AsyncInfiniumClient.sendBatchSequential()

Processes tasks one at a time for strict rate control:

const result = await asyncClient.sendBatchSequential(tasks);

BatchResult

The return value:

FieldTypeDescription
totalTasksnumberTotal tasks in the batch
successfulTasksnumberNumber sent successfully
failedTasksnumberNumber that failed
resultsApiResponse[]Individual response per task
errorsstring[]Error messages for failures

Error Handling

Individual task failures don’t stop the batch. Check BatchResult to see which tasks succeeded:

const result = await client.sendBatch(tasks);

result.results.forEach((resp, i) => {
  if (!resp.success) {
    console.error(`Task ${i} failed: ${resp.message}`);
  }
});

For catastrophic batch failures, a BatchError exception is raised:

import { BatchError } from 'infinium-o2';

try {
  const result = await client.sendBatch(tasks);
} catch (error) {
  if (error instanceof BatchError) {
    console.error(`Batch failed: ${error.failedTasks}/${error.totalTasks}`);
    error.errors?.forEach((e) => console.error(`  - ${e}`));
  }
}

Choosing a Strategy

StrategyClientThroughputRate Safety
sendBatch()InfiniumClientSequentialSafe
sendBatch()AsyncInfiniumClientConcurrentRate-limited
sendBatchSequential()AsyncInfiniumClientSequentialSafest