主导航

遗留 API

管理员 API

以编程方式管理组织资源和行政工作流程。

管理 API(Admin APIs)允许您自动化组织管理工作流程,例如用户邀请、审计日志查看、项目管理、API 密钥管理、支出提醒、数据保留和速率限制操作。使用它们可以实现后台自动化、安全工作流程以及需要在仪表板之外运行的操作工具。

有关端点详情,请参阅管理 API 参考文档,包括管理 API 密钥邀请用户项目以及审计日志

将管理 API 密钥与 SDK 结合使用

要访问这些端点,请创建管理 API 密钥。管理 API 密钥不能用于非管理类端点。

这些 SDK 版本中增加了对管理 API 的支持,可能需要更新您的 SDK 版本:

  • Node: 6.36.0
  • Python: 2.34.0
  • Go: 3.34.0
  • Ruby: 0.61.0
  • Java: 4.34.0

设置 OPENAI_ADMIN_KEY,然后为您的语言初始化 SDK。

使用管理 API 密钥设置 SDK
1
2
3
4
5
import OpenAI from "openai";

const client = new OpenAI({
  adminAPIKey: process.env.OPENAI_ADMIN_KEY,
});

限制项目的模型访问权限

使用项目模型权限来为项目设置允许列表(allowlist)或拒绝列表(denylist)。将 mode 设置为 allow_list 仅允许列出的模型,或将 mode 设置为 deny_list 以阻止列出的模型,同时允许其他可用模型。模型 ID 必须对组织可见,包括可见的微调模型快照。

设置项目模型允许列表/拒绝列表
1
2
3
4
5
6
7
const modelPermissions =
  await client.admin.organization.projects.modelPermissions.update("proj_abc", {
    mode: "allow_list",
    model_ids: ["gpt-4.1", "o3"],
  });

console.log(modelPermissions.mode);

管理支出限额提醒

使用项目支出提醒在项目支出达到阈值时通知您的团队。阈值金额以分为单位。

创建项目支出限额提醒
1
2
3
4
5
6
7
8
9
10
11
12
13
const spendAlert =
  await client.admin.organization.projects.spendAlerts.create("proj_abc", {
    currency: "USD",
    interval: "month",
    notification_channel: {
      recipients: ["billing@example.com"],
      type: "email",
      subject_prefix: "[OpenAI spend]",
    },
    threshold_amount: 50000,
  });

console.log(spendAlert.id);

管理数据保留

使用项目数据保留控制来覆盖或继承组织的保留策略。将 retention_type 设置为 organization_default 以继承组织设置。

设置项目数据保留
1
2
3
4
5
6
const dataRetention =
  await client.admin.organization.projects.dataRetention.update("proj_abc", {
    retention_type: "organization_default",
  });

console.log(dataRetention.type);

通过电子邮件邀请用户

使用邀请(Invites)端点向电子邮件地址发送组织邀请。

通过电子邮件邀请用户
1
2
3
4
5
6
const invite = await client.admin.organization.invites.create({
  email: "user@example.com",
  role: "reader",
});

console.log(invite.id);

检索审计日志

使用审计日志(Audit Logs)端点列出组织中近期的用户操作和配置更改。

检索审计日志
1
2
3
4
5
const auditLogs = await client.admin.organization.auditLogs.list({
  limit: 10,
});

console.log(auditLogs.data);
© . This website operates independently and is not affiliated with or endorsed by OpenAI, Inc. All brand names, logos, and trademarks are the property of their respective owners.