Skip to content

feat: Add per-request headers, timeout, and auth overrides to endpoint functions#1416

Open
kwardega-sc wants to merge 2 commits intoopenapi-generators:mainfrom
kwardega-sc:main
Open

feat: Add per-request headers, timeout, and auth overrides to endpoint functions#1416
kwardega-sc wants to merge 2 commits intoopenapi-generators:mainfrom
kwardega-sc:main

Conversation

@kwardega-sc
Copy link

Adds optional headers, timeout, and auth keyword arguments to all generated endpoint functions (sync_detailed, asyncio_detailed, sync, asyncio). These are forwarded directly to the underlying httpx .request() call, allowing per-request overrides without creating a new client instance or disrupting the shared connection pool.

with_headers() and with_timeout() mutate the original client's underlying httpx client as a side effect and cause the returned client to open a new connection pool on first use, making them unsafe for runtime per-request use (especially in concurrent async code).

…t functions

Adds optional `headers`, `timeout`, and `auth` keyword arguments to all
generated endpoint functions (sync_detailed, asyncio_detailed, sync, asyncio).
These are forwarded directly to the underlying httpx `.request()` call,
allowing per-request overrides without creating a new client instance or
disrupting the shared connection pool.

`with_headers()` and `with_timeout()` mutate the original client's underlying
httpx client as a side effect and cause the returned client to open a new
connection pool on first use, making them unsafe for runtime per-request use
(especially in concurrent async code). This change provides the correct
alternative.

Known limitation: client-level headers cannot be removed for a single request;
they can only be overridden with a different value.
@kwardega-sc kwardega-sc marked this pull request as ready for review March 26, 2026 22:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant