From 42d6cc34d1602bc2a7b82f15c9d1e5fac4a4a897 Mon Sep 17 00:00:00 2001 From: wellenzheng <40078093+wellenzheng@users.noreply.github.com> Date: Sun, 27 Jul 2025 15:05:59 +0800 Subject: [PATCH] chore: readme and china region api base url (#21) Co-authored-by: zhengweijun --- README.md | 17 +++++++++++++++-- README_CN.md | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 27e679d..8e1675c 100644 --- a/README.md +++ b/README.md @@ -77,6 +77,16 @@ pip install zai-sdk ## 🚀 Quick Start ### Create API Key + +#### Get API Key +- **Overseas regions**: Visit [Z.ai Open Platform](https://docs.z.ai/) to get your API key +- **Mainland China regions**: Visit [Zhipu AI Open Platform](https://www.bigmodel.cn/) to get your API key + +#### API BASE URL +- **Mainland China regions**: `https://open.bigmodel.cn/api/paas/v4/` +- **Overseas regions**: `https://api.z.ai/api/paas/v4/` + +#### Usage Steps 1. **Create client with API key** 2. **Call the corresponding API methods** @@ -85,11 +95,14 @@ For complete examples, please refer to the open platform [API Reference](https:/ ### Basic Usage ```python -from zai import ZaiClient +from zai import ZaiClient, ZhipuAiClient -# Initialize client +# For Overseas users, create the ZaiClient client = ZaiClient(api_key="your-api-key") +# For Chinese users, create the ZhipuAiClient +client = ZhipuAiClient(api_key="your-api-key") + # Create chat completion response = client.chat.completions.create( model="glm-4", diff --git a/README_CN.md b/README_CN.md index b2a1807..0d7a8a6 100644 --- a/README_CN.md +++ b/README_CN.md @@ -76,13 +76,45 @@ pip install zai-sdk ## 🚀 快速开始 -### 基本用法 +### 创建 API Key + +#### 获取 API Key +- **海外区域**: 访问 [Z.ai 开放平台](https://docs.z.ai/) 获取 API Key +- **中国大陆区域**: 访问 [智谱 AI 开放平台](https://www.bigmodel.cn/) 获取 API Key + +#### API BASE URL +- **中国大陆区域**: `https://open.bigmodel.cn/api/paas/v4/` +- **海外区域**: `https://api.z.ai/api/paas/v4/` + +#### 使用步骤 1. **使用API密钥创建客户端** 2. **调用相应的API方法** 完整示例请参考开放平台[接口文档](https://docs.z.ai/api-reference/)以及[使用指南](https://docs.z.ai/guides/),记得替换为您自己的API密钥。 +### 基本用法 +### Basic Usage + +```python +from zai import ZaiClient, ZhipuAiClient + +# 对于海外用户,使用ZaiClient +client = ZaiClient(api_key="your-api-key") + +# 对于中国大陆用户,使用ZhipuAiClient +client = ZhipuAiClient(api_key="your-api-key") + +# Create chat completion +response = client.chat.completions.create( + model="glm-4", + messages=[ + {"role": "user", "content": "Hello, Z.ai!"} + ] +) +print(response.choices[0].message.content) +``` + ### 客户端配置 SDK支持多种方式配置API密钥: