> ## 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.

# Client

The `cyborg::Client` class manages storage configurations and acts as a factory for creating or loading encrypted indexes.

## Constructor

```cpp theme={null}
cyborg::Client(const std::string& api_key,
               cyborg::StorageConfig storage_config,
               const int cpu_threads,
               const GPUConfig gpu_config);
```

Initializes a new instance of `Client`.

### Parameters

| Parameter        | Type                                      | Description                                                                                                                                                                                                                      |
| ---------------- | ----------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `api_key`        | `std::string`                             | API key for your CyborgDB account.                                                                                                                                                                                               |
| `storage_config` | [`StorageConfig`](../types#storageconfig) | Backing store shared across the client and all of its indexes. Built via `StorageConfig::Memory()`, `StorageConfig::Disk(path)`, or `StorageConfig::S3(bucket)`.                                                                 |
| `cpu_threads`    | `int`                                     | Number of CPU threads to use (e.g., `0` to use all available cores).                                                                                                                                                             |
| `gpu_config`     | [`GPUConfig`](../types#gpuconfig)         | GPU operations configuration (requires CUDA). Use bitflags: `kNone` (no GPU), `kUpsert` (GPU for upsert), `kTrain` (GPU for training), `kQuery` (GPU for query), or `kAll` (GPU for all operations). Combine with `\|` operator. |

<Warning>`Client` is **non-copyable and non-movable** — it owns unique keystore handles. Construct it in place, or hold it via `std::unique_ptr<cyborg::Client>`.</Warning>

### Exceptions

<AccordionGroup>
  <Accordion title="std::invalid_argument">
    * Throws if the `cpu_threads` parameter is less than `0`.
    * Throws if the [`StorageConfig`](../types#storageconfig) is invalid.
    * Throws if the GPU is not available when `gpu_accelerate` is `true`.
  </Accordion>

  <Accordion title="std::runtime_error">
    * Throws if the backing store is not available.
    * Throws if the Client could not be initialized.
  </Accordion>
</AccordionGroup>

### Example Usage

```cpp theme={null}
#include "cyborgdb_core/client.hpp"

std::string api_key = "your_api_key_here";  // Replace with your CyborgDB API key
int cpu_threads = 4;

// In-memory backing store (use StorageConfig::Disk(path) or ::S3(bucket) to persist).
cyborg::StorageConfig storage = cyborg::StorageConfig::Memory();

// Example 1: Enable GPU for all operations
cyborg::Client client1(api_key, cyborg::StorageConfig::Memory(), cpu_threads, cyborg::kAll);

// Example 2: Enable GPU for specific operations (upsert, train, and query)
cyborg::GPUConfig gpu_config_selective = cyborg::kUpsert | cyborg::kTrain | cyborg::kQuery;
cyborg::Client client2(api_key, cyborg::StorageConfig::Memory(), cpu_threads, gpu_config_selective);

// Example 3: Disable GPU completely
cyborg::Client client3(api_key, cyborg::StorageConfig::Memory(), cpu_threads, cyborg::kNone);

// Hold the client via unique_ptr (Client is non-movable)
auto client = std::make_unique<cyborg::Client>(
    api_key, cyborg::StorageConfig::Disk("/tmp/cyborgdb"), cpu_threads, cyborg::kNone);
```

<Note>Get your API key from the [API key page](../../../intro/get-api-key).</Note>

***

## Methods

### `cpu_threads()`

```cpp theme={null}
int cpu_threads() const;
```

Returns the number of CPU threads configured for this client.

**Returns:** `int` - The number of CPU threads.

**Example:**

```cpp theme={null}
int threads = client.cpu_threads();
std::cout << "Using " << threads << " CPU threads" << std::endl;
```

***

### `gpu_accelerate()`

```cpp theme={null}
bool gpu_accelerate() const;
```

Checks if GPU acceleration is enabled for any operations.

**Returns:** `bool` - `true` if GPU is enabled for any operation, `false` otherwise.

**Example:**

```cpp theme={null}
if (client.gpu_accelerate()) {
    std::cout << "GPU acceleration is enabled" << std::endl;
}
```

***

### `gpu_config()`

```cpp theme={null}
GPUConfig gpu_config() const;
```

Returns the GPU operations configuration for this client.

**Returns:** [`GPUConfig`](../types#gpuconfig) - The GPU operations configuration.

**Example:**

```cpp theme={null}
cyborg::GPUConfig config = client.gpu_config();
if (config & cyborg::kTrain) {
    std::cout << "GPU is enabled for training" << std::endl;
}
```
