> ## 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 secure random 32-byte encryption key for index encryption.

<Tabs>
  <Tab title="Embedded">
    ```python theme={null}
    @staticmethod
    generate_key() -> bytes
    ```

    ### Returns

    `bytes`: Cryptographically secure 32-byte key

    ### Example Usage

    ```python theme={null}
    from cyborgdb_core import StorageConfig

    # Generate a new encryption key
    index_key = CyborgVectorStore.generate_key()
    print(f"Key length: {len(index_key)} bytes")

    # Use the key to create a store
    store = CyborgVectorStore(
        index_name="secure_index",
        index_key=index_key,
        api_key="your-api-key",
        embedding="all-MiniLM-L6-v2",
        storage_config=StorageConfig.s3("secure-bucket", region="us-east-1")
    )

    # Store the key securely for future use
    import base64
    encoded_key = base64.b64encode(index_key).decode('utf-8')
    print(f"Base64 encoded key: {encoded_key}")
    ```
  </Tab>

  <Tab title="Python SDK">
    ```python theme={null}
    @staticmethod
    generate_key(save: bool = False) -> bytes
    ```

    ### Parameters

    | Parameter | Type | Default | Description |
    | - | - | - | - |
    | `save` | `bool` | `False` | Whether to save/load the generated key to/from a local file |

    ### Returns

    `bytes`: Cryptographically secure 32-byte key

    ### Example Usage

    ```python theme={null}
    index_key = CyborgVectorStore.generate_key(save=True)

    store = CyborgVectorStore(
        index_name="secure_index",
        index_key=index_key,
        api_key="your-api-key",
        embedding="all-MiniLM-L6-v2",
        base_url="http://localhost:8000"
    )
    ```
  </Tab>

  <Tab title="JS/TS">
    ```typescript theme={null}
    static generateKey(): Uint8Array
    ```

    ### Returns

    `Uint8Array`: Cryptographically secure 32-byte key

    <Note>The JS/TS SDK does not have a `save` parameter. Key persistence must be handled by your application. The return type is `Uint8Array` instead of Python's `bytes`.</Note>

    ### Example Usage

    ```typescript theme={null}
    const indexKey = CyborgVectorStore.generateKey();
    console.log(`Key length: ${indexKey.length} bytes`);

    const store = new CyborgVectorStore(
        new OpenAIEmbeddings(),
        {
            baseUrl: "http://localhost:8000",
            apiKey: "your-api-key",
            indexName: "secure_index",
            indexKey: indexKey
        }
    );
    ```
  </Tab>
</Tabs>

### Security Notes

<Warning>
  Store encryption keys securely! Never commit keys to version control or expose them in logs. Consider using a key management service for production deployments.
</Warning>


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