# 写入密钥 (/docs/api/native/application/putSecret)



`PUT /application/v1/workers/{worker_id}/secrets/{name}`

Create or replace a secret by value or vault reference. Unlike Cloudflare, this derives a new version from the current one and deploys it, so the change is live only once that deployment is active.

**支持状态: supported**

## 参数 [#参数]

| 名称         | 位置   | 类型     | 必填   | 说明                                                                                                       |
| ---------- | ---- | ------ | ---- | -------------------------------------------------------------------------------------------------------- |
| worker\_id | path | string | true | Worker ID (wkr\_…).                                                                                      |
| name       | path | string | true | Secret name as seen in the Worker's env: 1–64 letters, digits or underscores, not starting with a digit. |

## 请求体 (application/json) [#请求体-applicationjson]

必填: true

| 名称     | 类型     | 说明                                                                                                |
| ------ | ------ | ------------------------------------------------------------------------------------------------- |
| source | object | \{type: value, text} stores a value; \{type: vault, vault\_id, secret} references a vault secret. |

```json
{
  "type": "object",
  "required": [
    "source"
  ],
  "properties": {
    "source": {
      "type": "object",
      "additionalProperties": true,
      "description": "{type: value, text} stores a value; {type: vault, vault_id, secret} references a vault secret."
    }
  }
}
```

## 响应 [#响应]

### HTTP 200 [#http-200]

Success

**application/json**

| 名称 | 类型 | 说明 |
| --- | --- | --- |
| secret | object | The secret after the write; its value is not returned. |
| secret.worker_id | string | Owning Worker. |
| secret.name | string | Secret name, as seen by the Worker's env. |
| secret.source | object | &#123;type: value&#125; for a stored value, or &#123;type: vault, vault_id, secret&#125; for a vault reference. Values are never returned. |
| secret.updated_on | string | When the secret last changed. |
| deployment | object | The deployment of the version derived from this change. |
| deployment.id | string | Deployment ID, prefixed dep_. |
| deployment.created_on | string | When the deployment was created. |
| deployment.source | string | Origin: api, sdk, console or rollback. |
| deployment.strategy | string | Rollout strategy. |
| deployment.versions | array&lt;object&gt; | Exactly one version at 100 percent. |
| deployment.annotations | object | Free-form annotations. |
| deployment.author_email | string &#124; null | Who created the deployment. |
| deployment.praxis | object | Platform fields: deployments run asynchronously, so track status, progress and error here. |
