> 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/ai-studio-sdk.md).

# AI Studio SDK

## Krutrim AI Studio SDK Guide (Python)

### 1. Overview

The Krutrim AI Studio / AI Cloud Python SDK (krutrim-cloud) is intended for model inference, image generation, speech/text APIs, fine-tuning and BYOM workflows. It supports synchronous and asynchronous workflows for AI applications. It does not provide Core Infrastructure or Sandbox APIs.

**Need VPCs, VMs, storage, security groups, or Sandbox?** Use the separate Core Infrastructure SDK: `pip install krutrim-client` and `from krutrim_client import KrutrimClient`. See [Which Python SDK should I use?](https://docs.cloud.olakrutrim.com/sdk-guide/core-infra-sdk#which-python-sdk-should-i-use) and the Core Infrastructure installation guide. These are distinct SDK scopes, not a deprecation or a replacement relationship.

Supported Python Versions: **3.10 – 3.12**\
Package: <https://pypi.org/project/krutrim-cloud>

***

### 2. Installation

Install the SDK via pip:

```bash
pip install krutrim-cloud
```

#### System Dependencies

Some modules require `ffmpeg` and `ffprobe` to be available in your environment:

```bash
# macOS (with Homebrew)
brew install ffmpeg

# Ubuntu/Debian
sudo apt-get install ffmpeg
```

***

### 3. Authentication

You need an API key to authenticate your requests. This can be provided as an environment variable or passed directly into the client.

#### Environment Variable (Recommended)

```bash
export KRUTRIM_CLOUD_API_KEY="your_api_key_here"
```

#### Manual Key Injection

```python
from krutrim_cloud import KrutrimCloud
client = KrutrimCloud(api_key="your_api_key_here")
```

***

### 4. Client Initialization

#### Synchronous Client

```python
from krutrim_cloud import KrutrimCloud
client = KrutrimCloud()
```

#### Asynchronous Client

```python
from krutrim_cloud import KrutrimCloudAsync
client = KrutrimCloudAsync()
```

***

### 5. Error Handling

API responses may raise exceptions for invalid input, network issues, or internal errors.

Basic handling:

```python
try:
    response = client.texts.completions.bhashini(prompt="Hello")
except Exception as e:
    print(f"Error: {str(e)}")
```

***

### 6. Using Async Workflows

```python
import asyncio
from krutrim_cloud import KrutrimCloudAsync

async def run():
    client = KrutrimCloudAsync()
    result = await client.images.generations.diffusion(
        model_name="diffusion1XL",
        image_height=512,
        image_width=512,
        prompt="a futuristic AI city"
    )
    print(result.generated_images)

asyncio.run(run())
```

***

### 7. Examples & Sample Projects

Explore example notebooks and scripts:

* [Basic Inference](https://github.com/ola-krutrim/krutrim-cloud-python/tree/main/examples)
* \[Fine-Tuning (Coming Soon)]
* \[CLI Wrapper (WIP)]

***

### 8. Versioning & Updates

To upgrade the SDK:

```bash
pip install --upgrade krutrim-cloud
```

Check the [GitHub repo](https://github.com/ola-krutrim/krutrim-cloud-python) for changelogs and release notes.

***

### 9. Support & Contribution

* For issues, submit a GitHub Issue [here](https://github.com/ola-krutrim/krutrim-cloud-python/issues)
* Need help creating a key? See [API Keys](https://docs.cloud.olakrutrim.com/basics/key-management-system/model-api-keys.md).

***
