Files

25 lines
565 B
Python

import httpx
from openai import OpenAI
def create_openai_client(
api_key: str,
proxy: str = "",
timeout: float = 600.0,
) -> OpenAI:
"""Create an OpenAI client with optional proxy support.
Matches the reference script pattern:
httpx.Client(proxy=..., http2=True) → OpenAI(http_client=...)
"""
http_client = httpx.Client(
proxy=proxy.strip() if proxy else None,
timeout=timeout,
verify=False,
http2=False,
)
return OpenAI(
api_key=api_key,
http_client=http_client,
)