> ## Documentation Index
> Fetch the complete documentation index at: https://www.bazhuayu.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建或更新密钥

> 写入一个密钥的值，已存在则覆盖（轮换）。

## 端点

```
PUT https://api-datahub.bazhuayu.com/v1/secrets/{name}
```

认证：需要 API Key（`Authorization: Bearer <API Key>`）。

写入密钥值，已存在则覆盖，即轮换。名称是 manifest `runtime.env` 里引用的那个。

## 请求

### 路径参数

<ParamField path="name" type="string" required>
  密钥名称，大写字母、数字与下划线。
</ParamField>

### 请求体

<ParamField body="value" type="string" required>
  密钥明文。只写不读。
</ParamField>

### 示例请求

```bash theme={null}
curl -X PUT \
  -H "Authorization: Bearer $BAZHUAYU_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"value": "sk-example"}' \
  "https://api-datahub.bazhuayu.com/v1/secrets/EXAMPLE_API_KEY"
```

## 响应

### 200 成功

```json theme={null}
{
  "data": {
    "name": "EXAMPLE_API_KEY",
    "masked": "********mple",
    "scope": "publisher",
    "created_at": "2026-09-15T07:45:42.285442+00:00",
    "updated_at": "2026-09-15T07:45:42.285442+00:00"
  }
}
```

返回该密钥的元信息，字段与<a href="/docs/zh/datahub/api/reference/secrets/list-secrets" target="_blank" rel="noopener noreferrer">我的密钥列表</a>的条目相同。

响应包在 `data` 字段中，其内容如下。

<ResponseField name="name" type="string" required>
  —
</ResponseField>

<ResponseField name="masked" type="string" required>
  —
</ResponseField>

<ResponseField name="scope" type="string">
  —
</ResponseField>

<ResponseField name="created_at" type="string" required>
  —
</ResponseField>

<ResponseField name="updated_at" type="string" required>
  —
</ResponseField>

### 错误

| HTTP | `code` | `category` | 说明 |
| - | - | - | - |
| 401 | `unauthorized` | `forbidden` | 缺少或无效的 API Key。 |

错误响应统一为 `{"error": {code, category, message, retryable}}`，见<a href="/docs/zh/datahub/api/reference/introduction#错误" target="_blank" rel="noopener noreferrer">错误</a>。

## 客户端库

Python 与 JavaScript SDK 暂未封装此端点，请直接调用 REST。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.