@ai-sdk/elevenlabs
Version:
The **[ElevenLabs provider](https://ai-sdk.dev/providers/ai-sdk-providers/elevenlabs)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the ElevenLabs chat and completion APIs and embedding model support for the ElevenLabs em
133 lines (123 loc) • 5.32 kB
TypeScript
import * as _ai_sdk_provider from '@ai-sdk/provider';
import { TranscriptionModelV4, ProviderV4, SpeechModelV4 } from '@ai-sdk/provider';
import { FetchFunction, WORKFLOW_SERIALIZE, WORKFLOW_DESERIALIZE } from '@ai-sdk/provider-utils';
import { z } from 'zod/v4';
type ElevenLabsConfig = {
provider: string;
url: (options: {
modelId: string;
path: string;
}) => string;
headers?: () => Record<string, string | undefined>;
fetch?: FetchFunction;
generateId?: () => string;
};
type ElevenLabsTranscriptionModelId = 'scribe_v1' | 'scribe_v1_experimental' | 'scribe_v2' | (string & {});
interface ElevenLabsTranscriptionModelConfig extends ElevenLabsConfig {
_internal?: {
currentDate?: () => Date;
};
}
declare class ElevenLabsTranscriptionModel implements TranscriptionModelV4 {
readonly modelId: ElevenLabsTranscriptionModelId;
private readonly config;
readonly specificationVersion = "v4";
get provider(): string;
static [WORKFLOW_SERIALIZE](model: ElevenLabsTranscriptionModel): {
modelId: string;
config: _ai_sdk_provider.JSONObject;
};
static [WORKFLOW_DESERIALIZE](options: {
modelId: ElevenLabsTranscriptionModelId;
config: ElevenLabsTranscriptionModelConfig;
}): ElevenLabsTranscriptionModel;
constructor(modelId: ElevenLabsTranscriptionModelId, config: ElevenLabsTranscriptionModelConfig);
private getArgs;
doGenerate(options: Parameters<TranscriptionModelV4['doGenerate']>[0]): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>>;
}
type ElevenLabsSpeechModelId = 'eleven_v3' | 'eleven_multilingual_v2' | 'eleven_flash_v2_5' | 'eleven_flash_v2' | 'eleven_turbo_v2_5' | 'eleven_turbo_v2' | 'eleven_monolingual_v1' | 'eleven_multilingual_v1' | (string & {});
type ElevenLabsSpeechVoiceId = string;
interface ElevenLabsProvider extends ProviderV4 {
(modelId: ElevenLabsTranscriptionModelId, settings?: {}): {
transcription: ElevenLabsTranscriptionModel;
};
/**
* Creates a model for transcription.
*/
transcription(modelId: ElevenLabsTranscriptionModelId): TranscriptionModelV4;
/**
* Creates a model for speech generation.
*/
speech(modelId: ElevenLabsSpeechModelId): SpeechModelV4;
/**
* @deprecated Use `embeddingModel` instead.
*/
textEmbeddingModel(modelId: string): never;
}
interface ElevenLabsProviderSettings {
/**
* API key for authenticating requests.
*/
apiKey?: string;
/**
* Custom headers to include in the requests.
*/
headers?: Record<string, string>;
/**
* Custom fetch implementation. You can use it as a middleware to intercept requests,
* or to provide a custom fetch implementation for e.g. testing.
*/
fetch?: FetchFunction;
}
/**
* Create an ElevenLabs provider instance.
*/
declare function createElevenLabs(options?: ElevenLabsProviderSettings): ElevenLabsProvider;
/**
* Default ElevenLabs provider instance.
*/
declare const elevenLabs: ElevenLabsProvider;
declare const elevenLabsSpeechModelOptionsSchema: z.ZodObject<{
languageCode: z.ZodOptional<z.ZodString>;
voiceSettings: z.ZodOptional<z.ZodObject<{
stability: z.ZodOptional<z.ZodNumber>;
similarityBoost: z.ZodOptional<z.ZodNumber>;
style: z.ZodOptional<z.ZodNumber>;
useSpeakerBoost: z.ZodOptional<z.ZodBoolean>;
}, z.core.$strip>>;
pronunciationDictionaryLocators: z.ZodOptional<z.ZodArray<z.ZodObject<{
pronunciationDictionaryId: z.ZodString;
versionId: z.ZodOptional<z.ZodString>;
}, z.core.$strip>>>;
seed: z.ZodOptional<z.ZodNumber>;
previousText: z.ZodOptional<z.ZodString>;
nextText: z.ZodOptional<z.ZodString>;
previousRequestIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
nextRequestIds: z.ZodOptional<z.ZodArray<z.ZodString>>;
applyTextNormalization: z.ZodOptional<z.ZodEnum<{
auto: "auto";
on: "on";
off: "off";
}>>;
applyLanguageTextNormalization: z.ZodOptional<z.ZodBoolean>;
enableLogging: z.ZodOptional<z.ZodBoolean>;
}, z.core.$strip>;
type ElevenLabsSpeechModelOptions = z.infer<typeof elevenLabsSpeechModelOptionsSchema>;
declare const elevenLabsTranscriptionModelOptionsSchema: z.ZodObject<{
languageCode: z.ZodOptional<z.ZodNullable<z.ZodString>>;
tagAudioEvents: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
numSpeakers: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
timestampsGranularity: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
none: "none";
word: "word";
character: "character";
}>>>>;
diarize: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodBoolean>>>;
fileFormat: z.ZodDefault<z.ZodOptional<z.ZodNullable<z.ZodEnum<{
pcm_s16le_16: "pcm_s16le_16";
other: "other";
}>>>>;
}, z.core.$strip>;
type ElevenLabsTranscriptionModelOptions = z.infer<typeof elevenLabsTranscriptionModelOptionsSchema>;
declare const VERSION: string;
export { type ElevenLabsProvider, type ElevenLabsProviderSettings, type ElevenLabsSpeechModelId, type ElevenLabsSpeechModelOptions, type ElevenLabsSpeechVoiceId, type ElevenLabsTranscriptionModelOptions, VERSION, createElevenLabs, elevenLabs, elevenLabs as elevenlabs };