[Inworld] add User-Agent and X-Request-Id for better traceability

This commit is contained in:
Ian Lee
2026-02-10 17:52:38 -08:00
parent 9c627e7292
commit dcbcab1542
2 changed files with 17 additions and 3 deletions

View File

@@ -0,0 +1 @@
- Added `X-User-Agent` and `X-Request-Id` headers to `InworldTTSService` for better traceability.

View File

@@ -16,11 +16,16 @@ Inworlds text-to-speech (TTS) models offer ultra-realistic, context-aware spe
import asyncio import asyncio
import base64 import base64
import json import json
import uuid
from typing import Any, AsyncGenerator, Dict, List, Optional, Tuple from typing import Any, AsyncGenerator, Dict, List, Optional, Tuple
import aiohttp import aiohttp
import websockets import websockets
from loguru import logger from loguru import logger
from pipecat import version as pipecat_version
USER_AGENT = f"pipecat/{pipecat_version()}"
from pydantic import BaseModel from pydantic import BaseModel
try: try:
@@ -236,9 +241,12 @@ class InworldHttpTTSService(WordTTSService):
# Use WORD timestamps for simplicity and correct spacing/capitalization # Use WORD timestamps for simplicity and correct spacing/capitalization
payload["timestampType"] = self._timestamp_type payload["timestampType"] = self._timestamp_type
request_id = str(uuid.uuid4())
headers = { headers = {
"Authorization": f"Basic {self._api_key}", "Authorization": f"Basic {self._api_key}",
"Content-Type": "application/json", "Content-Type": "application/json",
"X-User-Agent": USER_AGENT,
"X-Request-Id": request_id,
} }
try: try:
@@ -252,7 +260,7 @@ class InworldHttpTTSService(WordTTSService):
) as response: ) as response:
if response.status != 200: if response.status != 200:
error_text = await response.text() error_text = await response.text()
logger.error(f"Inworld API error: {error_text}") logger.error(f"Inworld API error (request_id={request_id}): {error_text}")
yield ErrorFrame(error=f"Inworld API error: {error_text}") yield ErrorFrame(error=f"Inworld API error: {error_text}")
return return
@@ -693,8 +701,13 @@ class InworldTTSService(AudioContextWordTTSService):
if self._websocket and self._websocket.state is State.OPEN: if self._websocket and self._websocket.state is State.OPEN:
return return
logger.debug("Connecting to Inworld WebSocket TTS") request_id = str(uuid.uuid4())
headers = [("Authorization", f"Basic {self._api_key}")] logger.debug(f"Connecting to Inworld WebSocket TTS (request_id={request_id})")
headers = [
("Authorization", f"Basic {self._api_key}"),
("X-User-Agent", USER_AGENT),
("X-Request-Id", request_id),
]
self._websocket = await websocket_connect(self._url, additional_headers=headers) self._websocket = await websocket_connect(self._url, additional_headers=headers)
await self._call_event_handler("on_connected") await self._call_event_handler("on_connected")
except Exception as e: except Exception as e: