---
title: "p-image-trainer"
description: "Train custom LoRAs for image generation"
url: "https://docs.api.pruna.ai/guides/models/p-image-trainer"
image: "https://docs.api.pruna.ai/_og/d/c_Ocean.takumi,title_p-image-trainer,description_Train+custom+LoRAs+for+image+generation,props_eyJ0aGVtZSI6eyJtb2RlIjoibGlnaHQiLCJjb2xvcnMiOnsicHJpbWFyeSI6IiM3YzNhZWQifX19,p_Ii9ndWlkZXMvbW9kZWxzL3AtaW1hZ2UtdHJhaW5lciI,s_QMAhg-sipkWN_kRx.png"
---

# p-image-trainer

Train custom LoRAs for text-to-image generation

## [Overview](#overview)

p-image-trainer allows you to train custom LoRA (Low-Rank Adaptation) weights for use with the `p-image-lora` model. Train personalized styles, subjects, characters, or concepts using your own images.

**This is NOT an inference model.** It does not generate images. Instead, it outputs a ZIP file containing trained LoRA weights (.safetensors).

**Rate Limit:** 5 requests per minute

**Category:** LoRA Training

**Price:** $1.80 / 1000 steps

**Important Notes:**

-   **Async only** - Training takes minutes to hours. Do not use `Try-Sync` header.
-   **Download within 30 minutes** - The output URL expires approximately 30 minutes after training completes. Download immediately and upload to HuggingFace for permanent storage.
-   Trained LoRAs only work with `p-image-lora`, not with other models.

## [Workflow](#workflow)

1.  **Prepare training data** - Create a ZIP file with at least 10 images and optional caption files
2.  **Upload ZIP to accessible URL** - Host your training data somewhere accessible (e.g., cloud storage)
3.  **Start training** - Submit async request (takes minutes to hours)
4.  **Poll for completion** - Check status until training succeeds
5.  **Download output** - Get the ZIP file within 30 minutes
6.  **Upload to HuggingFace** - Store the .safetensors file for permanent access
7.  **Use with p-image-lora** - Generate images using your trained LoRA

## [Quickstart](#quickstart)

### [Prepare Training Data](#prepare-training-data)

Create a ZIP archive with your training images:

```text
training_data.zip
├── image1.jpg
├── image1.txt        # Optional: caption for image1.jpg
├── image2.png
├── image2.txt        # Optional: caption for image2.png
├── image3.jpg
└── ...
```

Use at least 10 images for good results. Caption files should match image names (e.g., `photo.txt` for `photo.jpg`).

### [Start Training (Async Only)](#start-training-async-only)

```bash
curl -X POST 'https://api.pruna.ai/v1/predictions' \
  -H 'Content-Type: application/json' \
  -H 'apikey: YOUR_API_KEY' \
  -H 'Model: p-image-trainer' \
  -d '{
    "input": {
      "image_data": "https://your-storage.com/training_data.zip",
      "steps": 1000,
      "training_type": "balanced"
    }
  }'
```

Response:

```text
{
  "id": "training123xyz",
  "model": "p-image-trainer",
  "input": { ... },
  "get_url": "https://api.pruna.ai/v1/predictions/status/training123xyz"
}
```

### [Poll for Completion](#poll-for-completion)

Training takes minutes to hours depending on steps. Poll periodically:

```bash
curl -X GET 'https://api.pruna.ai/v1/predictions/status/training123xyz' \
  -H 'apikey: YOUR_API_KEY'
```

When complete:

```text
{
  "status": "succeeded",
  "output": "https://api.pruna.ai/v1/predictions/delivery/xezq/abc123.../lora_weights.zip"
}
```

### [Download Output Immediately](#download-output-immediately)

The output URL expires in ~30 minutes. Download the ZIP file immediately:

```bash
curl -o lora_output.zip "https://api.pruna.ai/v1/predictions/delivery/xezq/abc123.../lora_weights.zip"
```

### [Upload to HuggingFace](#upload-to-huggingface)

Extract and upload the .safetensors file to HuggingFace:

```bash
unzip lora_output.zip
# Upload lora.safetensors to huggingface.co/your-username/my-lora
```

### [Use with p-image-lora](#use-with-p-image-lora)

```bash
curl -X POST 'https://api.pruna.ai/v1/predictions' \
  -H 'Content-Type: application/json' \
  -H 'apikey: YOUR_API_KEY' \
  -H 'Model: p-image-lora' \
  -d '{
    "input": {
      "prompt": "A portrait in my custom style",
      "lora_weights": "huggingface.co/your-username/my-lora"
    }
  }'
```

### [Parameters](#parameters)

#### [Required Parameters](#required-parameters)

| Parameter  | Type         | Description                                                                      |
| :--------- | :----------- | :------------------------------------------------------------------------------- |
| image_data | string (URI) | URL to a ZIP archive with training images. Use at least 10 images. Can include text files for captions (e.g., photo.txt for photo.jpg) |

#### [Optional Parameters](#optional-parameters)

| Parameter       | Type    | Default    | Description                                                                      |
| :-------------- | :------ | :--------- | :------------------------------------------------------------------------------- |
| steps           | integer | 1000       | Number of training steps. Range: 100-5000, in increments of 100. More steps = longer training, potentially better results |
| learning_rate   | number  | 0.0001     | Learning rate for training. Range: 0.00001-0.01. Lower = slower but more stable  |
| training_type   | string  | "balanced" | Type of training: "content" (subjects/characters), "style" (artistic styles), "balanced" (both) |
| default_caption | string  | -          | Default caption for images without .txt files. If not provided and captions are missing, training will fail |

#### [Training Type Options](#training-type-options)

| Type     | Use Case                                              |
| :------- | :---------------------------------------------------- |
| content  | Specific subjects, characters, objects, people        |
| style    | Artistic styles, color palettes, aesthetic treatments |
| balanced | General-purpose, mixed content and style              |

#### [Steps Guidelines](#steps-guidelines)

| Steps     | Use Case                   | Expected Time |
| :-------- | :------------------------- | :------------ |
| 100-500   | Quick tests, simple styles | Minutes       |
| 500-1000  | Standard training          | 10-30 minutes |
| 1000-2000 | High quality, complex      | 30-60 minutes |
| 2000-5000 | Maximum quality            | 1-2+ hours    |