Skip to content

Add configurable network timeouts to all HTTP clients#19

Merged
francescobianco merged 6 commits into
openapi:mainfrom
Deadpool2000:enhance-18
Apr 28, 2026
Merged

Add configurable network timeouts to all HTTP clients#19
francescobianco merged 6 commits into
openapi:mainfrom
Deadpool2000:enhance-18

Conversation

@Deadpool2000

@Deadpool2000 Deadpool2000 commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

ref #18
This PR introduces a simple, built-in way for developers to configure network timeouts across all the SDK clients (Client, AsyncClient, OauthClient, and AsyncOauthClient).

Why is this necessary?

Right now, the SDK uses the default 5-second timeout imposed by httpx. While that's fine for simple requests, it's a bit too strict for heavy API operations (like generating large PDFs or querying massive datasets) and causes perfectly valid requests to unexpectedly crash with a TimeoutException.

Previously, the only way to avoid this was to build a completely custom httpx.Client(timeout=...) object and pass it in during initialization, which was a lot of unnecessary boilerplate for a very common need.

How was this implemented? Let's break down the changes:

  1. Added a timeout argument: I added timeout: float = 30.0 directly to the __init__ methods of all four client classes.
  2. Passed it down natively: The param is passed directly into httpx.Client(timeout=timeout) and httpx.AsyncClient(timeout=timeout).
  3. Smarter default: Upped the default SDK timeout from 5 seconds to a much safer 30 seconds to prevent crashes on slower endpoints without hanging forever.
  4. Preserved backward compatibility: Check out the logic: self.client = client if client is not None else httpx.Client(timeout=timeout). We only apply this timeout if a user isn't passing in their own custom HTTP client config. This guarantees we don't break existing custom transport layers.
  5. Updated Documentation:
    • Appended a new Configuring Network Timeouts snippet to the README.md.
    • Replicated those usage snippets to docs/readme-pypi.md and updated the Markdown API tables to reflect the new timeout=30.0 signature.

Testing

  • Ran the internal test suite via poetry run pytest and verified all 18 existing test cases still pass perfectly with these changes!
@Deadpool2000

Deadpool2000 commented Apr 25, 2026

Copy link
Copy Markdown
Contributor Author

@francescobianco check this and let me know can it be merged?

Feature #18

@francescobianco

Copy link
Copy Markdown
Member

Very useful — let’s merge it. Thanks for your dedication! 🚀 @Deadpool2000

@francescobianco francescobianco merged commit 7869447 into openapi:main Apr 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants