Add individual test cases when you need precise control:
Copy
// Add a single itemconst item = await client.datasets.addItem(dataset.id, { input: { customer_name: 'John', question: 'How do I cancel my subscription?', }, expectedOutput: 'To cancel your subscription, go to Account > Subscription > Cancel. Your access will continue until the end of your billing period.', metadata: { category: 'billing', difficulty: 'easy', source: 'support_tickets', },});console.log('Added item:', item.id);
// Add multiple items in one callawait client.datasets.addItems(dataset.id, [ { input: { question: 'What is the pricing?' }, expectedOutput: 'Our plans start at $9/month for Basic, $29/month for Pro, and custom pricing for Enterprise.', metadata: { category: 'pricing' }, }, { input: { question: 'Is there a free trial?' }, expectedOutput: 'Yes, we offer a 14-day free trial with full access to all Pro features. No credit card required.', metadata: { category: 'pricing' }, }, { input: { question: 'How do I contact support?' }, expectedOutput: 'You can reach our support team via email at [email protected], live chat on our website, or phone at 1-800-EXAMPLE.', metadata: { category: 'support' }, }, { input: { question: 'What payment methods do you accept?' }, expectedOutput: 'We accept all major credit cards (Visa, MasterCard, American Express), PayPal, and bank transfers for Enterprise plans.', metadata: { category: 'billing' }, },]);console.log('Dataset now has', dataset.itemCount, 'items');
[ { "input": { "customer_name": "Alice", "question": "How do I upgrade my account?" }, "expectedOutput": "Visit Account Settings and click Upgrade Plan.", "metadata": { "category": "account", "priority": "high" } }, { "input": { "customer_name": "Bob", "question": "Can I get a refund?" }, "expectedOutput": "Refunds are available within 30 days of purchase.", "metadata": { "category": "billing", "priority": "medium" } }]
Create a copy of an existing dataset for iteration or A/B testing:
Copy
// Clone with a new nameconst cloned = await client.datasets.clone(originalDatasetId, { name: 'Support Cases v2', description: 'Updated version with additional edge cases',});console.log('Cloned dataset:', cloned.id);console.log('Items copied:', cloned.itemCount);// Now add new items to the cloneawait client.datasets.addItems(cloned.id, [ { input: { question: 'New edge case question' }, expectedOutput: 'Expected response for edge case', },]);
// Export to JSONconst data = await client.datasets.export(dataset.id);// Save to filefs.writeFileSync( 'dataset-backup.json', JSON.stringify(data, null, 2));console.log('Exported', data.items.length, 'items');
// Update a single itemawait client.datasets.updateItem(datasetId, itemId, { expectedOutput: 'Updated expected response with more detail.', metadata: { lastReviewed: new Date().toISOString(), reviewedBy: 'team-lead', },});// Delete an itemawait client.datasets.deleteItem(datasetId, itemId);