Repository: livekit/agents
File: livekit-plugins/livekit-plugins-trugen/livekit/plugins/trugen/avatar.py (Python)

Code before:
                        "avatar_id": self._avatar_id,
                        "livekit_url": livekit_url,
                        "livekit_token": livekit_token,
                    },
                    timeout=aiohttp.ClientTimeout(sock_connect=self._conn_options.timeout),
                ) as response:
                    if not response.ok:
                        text = await response.text()
                        raise APIStatusError(
                            "Server returned an error", status_code=response.status, body=text
                        )
                    return

            except Exception as e:
                if isinstance(e, APIConnectionError):
                    logger.warning(
                        "API Error; Unable to trigger TruGen.AI API backend.",
                        extra={"error": str(e)},
                    )
                else:
                    logger.exception("API Error; Unable to trigger TruGen.AI API backend.")

                if i < self._conn_options.max_retry - 1:
                    await asyncio.sleep(self._conn_options.retry_interval)

        raise APIConnectionError("Max retry exhaused; Unable to start TruGen.AI Avatar Session.")


Review comment (suggestion):
```suggestion
        raise APIConnectionError("Max retries exhausted; Unable to start TruGen.AI Avatar Session.")
```

Code after:
            .with_attributes({ATTRIBUTE_PUBLISH_ON_BEHALF: local_participant_identity})
            .to_jwt()
        )

        logger.debug("Starting Realtime Avatar Session")
        await self._start_session(livekit_url, livekit_token)

        agent_session.output.audio = DataStreamAudioOutput(
            room=room,
            destination_identity=self._avatar_participant_identity,
            wait_remote_track=rtc.TrackKind.KIND_VIDEO,
        )

    async def _start_session(self, livekit_url: str, livekit_token: str) -> None:
        assert self._api_key is not None
        api_key = self._api_key
        assert isinstance(api_key, str)
        for i in range(self._conn_options.max_retry + 1):
            try:
                async with self._ensure_http_session().post(
                    f"{_BASE_API_URL}/v1/sessions",
                    headers={
                        "x-api-key": api_key,
                    },
                    json={
                        "avatar_id": self._avatar_id,
                        "livekit_url": livekit_url,
                        "livekit_token": livekit_token,
                    },
                    timeout=aiohttp.ClientTimeout(sock_connect=self._conn_options.timeout),
                ) as response:
                    if not response.ok:
                        text = await response.text()
                        raise APIStatusError(
                            "Server returned an error", status_code=response.status, body=text
                        )
                    return

            except Exception as e:
                if isinstance(e, APIStatusError):
                    logger.warning(
                        "API Error; Unable to trigger TruGen.AI API backend.",
                        extra={"status_code": e.status_code, "body": e.body},
                    )
                    if not e.retryable:
                        raise
                else:
                    logger.warning(
                        "API Error; Unable to trigger TruGen.AI API backend.",
                        extra={"error": str(e)},
                    )