tools = [ ...tools, { type: “query”, function: { name: “product-query”, description: “Handles queries about products or services using the assigned knowledge base.” } } ]; let toolId = null; if(vapiFileIds.length > 0) { try { const toolPayload = { type: “query”, function: { name: “product-query”, description: “Handles queries about products or services using the assigned knowledge base.” }, knowledgeBases: [ { provider: “google”, name: “product-kb”, description: “Use this knowledge base when the user asks or queries about the product or services”, fileIds: vapiFileIds } ] }; const response = await axios.post(`https://api.vapi.ai/tool/`, toolPayload, { headers: { Authorization: `Bearer ${config?.vapiApiKey}`, “Content-Type”: “application/json”, }, }); toolId = response.data.id; console.log(“Product-query tool created/updated with knowledge base file IDs:“, response); } catch(toolError) { console.error(“Failed to create/update product-query tool:“, toolError.response?.data || toolError.message); } } const vapiPayload = { name: name || existingAssistant.name, model: { provider: “openai”, model: “gpt-4o-mini”, temperature: 1.1, emotionRecognitionEnabled: true, messages: [ { role: “system”, content: systemContent, }, ], tools: tools, toolIds: toolId ? [toolId] : undefined, }, voice: { provider: “11labs”, voiceId: voice || existingAssistant.voice || “9BWtsMINqrJLrRacOk9x”, speed: 1.1 }, messagePlan: { idleMessages: [“Can I help you with anything else?“], idleMessageMaxSpokenCount: 1, idleTimeoutSeconds: 5, silenceTimeoutMessage: “Are you still there?” }, startSpeakingPlan: { waitSeconds: 0.4, smartEndpointingEnabled: true }, stopSpeakingPlan: { voiceSeconds: 0.2, backoffSeconds: 1 }, firstMessage: welcomeMessage || existingAssistant.welcomeMessage || “Hello, how can I assist you today?“, }; try { const vapiResponse = await axios.put(`https://api.vapi.ai/assistant/${assistantId}`, vapiPayload, { headers: { Authorization: `Bearer ${config?.vapiApiKey}`, “Content-Type”: “application/json”, }, }); res.status(200).json({ success: true, message: “Assistant create successfully!“, data: vapiResponse, }); } catch(error) { console.error(“Vapi API error details:“, error.response?.data); throw error; }