本文首发于平台公测首日,分享从注册到接入的完整体验,以及基于 Python 的详细接入教程。
今天天云港模型开放平台进入公测阶段,笔者在前几天已经参与过本平台,该平台提供与OpenAI兼容的接口,开发者可以无缝迁移现有项目,或从零快速构建 AI 应用。

平台首页 ↑
快速开始
登录
登录方式非常简单,直接使用云港网络知识分享站授权登录即可,账号体系和余额完全互通。
需要购买任意资源包后完成实名。
它的用户中心:


↑ 模型列表

↑ 资源包购买
资源包购买分为Max(容量100000)、Pro(容量40000)、Lite(容量20000)三种(⚠️重要提示:此站容量是按调用次数算的,调用doubao-seed-2.0-code,kimi-k2.5模型时用量按 “高峰期 3 倍,非高峰期 2 倍” 进行计算;可在复杂任务上切换至GLM模型处理,普通任务上继续使用GLM-4.7,以避免套餐用量额度消耗过快。“高峰期”为每日14:00~18:00。)
💡 性价比建议:Lite 套餐 19.9 元/月的价格相当实惠,一般个人开发者够用。
API 接入教程(Python)
以下示例均基于标准库 http.client。
购买资源包后,新建令牌。


基础示例
import http.client
import json
# 建立 HTTPS 连接
conn = http.client.HTTPSConnection("api.model.yungnet.cn")
# 构造请求体
payload = json.dumps({
"model": "glm-5",
"messages": [
{
"role": "user",
"content": "写一首关于春天的诗。"
}
],
"temperature": 1
})
# 设置请求头(替换为你的真实 API Key)
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
# 发送请求
conn.request("POST", "/v1/chat/completions", payload, headers)
res = conn.getresponse()
data = res.read()
# 解析响应
response = json.loads(data.decode("utf-8"))
print(response["choices"][0]["message"]["content"])
返回结构说明:
{
"id": "chatcmpl-xxx",
"object": "chat.completion",
"created": 1709222400,
"model": "glm-5",
"choices": [{
"index": 0,
"message": {
"role": "assistant",
"content": "春风拂面柳丝长,..."
},
"finish_reason": "stop"
}],
"usage": {
"prompt_tokens": 15,
"completion_tokens": 50,
"total_tokens": 65
}
}
带角色设定的对话
system 消息设定 AI 的身份:payload = json.dumps({
"model": "glm-5",
"messages": [
{
"role": "system",
"content": "你是一位专业的 Python 编程导师,擅长用通俗语言解释复杂概念,回答简洁且附带代码示例。"
},
{
"role": "user",
"content": "什么是递归?"
}
]
})
多轮对话(上下文记忆)
messages 数组包含完整历史:messages = [
{"role": "system", "content": "你是专业编程助手"},
{"role": "user", "content": "什么是递归?"},
{"role": "assistant", "content": "递归是函数调用自身的编程技术..."},
{"role": "user", "content": "能给我一个 Python 例子吗?"} # 基于上文
]
payload = json.dumps({
"model": "glm-5",
"messages": messages
})
流式输出实现
stream: true,通过 SSE 接收实时数据:import http.client
import json
conn = http.client.HTTPSConnection("api.model.yungnet.cn")
payload = json.dumps({
"model": "glm-5",
"messages": [{"role": "user", "content": "讲一个科幻故事"}],
"stream": True # 关键参数
})
headers = {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
}
conn.request("POST", "/v1/chat/completions", payload, headers)
res = conn.getresponse()
# 逐行读取 SSE 流
buffer = ""
for line in res:
line = line.decode('utf-8').strip()
if line.startswith('data: '):
data = line[6:]
if data == '[DONE]':
break
try:
chunk = json.loads(data)
# 提取增量内容
delta = chunk["choices"][0].get("delta", {})
content = delta.get("content", "")
if content:
print(content, end="", flush=True)
buffer += content
except json.JSONDecodeError:
continue
print(f"\n\n完整内容:{buffer}")
SSE数据格式:
data: {"id":"...","choices":[{"delta":{"content":"春"},"index":0}]}data: {"id":"...","choices":[{"delta":{"content":"天"},"index":0}]}...data: [DONE]
多模态:图片理解
glm-4.6v 模型,支持 URL 或 Base64 图片:payload = json.dumps({
"model": "glm-4.6v",
"messages": [
{
"role": "user",
"content": [
{
"type": "image_url",
"image_url": {
"url": "https://example.com/menu.jpg"
}
},
{
"type": "text",
"text": "这张菜单有什么招牌菜?推荐三道并估算总价。"
}
]
}
]
})
-
type: image_url:网络图片链接 -
type: text:文本提示 -
支持同时传入多张图片对比分析
工具调用(Function Calling)
payload = json.dumps({
"model": "glm-5",
"messages": [{"role": "user", "content": "今天北京的天气怎么样?"}],
"tools": [
{
"type": "function",
"function": {
"name": "get_weather",
"description": "获取指定城市的天气信息",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称,如北京、上海"
},
"date": {
"type": "string",
"description": "日期,格式 YYYY-MM-DD,默认今天"
}
},
"required": ["city"]
}
}
}
],
"tool_choice": "auto", # auto 表示模型自行判断
"temperature": 0.3 # 低温度确保稳定调用
})
处理工具调用响应:
response = json.loads(data.decode("utf-8"))
message = response["choices"][0]["message"]
# 检查是否触发工具调用
if "tool_calls" in message:
for tool_call in message["tool_calls"]:
if tool_call["type"] == "function":
func_name = tool_call["function"]["name"]
args = json.loads(tool_call["function"]["arguments"])
print(f"模型请求调用: {func_name}({args})")
# 在这里执行你的本地函数
if func_name == "get_weather":
result = get_weather_api(args["city"])
# 将结果传回模型进行总结
follow_up = {
"model": "glm-5",
"messages": [
{"role": "user", "content": "今天北京的天气怎么样?"},
message, # 保留模型的工具调用请求
{
"role": "tool",
"tool_call_id": tool_call["id"],
"content": json.dumps(result)
}
]
}
总结
广告:












暂无评论内容