from httpx import AsyncClient
from mcp_bridge.config import config

# Keep the original client name to avoid breaking imports
client: AsyncClient = AsyncClient(
    base_url=config.inference_server.base_url,
    headers={"Authorization": f"Bearer {config.inference_server.api_key}", "Content-Type": "application/json"},
    timeout=10000,
)

def get_client(api_key: str = None) -> AsyncClient:
    """Returns a client with the provided API key or the default client"""
    if api_key:
        return AsyncClient(
            base_url=config.inference_server.base_url,
            headers={"Authorization": f"Bearer {api_key}", "Content-Type": "application/json"},
            timeout=10000,
        )
    return client
