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

# Generate Key

Generates a random 32-byte (256-bit) key for creating an encrypted index with an SDK-supplied key.

```python theme={null}
@staticmethod
Client.generate_key(save: bool = False) -> bytes
```

### Parameters

| Parameter | Type | Default | Description |
| - | - | - | - |
| `save` | `bool` | `False` | *(Optional)* Store the key at `~/.cyborgdb/index_key`, or reuse the key already stored there. |

### Returns

`bytes`: 32 bytes from Python's `secrets.token_bytes(32)`, which reads the operating system's cryptographic random source.

### Saving the key

With `save=True`:

* If `~/.cyborgdb/index_key` exists and holds exactly 32 bytes, that key is returned and no new key is generated.
* Otherwise a new key is generated, written to that file, and returned.

The file is not encrypted, and the SDK logs a warning each time it's used. Use `save=True` for local development only; in production, store keys in a secrets manager or use a KMS-backed index. See [Managing Encryption Keys](../../guides/advanced/managing-keys).

<Warning>An index created with an SDK-supplied key can only be opened with that exact key. If the key is lost, the index's data can't be decrypted.</Warning>

### Example Usage

```python theme={null}
from cyborgdb import Client

client = Client(base_url='http://localhost:8000', api_key='your-api-key')

index_key = Client.generate_key()
print(len(index_key))
# Output: 32

index = client.create_index('my-secure-index', index_key)

# Keep the key somewhere safe, e.g. as hex in a secrets manager
key_hex = index_key.hex()
```


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