# Replace key

URL: https://docs.hanzo.ai/docs/openapi/websearch/set-search-engine-key

> Seals an engine's API key in KMS, replacing any key held.

`PUT /v1/websearch/engines/{name}/key`

> [Websearch →](https://docs.hanzo.ai/docs/openapi/websearch) · [All API references →](https://docs.hanzo.ai/docs/openapi) · [Get started →](https://docs.hanzo.ai/docs/guides)

|               |                                                        |
| ------------- | ------------------------------------------------------ |
| **Address**   | `https://api.hanzo.ai/v1/websearch/engines/{name}/key` |
| **Method**    | `PUT`                                                  |
| **Operation** | `set_search_engine_key`                                |
| **Auth**      | `Authorization: Bearer $HANZO_API_KEY`                 |

Seals an engine's API key in KMS, replacing any key held.

The key is the platform's: it lives in KMS under the platform org admin at
/websearch/\<ENGINE>\_KEY (env prod), every search reads it from there at the
moment it runs, and no
operation returns, logs or echoes it — the answer says only that a key is now
held. Only an engine that takes a key accepts one (mojeek, brave).

SuperAdmin only. 404 for an engine that does not exist, 400 for one that takes
no key or a key that is empty, longer than 4096 bytes or holds whitespace or
control characters, 503 when KMS cannot take it.

## Request

3 fields, body `application/json` (required).

| Field  | In   | Type   | Required | Description                        |
| ------ | ---- | ------ | -------- | ---------------------------------- |
| `name` | path | string | yes      | Name is the engine, from the path. |
| `key`  | body | string | —        | Key is the API key.                |
| `name` | body | string | —        | Name is the engine, from the path. |

## Response

| Status    | Body                        | Meaning |
| --------- | --------------------------- | ------- |
| `200`     | websearch.searchEngineKeyed | ok      |
| `default` | problem-details             | refused |

`200` body — 2 fields.

| Field   | In   | Type    | Always | Description                         |
| ------- | ---- | ------- | ------ | ----------------------------------- |
| `keyed` | body | boolean | —      | Keyed is whether a key is now held. |
| `name`  | body | string  | —      | Name is the engine.                 |

Failure carries the platform error shape — see [Errors](https://docs.hanzo.ai/docs/errors).

## Examples

**CLI**

```bash
hanzo websearch engines key replace <name>
```

**SDK**

**.ts**

```ts
import { Configuration, WebsearchApi } from 'hanzoai';

const api = new WebsearchApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const { data } = await api.setSearchEngineKey({ name: 'name', key: "<key>", name: "<name>" });
```

**.py**

```python
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import WebsearchApi

client = ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"]))
result = WebsearchApi(client).set_search_engine_key(name='name', key="<key>", name="<name>")
```

**.go**

```go
cfg := hanzoai.NewConfiguration()
cfg.AddDefaultHeader("Authorization", "Bearer "+os.Getenv("HANZO_API_KEY"))
client := hanzoai.NewAPIClient(cfg)

resp, _, err := client.WebsearchAPI.SetSearchEngineKey(context.Background()).Execute()
if err != nil {
	return err
}
```

**.rs**

```rust
use hanzo_client::apis::{configuration::Configuration, websearch_api};

let mut cfg = Configuration::new();
cfg.bearer_access_token = std::env::var("HANZO_API_KEY").ok();

let result = websearch_api::set_search_engine_key(&cfg, Default::default()).await?;
```

**.java**

```java
import ai.hanzo.cloud.ApiClient;
import ai.hanzo.cloud.api.WebsearchApi;

ApiClient client = new ApiClient();
client.setBearerToken(System.getenv("HANZO_API_KEY"));

var result = new WebsearchApi(client).setSearchEngineKey();
```

**HTTP**

```bash
curl -X PUT https://api.hanzo.ai/v1/websearch/engines/<name>/key \
  -H "Authorization: Bearer $HANZO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
       "key": "<key>",
       "name": "<name>"
     }'
```

**MCP**

MCP reaches **websearch** through the `websearch` tool, which names its 3 operations with its own verbs — this one among them, under a name only MCP declares. `describe` explains any of them:

```bash
curl -X POST https://api.hanzo.ai/v1/mcp \
  -H "Content-Type: application/json" \
  -d '{
       "jsonrpc": "2.0",
       "id": 1,
       "method": "tools/call",
       "params": {
         "name": "describe",
         "arguments": {
           "op": "list_search_engines"
         }
       }
     }'
```

---

[Websearch API](https://docs.hanzo.ai/docs/openapi/websearch) · [All Hanzo APIs](https://docs.hanzo.ai/docs/openapi) · [Interactive reference](https://docs.hanzo.ai/docs/openapi/reference)
