enh: ELEVENLABS_API_BASE_URL env var

This commit is contained in:
Timothy Jaeryang Baek 2025-10-28 00:06:52 -07:00
parent 81c530a9c4
commit e986488ab5
2 changed files with 9 additions and 4 deletions

View file

@ -3343,6 +3343,10 @@ DEEPGRAM_API_KEY = PersistentConfig(
os.getenv("DEEPGRAM_API_KEY", ""), os.getenv("DEEPGRAM_API_KEY", ""),
) )
# ElevenLabs configuration
ELEVENLABS_API_BASE_URL = os.getenv(
"ELEVENLABS_API_BASE_URL", "https://api.elevenlabs.io"
)
AUDIO_STT_OPENAI_API_BASE_URL = PersistentConfig( AUDIO_STT_OPENAI_API_BASE_URL = PersistentConfig(
"AUDIO_STT_OPENAI_API_BASE_URL", "AUDIO_STT_OPENAI_API_BASE_URL",

View file

@ -39,13 +39,14 @@ from open_webui.config import (
WHISPER_MODEL_DIR, WHISPER_MODEL_DIR,
CACHE_DIR, CACHE_DIR,
WHISPER_LANGUAGE, WHISPER_LANGUAGE,
ELEVENLABS_API_BASE_URL,
) )
from open_webui.constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from open_webui.env import ( from open_webui.env import (
ENV,
AIOHTTP_CLIENT_SESSION_SSL, AIOHTTP_CLIENT_SESSION_SSL,
AIOHTTP_CLIENT_TIMEOUT, AIOHTTP_CLIENT_TIMEOUT,
ENV,
SRC_LOG_LEVELS, SRC_LOG_LEVELS,
DEVICE_TYPE, DEVICE_TYPE,
ENABLE_FORWARD_USER_INFO_HEADERS, ENABLE_FORWARD_USER_INFO_HEADERS,
@ -413,7 +414,7 @@ async def speech(request: Request, user=Depends(get_verified_user)):
timeout=timeout, trust_env=True timeout=timeout, trust_env=True
) as session: ) as session:
async with session.post( async with session.post(
f"https://api.elevenlabs.io/v1/text-to-speech/{voice_id}", f"{ELEVENLABS_API_BASE_URL}/v1/text-to-speech/{voice_id}",
json={ json={
"text": payload["input"], "text": payload["input"],
"model_id": request.app.state.config.TTS_MODEL, "model_id": request.app.state.config.TTS_MODEL,
@ -1037,7 +1038,7 @@ def get_available_models(request: Request) -> list[dict]:
elif request.app.state.config.TTS_ENGINE == "elevenlabs": elif request.app.state.config.TTS_ENGINE == "elevenlabs":
try: try:
response = requests.get( response = requests.get(
"https://api.elevenlabs.io/v1/models", f"{ELEVENLABS_API_BASE_URL}/v1/models",
headers={ headers={
"xi-api-key": request.app.state.config.TTS_API_KEY, "xi-api-key": request.app.state.config.TTS_API_KEY,
"Content-Type": "application/json", "Content-Type": "application/json",
@ -1141,7 +1142,7 @@ def get_elevenlabs_voices(api_key: str) -> dict:
try: try:
# TODO: Add retries # TODO: Add retries
response = requests.get( response = requests.get(
"https://api.elevenlabs.io/v1/voices", f"{ELEVENLABS_API_BASE_URL}/v1/voices",
headers={ headers={
"xi-api-key": api_key, "xi-api-key": api_key,
"Content-Type": "application/json", "Content-Type": "application/json",