Heads up: PR for better error reporting in agents-js for inference gateway connection failures

If you’ve ever been stumped by APIConnectionError: Error connecting to LiveKit WebSocket with no further details, I’ve submitted a fix: fix: report actual HTTP status codes in connectWs instead of generic connection error by codicerecta · Pull Request #1075 · livekit/agents-js · GitHub.

Currently, connectWs swallows HTTP status codes from the inference gateway — rate limits (429), auth failures (401), server errors (500) all show up as the same generic connection error. The root cause is that the ws library doesn’t put the HTTP status code where the existing check expects it.

With this fix, HTTP errors are reported as APIStatusError with the actual status code, and network errors preserve the original message (e.g., ECONNREFUSED) instead of discarding it.

This would have saved me hours yesterday. Would love any feedback from folks who’ve run into this!

2 Likes

Thank you for the contribution, I see comments from the JS maintainer about a linting error, but other than that looks like it’s good to merge.