v2 upgrade guide - elevenlabs/elevenlabs-js GitHub Wiki
v2 of the ElevenLabs introduces a variety of new features and breaking changes to the SDK.
The largest change is the renaming of many methods to simplify the API surface. Here's the complete list of method name changes:
Old method | New Method |
---|---|
client.conversationalAi.createAgent |
client.conversationalAi.agents.create |
client.conversationalAi.getAgent |
client.conversationalAi.agents.get |
client.conversationalAi.updateAgent |
client.conversationalAi.agents.update |
client.conversationalAi.deleteAgent |
client.conversationalAi.agents.delete |
client.conversationalAi.getAgentWidget |
client.conversationalAi.agents.widget.get |
client.conversationalAi.postAgentAvatar |
client.conversationalAi.agents.widget.avatar.create |
client.conversationalAi.getAgentLink |
client.conversationalAi.agents.link.get |
client.conversationalAi.postAgentLink |
client.conversationalAi.agents.link.create |
client.conversationalAi.getAgents |
client.conversationalAi.agents.list |
client.conversationalAi.countAgents |
client.conversationalAi.agents.count |
client.conversationalAi.getBatchCall |
client.conversationalAi.batchCalls.get |
client.conversationalAi.getSignedUrl |
client.conversationalAi.conversations.getSignedUrl |
client.conversationalAi.twilioOutboundCall |
client.conversationalAi.twilio.outboundCall |
client.conversationalAi.getConversations |
client.conversationalAi.conversations.list |
client.conversationalAi.getConversation |
client.conversationalAi.conversations.get |
client.conversationalAi.deleteConversation |
client.conversationalAi.conversations.delete |
client.conversationalAi.getConversationAudio |
client.conversationalAi.conversations.audio.get |
client.conversationalAi.postConversationFeedback |
client.conversationalAi.conversations.feedback.create |
client.conversationalAi.createKnowledgeBaseUrlDocument |
client.conversationalAi.knowledgeBase.documents.createFromUrl |
client.conversationalAi.createKnowledgeBaseFileDocument |
client.conversationalAi.knowledgeBase.documents.createFromFile |
client.conversationalAi.createKnowledgeBaseTextDocument |
client.conversationalAi.knowledgeBase.documents.createFromText |
client.conversationalAi.getKnowledgeBaseDocumentById |
client.conversationalAi.knowledgeBase.documents.get |
client.conversationalAi.getKnowledgeBaseDocumentContent |
client.conversationalAi.knowledgeBase.documents.getContent |
client.conversationalAi.deleteKnowledgeBaseDocument |
client.conversationalAi.knowledgeBase.documents.delete |
client.conversationalAi.getKnowledgeBaseList |
client.conversationalAi.knowledgeBase.list |
client.conversationalAi.getKnowledgeBaseDocumentPartById |
client.conversationalAi.knowledgeBase.documents.chunk.get |
client.conversationalAi.getPhoneNumber |
client.conversationalAi.phoneNumbers.get |
client.conversationalAi.getPhoneNumbers |
client.conversationalAi.phoneNumbers.list |
client.conversationalAi.deletePhoneNumber |
client.conversationalAi.phoneNumbers.delete |
client.conversationalAi.updatePhoneNumber |
client.conversationalAi.phoneNumbers.update |
client.conversationalAi.getSecrets |
client.conversationalAi.secrets.list |
client.conversationalAi.createSecret |
client.conversationalAi.secrets.create |
client.conversationalAi.deleteSecret |
client.conversationalAi.secrets.delete |
client.conversationalAi.getSettings |
client.conversationalAi.settings.get |
client.conversationalAi.updateSettings |
client.conversationalAi.settings.update |
client.conversationalAi.getDashboardSettings |
client.conversationalAi.dashboard.settings.get |
client.conversationalAi.updateDashboardSettings |
client.conversationalAi.dashboard.settings.update |
client.audioIsolation.audioIsolation |
client.audioIsolation.convert |
client.audioIsolation.audioIsolationStream |
client.audioIsolation.stream |
client.audioNative.updateContent |
client.audioNative.update |
client.dubbing.dubAVideoOrAnAudioFile |
client.dubbing.create |
client.dubbing.getDubbingProjectMetadata |
client.dubbing.get |
client.dubbing.getDubbedFile |
client.dubbing.audio.get |
client.dubbing.getTranscriptForDub |
client.dubbing.transcript.get |
client.dubbing.deleteDubbingProject |
client.dubbing.delete |
client.dubbing.getDubbingResource |
client.dubbing.resource.get |
client.dubbing.addLanguageToResource |
client.dubbing.resource.language.add |
client.dubbing.speaker.segment.create |
client.dubbing.resource.speaker.segment.create |
client.dubbing.updateSegmentLanguage |
client.dubbing.resource.segment.update |
client.dubbing.deleteSegment |
client.dubbing.resource.segment.delete |
client.dubbing.transcribeSegments |
client.dubbing.resource.transcribe |
client.dubbing.translateSegments |
client.dubbing.resource.translate |
client.dubbing.dubSegments |
client.dubbing.resource.dub |
client.dubbing.speaker.update |
client.dubbing.resource.speaker.update |
client.dubbing.speaker.similarVoices |
client.dubbing.resource.speaker.findSimilarVoices |
client.voices.getSimilarLibraryVoices |
client.voices.findSimilarVoices |
client.speechToSpeech.convertAsStream |
client.speechToSpeech.stream |
client.textToSpeech.convertAsStream |
client.textToSpeech.stream |
client.voices.getDefaultSettings |
client.voices.settings.getDefault |
client.voices.editSettings |
client.voices.settings.update |
client.voices.add |
client.voices.ivc.create |
client.voices.edit |
client.voices.update |
client.models.getAll |
client.models.list |
client.studio.projects.getAll |
client.studio.projects.list |
client.studio.projects.add |
client.studio.projects.create |
client.studio.projects.updateMetadata |
client.studio.projects.update |
client.studio.projects.updateContent |
client.studio.projects.content.update |
client.studio.projects.getProjectSnapshot |
client.studio.projects.snapshots.get |
client.studio.projects.streamAudio |
client.studio.projects.snapshots.stream |
client.studio.projects.chapters.getAll |
client.studio.projects.chapters.list |
client.studio.chapters.get |
client.studio.projects.chapters.get |
client.studio.chapters.create |
client.studio.projects.chapters.create |
client.studio.chapters.edit |
client.studio.projects.chapters.update |
client.studio.chapters.convert |
client.studio.projects.chapters.convert |
client.studio.chapters.getAllSnapshots |
client.studio.projects.chapters.snapshots.list |
client.studio.chapters.streamSnapshot |
client.studio.projects.chapters.snapshots.stream |
client.studio.projects.updatePronunciationDictionaries |
client.studio.projects.pronunciationDictionaries.create |
client.pronunciationDictionary.addFromFile |
client.pronunciationDictionaries.createFromFile |
client.pronunciationDictionary.addFromRules |
client.pronunciationDictionaries.createFromRules |
client.pronunciationDictionary.addRules |
client.pronunciationDictionaries.rules.add |
client.pronunciationDictionary.removeRules |
client.pronunciationDictionaries.rules.remove |
client.pronunciationDictionary.download |
client.pronunciationDictionaries.download |
client.pronunciationDictionary.get |
client.pronunciationDictionaries.get |
client.pronunciationDictionary.getAll |
client.pronunciationDictionaries.list |
client.samples.getAudio |
client.voices.samples.audio.get |
client.history.getAll |
client.history.list |
client.usage.getCharactersUsageMetrics |
client.usage.get |
client.user.getSubscription |
client.user.subscription.get |
client.voices.addSharingVoice |
client.voices.share |
client.workspace.searchUserGroups |
client.workspace.groups.search |
client.workspace.deleteMemberFromUserGroup |
client.workspace.groups.members.remove |
client.workspace.addMemberToUserGroup |
client.workspace.groups.members.add |
client.workspace.inviteUser |
client.workspace.invites.create |
client.workspace.inviteMultipleUsers |
client.workspace.invites.createBatch |
client.workspace.deleteExistingInvitation |
client.workspace.invites.delete |
client.workspace.updateMember |
client.workspace.members.update |
client.workspace.deleteMember |
client.workspace.members.delete |
client.workspace.getResource |
client.workspace.resources.get |
client.workspace.shareWorkspaceResource |
client.workspace.resources.share |
client.workspace.unshareWorkspaceResource |
client.workspace.resources.unshare |
Request stitching
Request stitching is the process of providing request ID from previous generations to an audio generation endpoint. By providing these IDs the model can ensure that subsequent generations match the style and prosody of previous iterations. Here's a simple example using the elevenlabs-js SDK:
import "dotenv/config";
import { ElevenLabsClient, play } from 'elevenlabs';
import { Readable } from 'node:stream';
const elevenlabs = new ElevenLabsClient({
apiKey: process.env.ELEVENLABS_API_KEY,
});
const paragraphs = [
"The first move is what sets everything in motion.",
"The second move is what sets everything in motion.",
"The third move is what sets everything in motion.",
];
const requestIds: string[] = [];
const audioBuffers: Buffer[] = [];
for (const paragraph of paragraphs) {
const response = await elevenlabs.textToSpeech.convert("T7QGPtToiqH4S8VlIkMJ", {
text: paragraph,
modelId: "eleven_multilingual_v2",
previousRequestIds: requestIds,
}).withRawResponse();
requestIds.push(response.rawResponse.headers.get("request-id") ?? "");
// Convert stream to buffer
const chunks: Buffer[] = [];
for await (const chunk of response.data) {
chunks.push(Buffer.from(chunk));
}
audioBuffers.push(Buffer.concat(chunks));
}
// Create a single readable stream from all buffers
const combinedStream = Readable.from(Buffer.concat(audioBuffers));
play(combinedStream);
By using the new withRawResponse()
method we can extract the request headers, which include the request ID.
Webhook events
The new helper method elevenlabs.webhooks.constructEvent
is used to confirm that the event was sent by ElevenLabs. Example usage:
const elevenlabs = new ElevenLabsClient();
// req is the raw request to the webhook endpoint
const sigHeader = req.headers.get('ElevenLabs-Signature');
const event = await elevenlabs.webhooks.constructEvent(req.body, sigHeader, process.env.ELEVENLABS_WEBHOOK_SECRET);
// If the above succeeds, the event was confirmed to have come from ElevenLabs
generate
method
Removal of generate
has been removed from the SDK. Instead use the elevenlabs.textToSpeech.convert
method to generate text-to-speech audio.
Snake case for variables
Parameters for SDK methods now use snake case to be more in line with the JavaScript ecosystem. For example:
const audio = await client.textToSpeech.convert("JBFqnCBsd6RMkjVDRZzb", {
text: "The first move is what sets everything in motion.",
modelId: "eleven_multilingual_v2", // modelId instead of model_id
outputFormat: "mp3_44100_128", // outputFormat instead of output_format
});