Configure the ZhipuAI client
mainYou can configure the ZhipuAI client using environment variables or directly in your code.
Environment Variables:
ZHIPUAI_API_KEY: Your API key.ZHIPUAI_BASE_URL: Custom API endpoint (optional, defaults tohttps://open.bigmodel.cn/api/paas/v4/).
Code Configuration:
Pass the api_key to the ZhipuAI constructor. For advanced settings, you can also configure timeout, max_retries, and base_url.
import httpx
from zhipuai import ZhipuAI
client = ZhipuAI(
api_key="your_api_key_here",
timeout=httpx.Timeout(timeout=300.0, connect=8.0),
max_retries=3,
base_url="https://open.bigmodel.cn/api/paas/v4/"
)