Custom GPT Actions 实战:从单一 GPT 到企业级 GPT 生态
Custom GPT Actions 是把 GPT 接进自家 API 的官方机制。本文覆盖 schema 设计、OAuth 鉴权、GPT Store 发布、企业部署(Teams / Enterprise 共享)、Actions 调试(Inspector)与安全最佳实践。
操作步骤
设计 Actions OpenAPI schema
写一个 OpenAPI 3.1 schema,描述 /customers/{id}/orders 的 GET endpoint、参数(customer_id)、返回结构(订单数组)。Schema 用 YAML 写到 Custom GPT Actions 配置里。
配置鉴权(API key)
在 Authentication tab 选 API key,把 key 写在 server-side(用户看不到)。GPT 调用时会自动带上 header。
用 Inspector 调试
打开 Actions Inspector,模拟 5-10 个 query 看 schema 是否匹配、参数是否正确。重点测:(1) 参数缺失时的 fallback;(2) 找不到客户时的错误处理;(3) 返回结构变化时的鲁棒性。
加 system prompt 引导
在 Custom GPT system prompt 里写明:何时调 /customers/{id}/orders(trigger 条件)、如何把订单列表转成自然语言回答、调失败时怎么 fallback。
发布 + 测试
GPT Store 发布(如果给外部用户用)或私有工作区(如果内部用)。发布后跑完整对话测试:正常 / 异常 / 边界 case 各 5 条。
Custom GPT Actions 是 OpenAI 给 GPT 增加的『调外部 API』能力。本文从单一 GPT 接自家 API 写到企业级部署——schema 设计、鉴权、GPT Store 发布、企业 Teams / Enterprise 共享、调试、安全最佳实践。
Actions 本质:GPT + OpenAPI + HTTP
┌────────────────────────────────────┐
│ 用户问:"客户 X 最近下了什么单?" │
└────────────────────────────────────┘
↓
┌────────────────────────────────────┐
│ Custom GPT(LLM) │
│ - 看 system prompt + 用户问题 │
│ - 决定调哪个 action │
│ - 决定传什么参数 │
└────────────────────────────────────┘
↓
┌────────────────────────────────────┐
│ Actions 引擎(ChatGPT 代理) │
│ - 调 HTTP endpoint │
│ - 鉴权 header │
│ - 返回结果给 LLM │
└────────────────────────────────────┘
↓
┌────────────────────────────────────┐
│ 后端 API(你的服务) │
│ - /customers/{id}/orders │
│ - 鉴权、查询、返回数据 │
└────────────────────────────────────┘
三个组件:
- Custom GPT:用户配置的 GPT(有 system prompt + knowledge + Actions schema)。
- Actions 引擎:ChatGPT 后端代理,负责 HTTP 调用 + 鉴权。
- 后端 API:你的服务(CRM / 工单系统 / 知识库)。
Actions schema 设计
OpenAPI 3.1 子集是 Actions 的标准格式。最小示例:
openapi: 3.1.0
info:
title: CRM API
description: 客户与订单管理 API
version: 1.0.0
servers:
- url: https://crm.example.com/api
paths:
/customers/{customer_id}/orders:
get:
operationId: get_customer_orders
summary: 获取指定客户的最近订单
description: |
当用户询问「客户 X 的订单」「客户 X 最近买了什么」时调用。
返回最近 30 天的订单列表。
parameters:
- name: customer_id
in: path
required: true
schema:
type: string
description: 客户 ID(如 C001)
- name: limit
in: query
required: false
schema:
type: integer
default: 10
description: 返回订单数量限制
responses:
'200':
description: 订单列表
content:
application/json:
schema:
type: object
properties:
orders:
type: array
items:
type: object
properties:
order_id: { type: string }
amount: { type: number }
status: { type: string }
created_at: { type: string, format: date-time }
关键设计:
operationId:GPT 用它来引用这个 action,命名要清晰(get_customer_orders而非getOrders1)。description:包含 trigger 条件(什么情况下 GPT 该调这个 action)和返回结构。这是 GPT 决定『调不调 / 怎么用』的核心依据。parameters必须 schema 详细:每个参数都有 type / description,避免 GPT 传错值。
鉴权
| 类型 | 适用 | 配置 |
|---|---|---|
| None | 公开数据 | 不设 |
| API key | 自家系统 | 选 API key 类型,填 key(用户看不到),GPT 自动带 header |
| OAuth 2.0 | 第三方 API(Notion / Slack) | 配置 authorization URL / token URL / scopes |
OAuth 配置示例(接 Notion):
Authorization URL: https://api.notion.com/v1/oauth/authorize
Token URL: https://api.notion.com/v1/oauth/token
Scopes: read_content, update_content
用户首次跟 GPT 对话时,会跳到 Notion 登录页授权,之后 GPT 拿短期 access token 调 API。
GPT Store 发布
发布到公共 GPT Store 的关键步骤:
- 完成基础信息:logo、name(≤ 40 字)、description(≤ 8000 字)、category。
- 隐私与法律:填写 privacy policy URL(公开页面)。
- Actions 测试:每个 action 跑 10+ 测试用例,确认无 schema 错误。
- Submit for review:在 GPT Builder 后台提交,OpenAI 团队人工审核(通常 1-2 周)。
- Featured 推荐:审核通过后可申请首页 Featured——这才是 discoverability 的关键。
提高 discoverability 的三件事:
- 头像 + 名称 + 描述足够抓人(用户第一眼)。
- 类别标签准确(用户搜索时能命中)。
- 早期拉一波真实用户评分(分享到社群 / 朋友圈)。
企业部署
三种部署形态:
| 形态 | 可见性 | 适用 |
|---|---|---|
| Public | 全网可见 + GPT Store 搜索 | 工具型 / 娱乐型 GPT |
| Unlisted | 有链接能用,搜索不到 | 半公开(团队外 demo) |
| Private to workspace | 工作区内可见,SSO 控制 | 企业内部 |
企业部署的关键设置:
- Privacy:
Only people in my workspace - Allowed users: SSO 域(如
@yourcompany.com) - Audit log: 开启,记录每次调用
- Data retention: 控制 retention 周期(默认 30 天)
调试:Inspector 工具
Custom GPT 编辑器的 Actions tab 里有个 Inspector Playground:
1. 打开 GPT Builder → Actions → Test
2. 输入模拟 query:"客户 C001 最近下了什么单?"
3. 看 GPT 是否触发 get_customer_orders action
4. 看参数是否正确(customer_id="C001")
5. 看后端返回是否符合 schema
外部调试技巧:
- 用
ngrok http 8000把本地服务暴露到公网,URL 填进 GPT 配置。 - 在后端加详细日志(每次调用打印 endpoint / params / user_id)。
- 生产前跑完整 test suite。
安全最佳实践
Actions 接进的是用户对话——攻击面比普通 API 大。三层防护:
1. 防 prompt injection
# 后端:不要把用户原话传给 GPT 作为『工具返回值』
@app.post("/query")
def query(query: str, user: User):
# 用户的查询原话可能含 prompt injection
# 不要 echo 回模型
result = safe_search(query)
return {"result": result, "trusted": True}
GPT 收到工具返回值时要知道『这是系统数据不是用户输入』。
2. 限流
# 每个 user / IP / endpoint QPS 限速
@limiter.limit("100/minute", key_func=lambda: request.user_id)
@limiter.limit("10/second", key_func=lambda: request.remote_addr)
def call_action():
...
Actions 一旦上线,单个用户可以高频调,限流是必须的。
3. 审计
# 每次调用记日志
audit_log.record(
user_id=user.id,
action="get_customer_orders",
params={"customer_id": customer_id},
timestamp=now(),
response_status=200,
)
合规要求(金融 / 医疗)+ 事后溯源都需要 audit log。
完整 schema 示例
接企业 CRM 的最小可用 schema:
openapi: 3.1.0
info:
title: Enterprise CRM
description: 客户、订单、产品查询
version: 1.0.0
servers:
- url: https://crm.example.com/api/v1
paths:
/customers/{customer_id}:
get:
operationId: get_customer
summary: 查询客户基本信息
parameters:
- name: customer_id
in: path
required: true
schema: { type: string }
responses:
'200':
description: 客户信息
content:
application/json:
schema:
type: object
properties:
customer_id: { type: string }
name: { type: string }
email: { type: string }
tier: { type: string, enum: [gold, silver, bronze] }
/customers/{customer_id}/orders:
get:
operationId: get_customer_orders
summary: 查询客户订单
parameters:
- name: customer_id
in: path
required: true
schema: { type: string }
- name: limit
in: query
schema: { type: integer, default: 10 }
responses:
'200':
description: 订单列表
content:
application/json:
schema:
type: object
properties:
orders:
type: array
items:
type: object
properties:
order_id: { type: string }
amount: { type: number }
status: { type: string }
部署 checklist
- Actions schema 用 OpenAPI 3.1,operationId / description 清晰
- 鉴权按场景选(自家 API 用 API key,第三方用 OAuth)
- 每个 action 跑 10+ 测试 query(正常 / 异常 / 边界)
- 后端有 prompt injection 防护(不 echo 用户原话)
- 限流按 user / IP / endpoint 多维度
- Audit log 记录 user_id / endpoint / params / 时间戳
- GPT Store 发布有 privacy policy URL
- 企业部署用 Private to workspace + SSO
常见坑
- schema description 写得太笼统:GPT 不会精确知道何时调。description 必须含 trigger 条件 + 参数说明 + 返回结构。
- 鉴权选 OAuth 但没配 refresh token:短期 access token 过期后用户要重新授权,体验差。配 refresh token 让 GPT 自动续期。
- 不测边界 case:schema 测通后没测『参数缺失』『返回空』『返回错误』三种情况,GPT 拿到错误响应不知道怎么 fallback。
- 企业部署忘了关 audit:默认开启但 retention 不设,企业合规要求保留 1 年以上。
- schema 版本不演进:API 改了但 schema 没同步更新,GPT 拿到返回对不上 schema 直接报错。Schema 用 Git 管理,跟后端 API 同步更新。
下一步
- 想了解 Custom GPT 入门?读 《Custom GPTs 完全上手指南:从想法到发布到 GPT Store》。
- 想了解 GPT Store 上线全流程?读 《自定义 GPT 完全指南:从想法到上线 GPT Store》。
- 想了解 Actions 背后的 Responses API?读 《OpenAI API 函数调用实战:Responses API 工具使用完全指南》。
关键要点
- Actions 本质是 GPT + OpenAPI 3.1 schema + HTTP 后端。schema 描述 endpoint、参数、返回结构,GPT 在对话中『看到』schema 后决定调哪个 endpoint、传什么参数
- 鉴权两种:API key(适合内部 / 自家系统,写到 Actions 后端 server-side)+ OAuth 2.0(适合第三方 API、需要用户授权的场景,如 Notion / Slack)
- GPT Store 发布前必须过三关:(1) schema 测试通过(用 Inspector 工具跑 10+ 测试用例);(2) privacy policy URL 公开;(3) 头像 + 描述 + 类别完整
- 企业部署走 Teams / Enterprise 私密 GPT:仅本工作区可见、SSO 控制、不进 GPT Store 公共搜索。适合内部知识库 / 内部工具集成
- Actions 安全三层:(1) 后端做 prompt injection 防护(不要把用户 / 工具返回值原样回传给模型);(2) 限流(每用户 / 每 IP / 每 endpoint QPS 限速);(3) 审计日志(每次调用记 user_id / endpoint / 参数)
常见问题
官方参考
相关文章
订阅 GPTMap Weekly
每周一封邮件,精选 OpenAI 重要更新、深度解读与最佳实践。无广告,可随时退订。