API 密钥

本页内容

API 密钥可让您自己的软件,或任何支持 BYOK(Bring Your Own Key,自带密钥)的第三方系统,使用 Performance Hub 发布的模型。密钥在 Settings(齿轮)→ Service Access & API Keys 下管理。您必须是 Organisation Administrator 才能管理密钥。

"Provision API keys so third-party software and systems that support BYOK (Bring Your Own Key) can connect to models published by Performance Hub."(配置 API 密钥,使支持 BYOK(自带密钥)的第三方软件和系统能够连接到 Performance Hub 发布的模型。)

API 密钥列表API 密钥列表

图 1:API 密钥列表:标签、遮蔽的密钥、状态、支出和限额、模型、上次使用时间以及行操作

密钥列表

列含义
Label您为密钥指定的可选名称。
Key遮蔽后的密钥(例如 phk_7Qm2…Xa9LkP):创建后完整密钥不会再次显示。
StatusActive、Provisioning…(新密钥设置期间短暂显示)或 Disabled(已吊销;该行显示为灰色)。
Spend / limits终身支出,以及相对于密钥上所设支出限额的进度。
Modelsall,或该密钥被限制使用的模型数量。
Last used该密钥上次发出请求的时间。
ActionsEdit、Rotate、Revoke(或 Re-activate)、Delete。

如果您使用 Workflows,Workflows 行会显示 Managed service,而不是遮蔽的密钥。如果没有任何密钥,列表会显示 "No API keys yet."

创建密钥

点击 Create key。Create API key 抽屉随即打开:

Create API key 抽屉Create API key 抽屉

图 2:Create API key 抽屉:标签、连接类型、支出限额、速率限制、模型限制和防护规则覆盖

设置行为
Label (optional)密钥的名称,通常是该密钥所用于的系统(例如 Hotel Concierge App、Clinic Intake Assistant 或 Booking Website)。强烈建议填写:Activity 和 Logs 中正是通过标签来归属使用情况。
Connection typeAPI key:"Generic API keys remain in the API Keys list."(通用 API 密钥保留在 API Keys 列表中。)External agent:"External agents appear under Connected Services and use this key to authenticate."(外部代理显示在 Connected Services 下,并使用此密钥进行身份验证。)在创建密钥时设置,之后无法更改。
Set spend limits for this key"Set any combination of daily, monthly and lifetime caps for this key."(为此密钥设置每日、每月和终身上限的任意组合。)包括 Daily limit("Resets at the start of each day (facility timezone).",在每天开始时重置(设施时区))、Monthly limit("Resets on the 1st of each month (facility timezone).",在每月 1 日重置(设施时区))和 Lifetime cap("Total spend over the lifetime of this key. Never resets.",此密钥整个生命周期内的总支出,永不重置)。
Rate limits (optional)"Cap requests and tokens per minute for this key. Leave blank for unlimited."(限制此密钥每分钟的请求数和令牌数。留空表示不限制。)包括 Requests / min 和 Tokens / min。
Restrict models for this key"Only the selected models will be usable with this key."(此密钥只能使用所选模型。)从设施已启用的模型中选择。
Override facility guardrails for this key"Select none to explicitly disable guardrails for this key."(不选择任何项即可为此密钥明确禁用防护规则。)开启后,此密钥将使用自己的防护规则选择(包括“无”),而不是设施的防护规则。请参阅 Guardrails。

点击 Create key。

一次性密钥显示

新密钥只会在 Copy your API key 对话框中显示一次:

Copy your API key 对话框Copy your API key 对话框

图 3:新密钥只显示一次:请在关闭对话框之前复制

"This is the only time the full key is shown. Store it somewhere safe."(这是唯一一次显示完整密钥。请将其妥善保存。)

在点击 Done 之前,请将其复制到您的密钥管理器中。此对话框关闭后,只会显示遮蔽后的形式。如果丢失了密钥,请对该密钥执行 Rotate 以获取新密钥。

编辑密钥

点击密钥所在行(或其 Edit 铅笔图标),打开 Configure API key 抽屉,其中的设置与创建时相同(标签、支出限额、速率限制、模型限制、防护规则覆盖):

Configure API key 抽屉Configure API key 抽屉

图 4:Configure API key 抽屉

更改在保存后片刻即会生效。当密钥设有每日/每月限额时,其所在行会显示相对于限额的使用情况(Today、This month、Lifetime),达到某项限额时会显示 Limit reached 标记。

密钥生命周期:轮换、吊销、删除

每项操作都有一个确认对话框,准确说明将会发生的情况:

操作效果确认文本
Rotate以相同设置签发新密钥(只显示一次);旧密钥立即失效。"A new key will be issued and the current key will stop working immediately."(将签发新密钥,当前密钥将立即失效。)"You will need to reconfigure any services still using the old key. This cannot be undone."(您需要重新配置仍在使用旧密钥的所有服务。此操作无法撤消。)
Revoke立即禁用密钥,可恢复。"This key will be disabled immediately and any services using it will stop working. You can re-activate it again later."(此密钥将立即被禁用,所有使用它的服务都将停止工作。您可以稍后重新激活它。)
Re-activate恢复已吊销的密钥(密钥值不变)。无,立即执行。
Delete永久删除密钥。"This permanently deletes the key and any services using it will stop working. This cannot be undone."(此操作将永久删除该密钥,所有使用它的服务都将停止工作。此操作无法撤消。)

删除 API 密钥确认删除 API 密钥确认

图 5:删除 API 密钥确认

**如何选择:**怀疑泄露时执行轮换(服务保留其设置和历史记录,只需更新密钥);需要暂时停用某个系统时执行吊销;仅当集成永久不再使用时才删除。

使用密钥进行连接

密钥列表下方的 Connecting to the API 卡片会显示适用于您环境的基础 URL 和可直接复制粘贴的示例请求。有关包含 SDK 示例和错误处理的完整快速入门,请参阅连接您的应用程序。