feat: configurable ElevenLabs base URL for Data Residency (#269)

Adds a `base_url` field to `ElevenlabsTTSConfiguration` so users on an
ElevenLabs Data Residency plan (EU, etc.) can point Dograh at the
regional endpoint instead of the hardcoded global one. Defaults to
`https://api.elevenlabs.io`, preserving existing behaviour. The
service factory rewrites the HTTP scheme to WSS when constructing the
WebSocket TTS service.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Abhishek Kumar 2026-05-12 18:33:45 +05:30
parent 9389340807
commit 114320a341
2 changed files with 15 additions and 0 deletions

View file

@ -443,6 +443,14 @@ class ElevenlabsTTSConfiguration(BaseServiceConfiguration):
default="eleven_flash_v2_5",
json_schema_extra={"examples": ELEVENLABS_TTS_MODELS},
)
base_url: str = Field(
default="https://api.elevenlabs.io",
description=(
"ElevenLabs API base URL. Override to use a Data Residency endpoint "
"(e.g. https://api.eu.residency.elevenlabs.io) for GDPR / HIPAA / "
"regional compliance."
),
)
OPENAI_TTS_MODELS = ["gpt-4o-mini-tts"]

View file

@ -247,9 +247,16 @@ def create_tts_service(user_config, audio_config: "AudioConfig"):
voice_id = user_config.tts.voice.split(" - ")[1]
except IndexError:
voice_id = user_config.tts.voice
# ElevenLabs TTS uses WebSocket. Users configure base_url with an HTTP
# scheme (matching ElevenLabs documentation, e.g.
# https://api.eu.residency.elevenlabs.io); rewrite it to the WS scheme.
elevenlabs_url = user_config.tts.base_url.replace(
"https://", "wss://"
).replace("http://", "ws://")
return ElevenLabsTTSService(
reconnect_on_error=False,
api_key=user_config.tts.api_key,
url=elevenlabs_url,
settings=ElevenLabsTTSSettings(
voice=voice_id,
model=user_config.tts.model,