https://open.bigmodel.cn/api/paas/v4/
Content-Type: application/json Authorization: Bearer YOUR_API_KEY
curl --location 'https://open.bigmodel.cn/api/paas/v4/chat/completions' \ --header 'Authorization: Bearer YOUR_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "model": "glm-4.5", "messages": [ { "role": "user", "content": "你好" } ] }'
curl --location 'https://open.bigmodel.cn/api/paas/v4/chat/completions' \ --header 'Authorization: Bearer YOUR_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "model": "glm-4.5", "messages": [ { "role": "user", "content": "请介绍一下人工智能的发展历程" } ], "temperature": 0.7, "max_tokens": 1000 }'
curl --location 'https://open.bigmodel.cn/api/paas/v4/chat/completions' \ --header 'Authorization: Bearer YOUR_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "model": "glm-4.5", "messages": [ { "role": "user", "content": "写一首关于春天的诗" } ], "stream": true }'
curl --location 'https://open.bigmodel.cn/api/paas/v4/chat/completions' \ --header 'Authorization: Bearer YOUR_API_KEY' \ --header 'Content-Type: application/json' \ --data '{ "model": "glm-4.5", "messages": [ { "role": "system", "content": "你是一个专业的编程助手" }, { "role": "user", "content": "什么是递归?" }, { "role": "assistant", "content": "递归是一种编程技术,函数调用自身来解决问题..." }, { "role": "user", "content": "能给我一个Python递归的例子吗?" } ] }'
import requests import json def call_zhipu_api(messages, model="glm-4.5"): url = "https://open.bigmodel.cn/api/paas/v4/chat/completions" headers = { "Authorization": "Bearer YOUR_API_KEY", "Content-Type": "application/json" } data = { "model": model, "messages": messages, "temperature": 0.7 } response = requests.post(url, headers=headers, json=data) if response.status_code == 200: return response.json() else: raise Exception(f"API调用失败: {response.status_code}, {response.text}") # 使用示例 messages = [ {"role": "user", "content": "你好,请介绍一下自己"} ] result = call_zhipu_api(messages) print(result['choices'][0]['message']['content'])
Was this page helpful?