> For the complete documentation index, see [llms.txt](https://docs.cloud.olakrutrim.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cloud.olakrutrim.com/sdk-guide/core-infra-sdk.md).

# Core Infra SDK

### Overview

The Krutrim Core Infrastructure Python SDK (krutrim-client) provides programmatic access to VPCs, VMs, storage, security groups, and Sandbox. Use this SDK for infrastructure and Sandbox APIs; use the separate krutrim-cloud SDK for AI Studio and model APIs.

### Which Python SDK should I use?

* **AI Studio / AI Cloud:** use `krutrim-cloud` for model inference, image generation, speech/text APIs, fine-tuning and BYOM workflows. See the [AI Studio SDK guide](https://docs.cloud.olakrutrim.com/sdk-guide/ai-studio-sdk).
* **Core Infrastructure / Sandbox:** use `krutrim-client` for VPCs, VMs, storage, security groups, and Sandbox. Install `krutrim-client` and import `KrutrimClient` from `krutrim_client`.

These SDKs serve different scopes. Their version numbers are independent, so choose by the APIs you need, not the higher version. The `krutrim-cloud` SDK does not provide Sandbox or Core Infrastructure APIs.

GitHub Repo: <https://github.com/ola-krutrim/Krutrim-client-python>\
Package: <https://pypi.org/project/krutrim-client/>

***

### Installation

```bash
pip install krutrim-client
python -c "from krutrim_client import KrutrimClient"
```

> If installing from source, run the following in the cloned SDK repository:

```bash
python -m pip install .
python -c "from krutrim_client import KrutrimClient"
```

***

### Authentication

```python
pythonCopyEditimport requests

url = "https://cloud.olakrutrim.com/iam/v1/signInAsRootUser"
payload = {
    "email": "<your_email>",
    "password": "<your_password>"
}
response = requests.post(url, json=payload)
access_token = response.json()["access_token"]
```

Tokens refresh every **5 minutes**.\
You should implement a token refresh mechanism for long-running scripts.

***

### Initializing the Client

```python
from krutrim_client import KrutrimClient

client = KrutrimClient(api_key=access_token)
```

***

### Services & Methods

#### 1. Networking – VPC & Subnets

| Method                                                                          | Parameters                                                                                                                                                                                                                                    | Description                     |
| ------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------- |
| `create_vpc(vpc_data: dict, x_region: str)`                                     | <p><strong>vpc\_data</strong> – dict containing <code>network</code>, <code>security\_group</code>, <code>subnet</code> details.<br><strong>x\_region</strong> – region name (<code>In-Bangalore-1</code> / <code>In-Hyderabad-1</code>).</p> | Create a new VPC.               |
| `get_vpc_task_status(task_id: str, x_region: str)`                              | <p><strong>task\_id</strong> – ID of the task.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                               | Check the status of a VPC task. |
| `retrieve_vpc(vpc_id: str, x_region: str, vpc_name: str = None)`                | <p><strong>vpc\_id</strong> – VPC ID.<br><strong>x\_region</strong> – region name.<br><strong>vpc\_name</strong> – optional name filter.</p>                                                                                                  | Get VPC details.                |
| `list_vpcs(x_region: str)`                                                      | **x\_region** – region name.                                                                                                                                                                                                                  | List all VPCs.                  |
| `delete_vpc(vpc_id: str, x_region: str)`                                        | <p><strong>vpc\_id</strong> – VPC ID.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                        | Delete a VPC.                   |
| `create_subnet(subnet_data: dict, vpc_id: str, router_krn: str, x_region: str)` | <p><strong>subnet\_data</strong> – subnet configuration.<br><strong>vpc\_id</strong> – VPC ID.<br><strong>router\_krn</strong> – router KRN.<br><strong>x\_region</strong> – region name.</p>                                                 | Create a subnet in a VPC.       |

***

#### 2. Security Groups

| Method                                                                                                                                       | Parameters                                                                                                                                                                                                                                                           | Description                                                                                                                                                                                                                |
| -------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `create_security_group(name: str, description: str, vpcid: str, x_region: str)`                                                              | <p><strong>name</strong> – security group name.<br><strong>description</strong> – description.<br><strong>vpcid</strong> – VPC ID.<br><strong>x\_region</strong> – region name.</p>                                                                                  | Create a new security group.                                                                                                                                                                                               |
| `list_by_vpc(vpc_krn_identifier: str, x_region: str)`                                                                                        | <p><strong>vpc\_krn\_identifier</strong> – VPC KRN.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                                 | List all security groups in a VPC.                                                                                                                                                                                         |
| `create_rule(direction: str, ethertype: str, protocol: str, port_range_min: int, port_range_max: int, remote_ip_prefix: str, x_region: str)` | Standard rule parameters + region.                                                                                                                                                                                                                                   | Create an inbound/outbound rule.                                                                                                                                                                                           |
| `attach_rule(ruleid: str, securityid: str, vpcid: str, x_region: str)`                                                                       | IDs + region name.                                                                                                                                                                                                                                                   | Attach a rule.                                                                                                                                                                                                             |
| `detach_rule(ruleid: str, securityid: str, vpcid: str, x_region: str)`                                                                       | IDs + region name.                                                                                                                                                                                                                                                   | Detach a rule.                                                                                                                                                                                                             |
| `delete_rule(securitygroupruleid: str, x_region: str)`                                                                                       | Rule ID + region name.                                                                                                                                                                                                                                               | Delete a rule.                                                                                                                                                                                                             |
| `delete_security_group(securitygroupid: str, x_region: str)`                                                                                 | Security group ID + region.                                                                                                                                                                                                                                          | Delete a security group.                                                                                                                                                                                                   |
| `update_port_security_groups(port_krn: str, security_groups: list[str], x_region: str)`                                                      | <p><strong>port\_krn</strong> – Port KRN (available in instance.network\_ports\[].krn).</p><p><strong>security\_groups</strong> – complete list of Security Group KRNs to retain (must not be empty).</p><p><strong>x\_region</strong> – region name.</p><p><br></p> | Updates Security Groups on a port using `PUT /api/v1/ports/{port_krn}`. This operation replaces the entire Security Group list. Include every Security Group that should remain attached; omit any that should be removed. |

***

#### 3. Compute – Instances (VMs)

| Method                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Parameters                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            | Description                                                                                                                                                                                                        |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `create_instance(instanceName: str, instanceType: str, region: str, vpc_id: str, subnet_id: str, sshkey_name: str, security_groups: list[str], image_krn: str = None, volume_name: str =` `None, volume_size: int = None, volumetype: str = None, volumes: list[str] = None, floating_ip: bool = False, user_data: str = "", delete_on_termination: bool = True, tags: list = [], count: int = 1, port_krn: str = None, isGpu: bool = False, timeout: int = None)` | <p><strong>instanceName</strong> – VM name.instance</p><p><strong>Type</strong> – e.g. "CPU-2x-8GB"</p><p><strong>region</strong> – deployment region</p><p><strong>vpc\_id</strong> – VPC ID</p><p><strong>subnet\_id</strong> – subnet ID</p><p><strong>sshkey\_name</strong> – SSH key name</p><p><strong>security\_groups</strong> – list of Security Group KRNs</p><p><strong>For a new boot volume,</strong> provide image\_krn, volume\_name, volume\_size, volumetype (omit volumes).</p><p><strong>To boot from an existing volume</strong>, provide volumes (omit image/volume creation fields).network\_id is automatically resolved from the VPC and subnet and must not be supplied.</p> | Launches a VM **asynchronously** using `POST /vm/v1/create_instance_async`. Returns `{ message, task_id }`. Poll with `search_instances()` or `retrieve_instance()` until the VM reaches **ACTIVE**.               |
| `search_instances(vpc_id: str, x_region: str, page: int = None, limit: int = None)`                                                                                                                                                                                                                                                                                                                                                                                | <p><strong>vpc\_id</strong> – VPC ID.</p><p><strong>x\_region</strong> – region name.</p><p><strong>page</strong> – optional page number.</p><p><strong>limit</strong> – optional page size.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Search instances in a VPC using `GET /vm/v1/search_instances`. Recommended for polling asynchronous VM create/delete operations.                                                                                   |
| `retrieve_instance(krn: str, x_region: str)`                                                                                                                                                                                                                                                                                                                                                                                                                       | <p><strong>krn</strong> – Instance KRN.</p><p><strong>x\_region</strong> – region name.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Retrieve complete VM details using `GET /v1/highlvlvpc/instance`, including `network_ports[].krn`, required for Security Group and Floating IP operations.                                                         |
| `delete_instance(instanceKrn: str, deleteVolume: bool, x_region: str)`                                                                                                                                                                                                                                                                                                                                                                                             | <p><strong>instanceKrn</strong> – VM KRN.</p><p><strong>deleteVolume</strong> – delete attached boot volume.</p><p><strong>x\_region</strong> – region name.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      | Deletes a VM **asynchronously** using `DELETE /vm/v1/delete_instance_async`. Returns `{ message, task_id }`. Poll `search_instances()` until the VM is removed.                                                    |
| `create_instance_template(name: str, vpc_id: str, subnet_id: str, instanceType: str, sshkey_name: str, region: str, image_krn: str, volumetype: str, volume_size: int, volume_name: str, security_groups: list[str], isGpu: bool = False, user_data: str = None)`                                                                                                                                                                                                  | <p><strong>name</strong> – template name.<br><strong>vpc\_id</strong> – VPC ID.<br><strong>subnet\_id</strong> – subnet ID.<br><strong>instanceType</strong> – VM flavor.<br><strong>sshkey\_name</strong> – SSH key.<br><strong>region</strong> – deployment region.<br><strong>image\_krn</strong> – image KRN.<br><strong>volumetype</strong> – boot volume type.<br><strong>volume\_size</strong> – boot volume size.<br><strong>volume\_name</strong> – boot volume name.<br><strong>security\_groups</strong> – Security Group KRNs.</p>                                                                                                                                                        | Creates an Instance Template using `POST /vm/v1/instance-templates/create`. Returns a template object containing `template_krn`. `network_id` is resolved automatically.                                           |
| `list_instance_templates(x_region: str, page: int = None, limit: int = None)`                                                                                                                                                                                                                                                                                                                                                                                      | <p><strong>x\_region</strong> – region name.<br><strong>page</strong> – optional page number.<br><strong>limit</strong> – optional page size.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     | Lists all Instance Templates using `GET /vm/v1/instance-templates/list`.                                                                                                                                           |
| `retrieve_instance_template(template_krn: str, x_region: str)`                                                                                                                                                                                                                                                                                                                                                                                                     | <p><strong>template\_krn</strong> – Instance Template KRN.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Retrieves details of an Instance Template using `GET /vm/v1/instance-templates/details`.                                                                                                                           |
| `delete_instance_template(template_krn: str, x_region: str)`                                                                                                                                                                                                                                                                                                                                                                                                       | <p><strong>template\_krn</strong> – Instance Template KRN.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           | Deletes an Instance Template using `DELETE /vm/v1/instance-templates/delete`. Returns `{ "message": "Template deleted" }`.                                                                                         |
| `batch_create_vms(template_krn: str, count: int, instanceName: str, x_region: str)`                                                                                                                                                                                                                                                                                                                                                                                | <p><strong>template\_krn</strong> – Instance Template KRN.<br><strong>count</strong> – number of VMs.<br><strong>instanceName</strong> – VM name prefix.<br><strong>x\_region</strong> – region name.</p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             | Creates multiple VMs using `POST /vm/v1/batch-vm-create`. Returns `{ batch_source, job_id, message, total_count }`. **Recommended** instead of `create_instance(count > 1)` to avoid boot-volume naming conflicts. |

***

#### 4. Block Storage

| Method                                                                                                                | Parameters                                                                                            | Description                                                                                                                   |
| --------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `create_volume(volumeName: str, size: int, volumeType: str, availabilityZone: str, x_region: str)`                    | Name, size (GB), type (`"standard"`/`"ssd"`), AZ, region.                                             | Create a block volume.                                                                                                        |
| `retrieve_volume(volumeId: str, x_region: str)`                                                                       | Volume ID, region.                                                                                    | Get volume details.                                                                                                           |
| `delete_volume(volumeId: str, x_region: str)`                                                                         | Volume ID, region.                                                                                    | Delete a volume.                                                                                                              |
| `list_volumes(k_tenant_id: str, x_region: str)`                                                                       | VPC KRN, region.                                                                                      | List all volumes in a VPC.                                                                                                    |
| `attach_volume(volume_id: str, instance_id: str, k_tenant_id: str, x_region: str, mount_partition: str = "/dev/vdz")` | Volume KRN, instance KRN, VPC KRN, region, mount path (default `/dev/vdz`).                           | Attach a volume to an instance. Returns `attachments[].remote_attachment_id`, needed later as `attachment_id` when detaching. |
| `detach_volume(volume_id: str, instance_id: str, attachment_id: str, k_tenant_id: str, x_region: str)`                | Volume KRN, instance KRN, attachment ID (from `attachments[].remote_attachment_id`), VPC KRN, region. | Detach a volume from an instance.                                                                                             |

***

#### 5. Object Storage

| Method                                                  | Parameters             | Description                  |
| ------------------------------------------------------- | ---------------------- | ---------------------------- |
| `create_access_keys(key_name: str, x_region: str)`      | Key name, region.      | Create a storage access key. |
| `list_access_keys()`                                    | None.                  | List all keys.               |
| `delete_access_keys(access_key_id: str, x_region: str)` | Access key ID, region. | Delete an access key.        |
| `create_bucket(bucketName: str, region: str)`           | Name, region.          | Create a bucket.             |
| `list_buckets()`                                        | None.                  | List buckets.                |
| `delete_bucket(bucketName: str, region: str)`           | Name, region.          | Delete a bucket.             |
