agents icon indicating copy to clipboard operation
agents copied to clipboard

tavus: 4xx errors are retried and the provider's status is replaced by a generic error

Open sidxh opened this issue 2 months ago • 1 comments

Bug Description

TavusAPI._post (used by create_conversation, create_pal, create_persona) retries every failure the same way, including 4xx responses that can never succeed. With a wrong TAVUS_API_KEY the avatar takes about 4 seconds to fail, logs three full tracebacks, and ends with APIConnectionError("Failed to call Tavus API after all retries"). The 401 and the response body are gone, and the error is marked retryable, so it looks exactly like a Tavus outage.

The loop in livekit-plugins-tavus/livekit/plugins/tavus/api.py catches Exception, which includes the APIStatusError it raises itself for a non-2xx response, logs it with logger.exception, and always ends with a generic APIConnectionError without chaining the cause. It also runs range(max_retry), one attempt fewer than Anam, TruGen, Keyframe and LemonSlice. Anam had the same loop and was fixed in #7314.

Expected Behavior

A non-retryable status (4xx) is raised immediately with its status code and body. 5xx and network errors are retried max_retry times after the first attempt, and the final error is the provider's status, or an APIConnectionError chained to the network error.

Reproduction Steps

Point TavusAPI(api_url=...) at a local server that returns 401 for every request and call create_conversation. With default connect options on main: 4.00s, three tracebacks, APIConnectionError with no status.

Versions

livekit-agents 1.8.3, livekit-plugins-tavus at main (57b3227a7), Python 3.13, macOS.

sidxh avatar Sep 26 '26 19:09 sidxh

@sidxh hey give this a try! no need for paying 3rd party avatar services.

this provide realistic avatars: https://github.com/NavodPeiris/gsplat-talkinghead

https://github.com/user-attachments/assets/670b67fe-e6f4-4bb6-a58e-66467fd7b977

NavodPeiris avatar Sep 29 '26 17:09 NavodPeiris