بنقرة واحدة
coze-api
调用扣子(Coze)智能体 API 进行对话、工作流执行等操作。当用户需要集成 Coze 智能体、调用 Coze API、或开发 Coze 相关应用时使用。支持流式和非流式对话、工作流调用等功能。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
调用扣子(Coze)智能体 API 进行对话、工作流执行等操作。当用户需要集成 Coze 智能体、调用 Coze API、或开发 Coze 相关应用时使用。支持流式和非流式对话、工作流调用等功能。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Knowledge comic creator supporting multiple styles (Logicomix/Ligne Claire, Ohmsha manga guide). Creates original educational comics with detailed panel layouts and sequential image generation. Use when user asks to create "知识漫画", "教育漫画", "biography comic", "tutorial comic", or "Logicomix-style comic".
AI SDK-based image generation using official OpenAI and Google APIs. Supports text-to-image, reference images, aspect ratios, and quality presets.
A fundamental skill that demonstrates the basic execution of a Python script. It serves as a "Hello, World!" example for the skill system, verifying that the environment is correctly set up and that the agent can execute scripts.
Complete browser automation with Playwright. Auto-detects dev servers, writes clean test scripts to /tmp. Test pages, fill forms, take screenshots, check responsive design, validate UX, test login flows, check links, automate any browser task. Use when user wants to test websites, automate browser interactions, validate web functionality, or perform any browser-based testing.
专业的代码审查助手,提供结构化的审查流程、详细的检查清单和建设性的反馈指南。适用于审查Pull Request、代码提交或任何需要代码质量评估的场景,涵盖功能性、安全性、性能、测试、文档、架构设计等多个维度。
Frontend-focused code review skill for React/TypeScript/Tailwind projects. Analyzes code quality, security vulnerabilities (XSS, CSRF), performance issues, accessibility (WCAG), React best practices, hooks usage, component architecture, responsive design, and SEO. Use when users request code review, want feedback on components, ask about frontend security, performance optimization, or accessibility compliance. Provides actionable feedback with severity levels and fix suggestions.
| name | coze-api |
| description | 调用扣子(Coze)智能体 API 进行对话、工作流执行等操作。当用户需要集成 Coze 智能体、调用 Coze API、或开发 Coze 相关应用时使用。支持流式和非流式对话、工作流调用等功能。 |
扣子(Coze)是字节跳动推出的 AI 智能体开发平台,本 Skill 提供完整的 Coze API 调用指南。
在使用 Coze API 前需要完成以下准备:
获取访问令牌 (Personal Access Token)
获取 Bot ID
https://www.coze.cn/space/123/bot/73482933347348293334发布 Bot 为 API 服务
API 基础 URL
https://api.coze.cn认证方式
Authorization: Bearer {YOUR_PAT_TOKEN}
Content-Type: application/json
使用限制
发起一次完整对话,等待完整结果后返回。
API 端点
POST https://api.coze.cn/v3/chat
Python 示例代码
import requests
import json
API_URL = "https://api.coze.cn/v3/chat"
RETRIEVE_URL = "https://api.coze.cn/v3/chat/retrieve"
MESSAGE_LIST_URL = "https://api.coze.cn/v3/chat/message/list"
# 配置参数
PAT_TOKEN = "YOUR_PAT_TOKEN"
BOT_ID = "YOUR_BOT_ID"
USER_ID = "unique_user_id"
def send_message(message):
"""发起对话"""
headers = {
"Authorization": f"Bearer {PAT_TOKEN}",
"Content-Type": "application/json"
}
data = {
"bot_id": BOT_ID,
"user_id": USER_ID,
"stream": False,
"auto_save_history": True,
"additional_messages": [
{
"role": "user",
"content": message,
"content_type": "text"
}
]
}
response = requests.post(API_URL, headers=headers, json=data)
return response.json()
def check_status(conversation_id, chat_id):
"""查询对话状态"""
headers = {
"Authorization": f"Bearer {PAT_TOKEN}",
"Content-Type": "application/json"
}
params = {
"conversation_id": conversation_id,
"chat_id": chat_id
}
response = requests.get(RETRIEVE_URL, headers=headers, params=params)
return response.json()
def get_messages(conversation_id, chat_id):
"""获取对话消息"""
headers = {
"Authorization": f"Bearer {PAT_TOKEN}",
"Content-Type": "application/json"
}
params = {
"conversation_id": conversation_id,
"chat_id": chat_id
}
response = requests.get(MESSAGE_LIST_URL, headers=headers, params=params)
return response.json()
# 使用示例
result = send_message("你好,请介绍一下自己")
print(json.dumps(result, ensure_ascii=False, indent=2))
实时接收 AI 回复,类似打字机效果。
Python 示例代码
import requests
import json
def stream_chat(message):
"""流式对话"""
headers = {
"Authorization": f"Bearer {PAT_TOKEN}",
"Content-Type": "application/json"
}
data = {
"bot_id": BOT_ID,
"user_id": USER_ID,
"stream": True,
"auto_save_history": False, # 流式时必须为 False
"additional_messages": [
{
"role": "user",
"content": message,
"content_type": "text"
}
]
}
response = requests.post(API_URL, headers=headers, json=data, stream=True)
# 处理流式响应
for line in response.iter_lines():
if line:
line_str = line.decode('utf-8')
# 跳过非 data 行
if not line_str.startswith('data:'):
continue
# 提取 JSON 数据
json_str = line_str.split('data:', 1)[1].strip()
try:
data = json.loads(json_str)
# 处理消息事件
if data.get('event') == 'conversation.message.delta':
content = data.get('data', {}).get('content', '')
print(content, end='', flush=True)
# 处理完成事件
elif data.get('event') == 'conversation.message.completed':
print("\n[对话完成]")
except json.JSONDecodeError:
continue
# 使用示例
stream_chat("写一首关于春天的诗")
请求参数
bot_id (必填): Bot 的唯一标识符user_id (必填): 用户标识符,用于区分不同用户stream (必填): 是否使用流式输出
true: 流式输出,auto_save_history 必须为 falsefalse: 非流式输出,auto_save_history 必须为 trueauto_save_history: 是否自动保存历史记录additional_messages: 消息数组
role: 角色,通常为 "user"content: 消息内容content_type: 内容类型,通常为 "text"conversation_id (可选): 对话 ID,用于继续之前的对话响应字段
conversation_id: 对话 IDchat_id: 本次对话的 IDstatus: 对话状态
in_progress: 处理中completed: 已完成failed: 失败执行已发布的工作流。
API 端点
POST https://api.coze.cn/v3/workflows/run
Python 示例代码
import requests
import json
WORKFLOW_RUN_URL = "https://api.coze.cn/v3/workflows/run"
def run_workflow(workflow_id, parameters):
"""执行工作流"""
headers = {
"Authorization": f"Bearer {PAT_TOKEN}",
"Content-Type": "application/json"
}
data = {
"workflow_id": workflow_id,
"parameters": parameters
}
response = requests.post(WORKFLOW_RUN_URL, headers=headers, json=data)
return response.json()
# 使用示例
workflow_id = "73xxx47"
params = {
"input_text": "需要处理的文本",
"option": "选项A"
}
result = run_workflow(workflow_id, params)
print(json.dumps(result, ensure_ascii=False, indent=2))
非流式对话需要轮询查询状态,直到对话完成。
import requests
import time
import json
def chat_with_polling(message, max_retries=30, interval=2):
"""
发起对话并轮询获取结果
Args:
message: 用户消息
max_retries: 最大重试次数
interval: 轮询间隔(秒)
"""
headers = {
"Authorization": f"Bearer {PAT_TOKEN}",
"Content-Type": "application/json"
}
# 1. 发起对话
data = {
"bot_id": BOT_ID,
"user_id": USER_ID,
"stream": False,
"auto_save_history": True,
"additional_messages": [
{
"role": "user",
"content": message,
"content_type": "text"
}
]
}
response = requests.post(API_URL, headers=headers, json=data)
result = response.json()
if response.status_code != 200:
print(f"发起对话失败: {result}")
return None
conversation_id = result['data']['conversation_id']
chat_id = result['data']['id']
print(f"对话已创建: conversation_id={conversation_id}, chat_id={chat_id}")
# 2. 轮询查询状态
retrieve_url = f"https://api.coze.cn/v3/chat/retrieve"
params = {
"conversation_id": conversation_id,
"chat_id": chat_id
}
for i in range(max_retries):
time.sleep(interval)
status_response = requests.get(retrieve_url, headers=headers, params=params)
status_data = status_response.json()
status = status_data['data']['status']
print(f"查询状态 [{i+1}/{max_retries}]: {status}")
if status == "completed":
# 3. 获取消息列表
message_url = f"https://api.coze.cn/v3/chat/message/list"
message_response = requests.get(message_url, headers=headers, params=params)
message_data = message_response.json()
# 提取 AI 回复
messages = message_data['data']
for msg in messages:
if msg['role'] == 'assistant' and msg['type'] == 'answer':
print("\n=== AI 回复 ===")
print(msg['content'])
return msg['content']
elif status == "failed":
print("对话失败")
return None
print("轮询超时")
return None
# 使用示例
response = chat_with_polling("介绍一下人工智能的发展历史")
400 - 请求参数错误
bot_id 是否正确stream 和 auto_save_history 的组合是否正确401 - 认证失败
403 - 权限不足
429 - 请求频率限制
500 - 服务器错误
def safe_api_call(func, *args, **kwargs):
"""安全的 API 调用"""
try:
result = func(*args, **kwargs)
return result
except requests.exceptions.RequestException as e:
print(f"请求错误: {e}")
return None
except json.JSONDecodeError as e:
print(f"JSON 解析错误: {e}")
return None
except Exception as e:
print(f"未知错误: {e}")
return None
使用 conversation_id 维持多轮对话:
def multi_turn_chat(conversation_id=None):
"""多轮对话"""
data = {
"bot_id": BOT_ID,
"user_id": USER_ID,
"stream": False,
"auto_save_history": True,
"additional_messages": [
{
"role": "user",
"content": "继续我们的对话",
"content_type": "text"
}
]
}
# 如果有 conversation_id,继续之前的对话
if conversation_id:
data["conversation_id"] = conversation_id
# ... 发送请求
非流式 (stream=False): 适合需要完整结果的场景
流式 (stream=True): 适合交互式场景
response = requests.post(
API_URL,
headers=headers,
json=data,
timeout=30 # 设置 30 秒超时
)
在对话中传递上下文信息:
data = {
"bot_id": BOT_ID,
"user_id": USER_ID,
"stream": False,
"auto_save_history": True,
"additional_messages": [...],
"custom_variables": {
"user_name": "张三",
"company": "ABC公司",
"department": "技术部"
}
}
auto_save_history 必须为 falseuser_id 区分不同用户,便于追踪和管理