Creates a new snippet with optional variations, folder assignment, and tags. This endpoint allows you to create structured snippets programmatically.API Cost: 1 request
Here’s a complete example of creating prompts for a voice AI system (like VAPI):
Copy
async function createVoiceAgentPrompts(clientData) { const { clientName, industry, teamId, folderId } = clientData; // Create a snippet with multiple language variations const snippet = { title: `${clientName} - ${industry} Agent`, content: { type: 'plaintext', content: `You are a professional ${industry} assistant for ${clientName}. Your role is to help customers with inquiries, schedule appointments, and provide information about services. Be polite, professional, and helpful.`, }, teamId: teamId, folderId: folderId, note: `Voice agent prompt for ${clientName}`, shortcut: `${clientName.toLowerCase()}_agent`, tagIds: [industryTagId, voiceAgentTagId], additionalVariations: [ { content: { type: 'plaintext', content: `Eres un asistente profesional de ${industry} para ${clientName}.Tu función es ayudar a los clientes con consultas, programar citasy proporcionar información sobre servicios. Sé cortés, profesional y servicial.`, }, variationName: 'Spanish Version', }, { content: { type: 'plaintext', content: `You are handling after-hours calls for ${clientName}.Inform customers of business hours and offer to schedule a callbackduring office hours. Be understanding and helpful.`, }, variationName: 'After Hours', }, ], }; try { const response = await createSnippet(snippet); console.log(`✅ Created voice agent prompt: ${response.data.snippetId}`); console.log(` Variations: ${response.data.metadata.totalVariations}`); return response.data.snippetId; } catch (error) { console.error( `❌ Failed to create prompt for ${clientName}:`, error.message ); throw error; }}// UsagecreateVoiceAgentPrompts({ clientName: 'Dental Clinic ABC', industry: 'Healthcare', teamId: 'healthcare-team-id', folderId: 'dental-clients-folder-id',});
To create multiple snippets, use the batch endpoint instead:
Copy
// Instead of this (inefficient):for (const snippetData of snippets) { await createSnippet(snippetData); // N API calls + N * rate limit issues}// Do this (efficient):await createSnippets({ snippets }); // 1 API call, N request cost
async function createSnippetSafe(snippetData) { // Pre-validate before API call if (!snippetData.title || snippetData.title.length === 0) { throw new Error('Title is required'); } if (snippetData.title.length > 200) { throw new Error('Title cannot exceed 200 characters'); } if (!snippetData.content) { throw new Error('Content is required'); } if (!snippetData.teamId) { throw new Error('Team ID is required'); } if (snippetData.note && snippetData.note.length > 5000) { throw new Error('Note cannot exceed 5000 characters'); } try { return await createSnippet(snippetData); } catch (error) { const status = error.response?.status; const message = error.response?.data?.message; if (status === 400) { throw new Error(`Validation error: ${message}`); } else if (status === 403) { if (message?.includes('team')) { throw new Error('API key does not have access to this team'); } else if (message?.includes('folder')) { throw new Error('Folder not found or not accessible'); } else if (message?.includes('tag')) { throw new Error('One or more tags not found'); } } throw error; }}