Improve error handling and add response size cap with timeout - #395
Merged
Conversation
TalZaccai
reviewed
Jul 28, 2026
TalZaccai
approved these changes
Jul 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces robust safeguards against denial-of-service (DoS) risks in both the Python and TypeScript language model clients by enforcing maximum response body sizes and request timeouts. It also improves error handling for unexpected or malformed responses and adds comprehensive tests to ensure these protections work as intended.
Python: DoS Hardening and Tests
max_response_bytesproperty (default 100 MB) toHttpxLanguageModel, and enforces it by incrementally reading response bodies and aborting if the limit is exceeded. This prevents memory exhaustion from malicious or buggy endpoints. [1] [2]_ResponseTooLargeErrorfor clear error reporting when the limit is exceeded.Content-Length) and incremental reading, as well as disabling the limit.TypeScript: DoS Hardening and Error Handling
maxResponseBytes(default 100 MB) andtimeoutMs(default 10 minutes) options toTypeChatLanguageModel, enforcing them in all REST API calls to prevent resource exhaustion and indefinite hangs. [1] [2] [3] [4] [5]fetchWithTimeoutandreadResponseJsonutilities for incremental response reading and timeouts.These changes significantly improve the resilience and reliability of the language model clients against large or malformed responses and network issues.