BYOK
注册、测试与吊销你自己的供应商凭证。
概览
基础路径:
/v1/byokPython 命名空间:
account.byoktext
# Python
from infrai import account
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.byok方法
byok.register
POST /v1/byok
注册供应商凭证,以通过你自己的密钥分发调用。
Python
python
account.byok.register(provider=..., alias=..., credentials={...}, idempotency_key=None)TypeScript
typescript
client.byok.register(opts: ByokRegisterOptions): Promise<ByokKey>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
provider | ByokProvider | string | 必填 | 供应商 provider id,例如 openai。 |
alias | string | 必填 | 你为该凭证选择的标签。 |
credentials | Record<string, string> | 必填 | 供应商凭证字段(只写)。 |
idempotency_key | string | 可选 | 可选去重 key;相同重试将返回同一结果。 |
返回
ByokKey { byok_id, provider, alias, state, created_at, test_result? }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import account
# Register your own vendor key; it is stored server-side after registration.
reg = account.byok.register(
provider="openai",
alias="team-main",
credentials={"api_key": "sk-..."},
)
byok_id = reg.get("byok_id") or reg.get("id")
print("id:", byok_id, "| state:", reg.get("state"))
# Test the key end-to-end (server-side).
tested = account.byok.test(id=byok_id)
print("test ok:", tested.get("ok") or tested.get("status"))byok.list
GET /v1/byok
列出你已注册的 BYOK 凭证。
Python
python
account.byok.list()TypeScript
typescript
client.byok.list(): Promise<{ items }>返回
{ items: ByokKey[] }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import account
for k in account.byok.list().get("items", []):
print(k.get("byok_id"), k.get("provider"), k.get("state"))byok.test
POST /v1/byok/{id}/test
测试某个 BYOK 凭证的连通性。
Python
python
account.byok.test(id=byok_id)TypeScript
typescript
client.byok.test(byokId: string): Promise<{ ok, latency_ms?, error? }>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 必填 | BYOK 凭证 id。 |
返回
{ ok, latency_ms?, error? }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import account
res = account.byok.test(id="byok_...")
print("ok:", res.get("ok"), "| latency_ms:", res.get("latency_ms"))byok.revoke
DELETE /v1/byok/{id}
吊销某个 BYOK 凭证。
Python
python
account.byok.revoke(id=byok_id)TypeScript
typescript
client.byok.revoke(byokId: string): Promise<{ ok }>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 必填 | BYOK 凭证 id。 |
返回
{ ok: boolean }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import account
print("revoked:", account.byok.revoke(id="byok_...").get("ok"))