elevenlabs-client
TypeScript icon, indicating that this package has built-in type declarations

0.0.20 • Public • Published

elevenlabs-client banner

GitHub License NPM bundle minzipped size NPM total downloads Join Discord

Status: Experimental

elevenlabs-client is a typesafe and straightforward fetch client for interacting with the ElevenLabs API using feature-fetch.

📖 Usage

🌟 Motivation

Create an ElevenLabs API client that works in a Remotion (ReactJs) environment.

⚖️ Alternatives

Create an ElevenLabs Client

Use createElvenLabsClient() to create a client with your API key.

import { createElvenLabsClient } from 'elevenlabs-client';

const client = createElvenLabsClient({
	apiKey: 'YOUR_API_KEY'
});

Error Handling

Errors can occur during API requests, and the client will return detailed error information. Possible error types include:

  • NetworkError: Indicates a failure in network communication, such as loss of connectivity
  • RequestError: Occurs when the server returns a response with a status code indicating an error (e.g., 4xx or 5xx)
  • FetchError: A general exception type that can encompass other error scenarios not covered by NetworkError or RequestError, for example when the response couldn't be parsed, ..
const voicesResult = await client.getVoices();

// First Approach: Handle error using `isErr()`
if (voicesResult.isErr()) {
	const { error } = voicesResult;
	if (error instanceof NetworkError) {
		console.error('Network error:', error.message);
	} else if (error instanceof RequestError) {
		console.error('Request error:', error.message, 'Status:', error.status);
	} else if (error instanceof FetchError) {
		console.error('Service error:', error.message, 'Code:', error.code);
	} else {
		console.error('Unexpected error:', error);
	}
}

// Second Approach: Unwrap response with `try-catch`
try {
	const voices = voicesResult.unwrap();
} catch (error) {
	if (error instanceof NetworkError) {
		console.error('Network error:', error.message);
	} else if (error instanceof RequestError) {
		console.error('Request error:', error.message, 'Status:', error.status);
	} else if (error instanceof FetchError) {
		console.error('Service error:', error.message, 'Code:', error.code);
	} else {
		console.error('Unexpected error:', error);
	}
}

Readme

Keywords

none

Package Sidebar

Install

npm i elevenlabs-client

Weekly Downloads

6

Version

0.0.20

License

MIT

Unpacked Size

250 kB

Total Files

18

Last publish

Collaborators

  • bennobuilder