BazaarLinkBazaarLink
登入
文件API 參考SDK 參考Agent 應用AI Skills
管理金鑰

建立 BYOK 金鑰

為組織建立一把 BYOK 上游金鑰並立即同步模型目錄。上游金鑰(apiKey)僅在此請求中以明文出現,儲存時加密,之後永遠只回傳遮蔽形式(keyMask)。建立成功回 201,附上金鑰物件與模型同步結果(sync)。

POST/api/v1/management/byok-keys

驗證

Authorization必填
string · header

在 Authorization 標頭以 Bearer token 傳入 API 金鑰。

Body

name必填
string

金鑰的顯示名稱。

1-200 chars
baseUrl必填
string

上游供應商的 API base URL。私有/內網位址會被拒絕(400)。

1-2000 chars, public HTTPS endpoint
apiKey必填
string

上游供應商的 API 金鑰明文。只在此請求出現;儲存加密,之後僅回傳 keyMask。

1-2000 chars
protocol
string

上游的 API 介面協定,預設 openai。

openaianthropic
Example: "openai"
fallbackMode
string

上游失敗時的行為:seamless(預設)=無縫回退到平台路由;strict=不回退,直接回錯誤。

seamlessstrict
Example: "seamless"
disabledCanonicalIds
string[]

建立時要先停用的模型(canonical id)清單;同步後這些模型不會經此金鑰路由。

≤2000 items
scopedApiKeyIds
string[]

限定此 BYOK 只套用於哪些平台 API 金鑰(金鑰 id)。空/省略=組織全部金鑰適用。含不屬於你組織的金鑰 id 會被拒(400)。

≤200 items; must be your own keys
POST /api/v1/management/byok-keys
curl https://bazaarlink.ai/api/v1/management/byok-keys \
  -H "Authorization: Bearer $BAZAARLINK_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "team-upstream",
    "baseUrl": "https://api.example-upstream.com/v1",
    "apiKey": "'$UPSTREAM_API_KEY'",
    "protocol": "openai",
    "fallbackMode": "seamless"
  }'
回應範例

已建立。key 為金鑰物件(僅含 keyMask);sync 回報模型目錄同步結果:matched(對上平台目錄的模型數)、unmatched(上游有但平台目錄沒有的模型 id)、stale(是否需要之後重新同步)。

{
  "key": {
    "id": "byok_abc123",
    "ownerType": "org",
    "userId": null,
    "organizationId": "org_abc123",
    "name": "team-upstream",
    "baseUrl": "https://api.example-upstream.com/v1",
    "keyMask": "sk-abc…wxyz",
    "protocol": "openai",
    "enabled": true,
    "fallbackMode": "seamless",
    "modelsStale": false,
    "lastVerifiedAt": "2026-07-29T00:00:00.000Z",
    "lastErrorAt": null,
    "lastErrorCode": null,
    "errorCount1h": 0,
    "createdAt": "2026-07-29T00:00:00.000Z",
    "updatedAt": "2026-07-29T00:00:00.000Z",
    "models": [
      {
        "canonicalId": "openai/gpt-4o",
        "upstreamModelId": "gpt-4o",
        "enabled": true
      }
    ],
    "scopedApiKeyIds": []
  },
  "sync": {
    "matched": 12,
    "unmatched": [
      "internal-model-x"
    ],
    "stale": false
  }
}
客服
客服
您好!有什麼可以協助?
請留下訊息,我們會盡快回覆。
建立 BYOK 金鑰 — BazaarLink API