Skip to content
This repository was archived by the owner on Aug 5, 2025. It is now read-only.
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

Reuse httpx connection instance instead of creating it at every request #163

@asvishnyakov

Description

@asvishnyakov

Right now you create new httpx client per request, which is probably inefficient.

It not only waste resources to initialization/finalization every time, but also establish new connection every time, preventing HTTP connection pooling.

Instead, httpx client should be initialized once [1] [2] at initialization of class which use it and then closed when class instance is no longer used, which is more efficient.

OpenAI doing exactly that for their client:
https://github.com/openai/openai-python/blob/b95be16e7c8a76c3d63335df13ab0d55ba3d5c35/src/openai/_base_client.py#L1449

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions