# Replicate Integration via LowCodeAPI

## Overview

Replicate is a platform for running and hosting AI models. The Replicate API provides comprehensive functionality for:

- **Models** - Browse, create, and manage AI models
- **Predictions** - Run model inference and generate predictions
- **Training** - Train custom models using your data
- **Deployments** - Deploy and manage model deployments
- **Files** - Upload and manage files for model input/output
- **Collections** - Explore curated model collections

## Base Endpoint

```
https://api.lowcodeapi.com/replicate/
```

## Authentication

LowCodeAPI handles authentication automatically using API Key authentication. You only need to:

1. **Sign up** at [Replicate](https://replicate.com) to get your API Key
2. **Connect your account** in the LowCodeAPI dashboard
3. **Use your `api_token`** in all requests

The `api_token` is your LowCodeAPI authentication token. LowCodeAPI will automatically:
- Fetch your Replicate API key
- Apply it to each request as a Bearer token

**Auth Type**: Bearer Token (TOKEN prefix)

## API Categories

- **AI Cloud** - AI model hosting and inference

## Common Endpoints

### Category: Models

#### List Models

**Method**: `GET` | **LowCodeAPI Path**: `/v1/models`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models?api_token={api_token}
```

**Description**: List models available on Replicate.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `cursor` | string | No | Pagination cursor |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/models?api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [List Models](https://replicate.com/docs/reference/http#models.list)

---

#### Get Model

**Method**: `GET` | **LowCodeAPI Path**: `/v1/models/model_owner/model_name`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name?model_owner={model_owner}&model_name={model_name}&api_token={api_token}
```

**Description**: Get a specific model by owner and name.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_owner` | string | Yes | The user or organization owning the model |
| `model_name` | string | Yes | The name of the model |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name?model_owner=stability-ai&model_name=stable-diffusion&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Model](https://replicate.com/docs/reference/http#models.get)

---

#### Create Model

**Method**: `POST` | **LowCodeAPI Path**: `/v1/models`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models?api_token={api_token}
```

**Description**: Create a new model.

**Request Body**:
```json
{
  "owner": "your-username",
  "name": "my-model",
  "visibility": "public",
  "hardware": "gpu-a40-large"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | Model name (unique for owner) |
| `owner` | string | Yes | User or organization owning the model |
| `visibility` | string | Yes | Model visibility: public or private |
| `hardware` | string | Yes | Hardware SKU for running the model |
| `description` | string | No | Model description |
| `github_url` | string | No | URL to model source code |
| `paper_url` | string | No | URL to model paper |
| `license_url` | string | No | URL to model license |
| `cover_image_url` | string | No | URL to model cover image |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/replicate/v1/models?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "owner": "my-username",
    "name": "my-custom-model",
    "visibility": "private",
    "hardware": "cpu"
  }'
```

**Official Documentation**: [Create Model](https://replicate.com/docs/reference/http#models.create)

---

#### Update Model

**Method**: `PATCH` | **LowCodeAPI Path**: `/v1/models/model_owner/model_name`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name?model_owner={model_owner}&model_name={model_name}&api_token={api_token}
```

**Description**: Update model properties.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_owner` | string | Yes | Model owner |
| `model_name` | string | Yes | Model name |

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `description` | string | No | Model description |
| `visibility` | string | No | Model visibility |
| `github_url` | string | No | Source code URL |
| `paper_url` | string | No | Paper URL |
| `license_url` | string | No | License URL |
| `cover_image_url` | string | No | Cover image URL |

**Example Request**:
```bash
curl -X PATCH "https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name?model_owner=myuser&model_name=mymodel&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "description": "Updated model description",
    "visibility": "public"
  }'
```

**Official Documentation**: [Update Model](https://replicate.com/docs/reference/http#models.update)

---

#### Delete Model

**Method**: `DELETE` | **LowCodeAPI Path**: `/v1/models/model_owner/model_name`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name?model_owner={model_owner}&model_name={model_name}&api_token={api_token}
```

**Description**: Delete a model.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_owner` | string | Yes | Model owner |
| `model_name` | string | Yes | Model name |

**Example Request**:
```bash
curl -X DELETE "https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name?model_owner=myuser&model_name=mymodel&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Delete Model](https://replicate.com/docs/reference/http#models.delete)

---

#### Get Model Versions

**Method**: `GET` | **LowCodeAPI Path**: `/v1/models/model_owner/model_name/versions`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions?model_owner={model_owner}&model_name={model_name}&api_token={api_token}
```

**Description**: List versions of a model.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_owner` | string | Yes | Model owner |
| `model_name` | string | Yes | Model name |
| `cursor` | string | No | Pagination cursor |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions?model_owner=stability-ai&model_name=stable-diffusion&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [List Versions](https://replicate.com/docs/reference/http#models.versions.list)

---

#### Get Model Version

**Method**: `GET` | **LowCodeAPI Path**: `/v1/models/model_owner/model_name/versions/version_id`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions/version_id?model_owner={model_owner}&model_name={model_name}&version_id={version_id}&api_token={api_token}
```

**Description**: Get a specific model version.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_owner` | string | Yes | Model owner |
| `model_name` | string | Yes | Model name |
| `version_id` | string | Yes | Version ID |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions/version_id?model_owner=stability-ai&model_name=stable-diffusion&version_id=abc123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Version](https://replicate.com/docs/reference/http#models.versions.get)

---

#### Delete Model Version

**Method**: `DELETE` | **LowCodeAPI Path**: `/v1/models/model_owner/model_name/versions/version_id`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions/version_id?model_owner={model_owner}&model_name={model_name}&version_id={version_id}&api_token={api_token}
```

**Description**: Delete a model version.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_owner` | string | Yes | Model owner |
| `model_name` | string | Yes | Model name |
| `version_id` | string | Yes | Version ID |

**Example Request**:
```bash
curl -X DELETE "https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions/version_id?model_owner=myuser&model_name=mymodel&version_id=abc123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Delete Version](https://replicate.com/docs/reference/http#models.versions.delete)

---

### Category: Predictions

#### Create Prediction

**Method**: `POST` | **LowCodeAPI Path**: `/v1/predictions`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/predictions?api_token={api_token}
```

**Description**: Create a prediction using a model version.

**Request Body**:
```json
{
  "version": "model_version_id",
  "input": {
    "text": "Hello, world!"
  },
  "webhook": "https://example.com/webhook",
  "webhook_events_filter": ["output", "completed"]
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| "version" | string | Yes | Model version ID |
| `input` | object | Yes | Input data for the model |
| `webhook` | string | No | Webhook URL for notifications |
| `webhook_events_filter` | array | No | Events triggering webhook: start, output, logs, completed |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/replicate/v1/predictions?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "version": "stability-ai/sdxl:abc123",
    "input": {
      "prompt": "A futuristic city at sunset"
    }
  }'
```

**Official Documentation**: [Create Prediction](https://replicate.com/docs/reference/http#predictions.create)

---

#### Get Prediction

**Method**: `GET` | **LowCodeAPI Path**: `/v1/predictions/prediction_id`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/predictions/prediction_id?prediction_id={prediction_id}&api_token={api_token}
```

**Description**: Get a prediction by ID.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `prediction_id` | string | Yes | Prediction ID |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/predictions/prediction_id?prediction_id=pred_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Prediction](https://replicate.com/docs/reference/http#predictions.get)

---

#### Cancel Prediction

**Method**: `POST` | **LowCodeAPI Path**: `/v1/predictions/prediction_id/cancel`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/predictions/prediction_id/cancel?prediction_id={prediction_id}&api_token={api_token}
```

**Description**: Cancel a running prediction.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `prediction_id` | string | Yes | Prediction ID to cancel |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/replicate/v1/predictions/prediction_id/cancel?prediction_id=pred_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Cancel Prediction](https://replicate.com/docs/reference/http#predictions.cancel)

---

#### List Predictions

**Method**: `GET` | **LowCodeAPI Path**: `/v1/predictions`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/predictions?api_token={api_token}
```

**Description**: List predictions.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `cursor` | string | No | Pagination cursor |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/predictions?api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [List Predictions](https://replicate.com/docs/reference/http#predictions.list)

---

### Category: Training

#### Create Training

**Method**: `POST` | **LowCodeAPI Path**: `/v1/models/model_owner/model_name/versions/version_id/trainings`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions/version_id/trainings?model_owner={model_owner}&model_name={model_name}&version_id={version_id}&api_token={api_token}
```

**Description**: Train a model using your data.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_owner` | string | Yes | Model owner |
| `model_name` | string | Yes | Model name |
| `version_id` | string | Yes | Base version ID |

**Request Body**:
```json
{
  "input": {
    "data": "https://example.com/training-data.zip"
  },
  "destination": "my-username/my-finetuned-model",
  "webhook": "https://example.com/webhook"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `input` | object | Yes | Training input data |
| `destination` | string | Yes | Destination model path |
| `webhook` | string | No | Webhook URL for notifications |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions/version_id/trainings?model_owner=replicate&model_name=sdxl&version_id=abc123&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {"data": "https://example.com/data.zip"},
    "destination": "myuser/my-model"
  }'
```

**Official Documentation**: [Create Training](https://replicate.com/docs/reference/http#trainings.create)

---

#### Get Training

**Method**: `GET` | **LowCodeAPI Path**: `/v1/trainings/training_id`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/trainings/training_id?training_id={training_id}&api_token={api_token}
```

**Description**: Get training by ID.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `training_id` | string | Yes | Training ID |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/trainings/training_id?training_id=train_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Training](https://replicate.com/docs/reference/http#trainings.get)

---

#### Cancel Training

**Method**: `POST` | **LowCodeAPI Path**: `/v1/trainings/training_id/cancel`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/trainings/training_id/cancel?training_id={training_id}&api_token={api_token}
```

**Description**: Cancel a running training.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `training_id` | string | Yes | Training ID to cancel |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/replicate/v1/trainings/training_id/cancel?training_id=train_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Cancel Training](https://replicate.com/docs/reference/http#trainings.cancel)

---

### Category: Files

#### Upload File

**Method**: `POST` | **LowCodeAPI Path**: `/v1/files`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/files?api_token={api_token}
```

**Description**: Upload a file for use with models.

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `file` | file | Yes | File to upload |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/replicate/v1/files?api_token=YOUR_API_TOKEN" \
  -F "[email protected]"
```

**Official Documentation**: [Upload File](https://replicate.com/docs/reference/http#files.create)

---

#### Get File

**Method**: `GET` | **LowCodeAPI Path**: `/v1/files/file_id`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/files/file_id?file_id={file_id}&api_token={api_token}
```

**Description**: Get file by ID.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `file_id` | string | Yes | File ID |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/files/file_id?file_id=file_123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get File](https://replicate.com/docs/reference/http#files.get)

---

### Category: Hardware

#### List Hardware

**Method**: `GET` | **LowCodeAPI Path**: `/v1/hardware`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/hardware?api_token={api_token}
```

**Description**: List available hardware options for running models.

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/hardware?api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [List Hardware](https://replicate.com/docs/reference/http#hardware.list)

---

### Category: Collections

#### List Collections

**Method**: `GET` | **LowCodeAPI Path**: `/v1/collections`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/collections?api_token={api_token}
```

**Description**: List model collections.

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/collections?api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [List Collections](https://replicate.com/docs/reference/http#collections.list)

---

#### Get Collection

**Method**: `GET` | **LowCodeAPI Path**: `/v1/collections/collection_slug`

**Full URL**:
```
https://api.lowcodeapi.com/replicate/v1/collections/collection_slug?collection_slug={collection_slug}&api_token={api_token}
```

**Description**: Get a collection by slug.

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `collection_slug` | string | Yes | Collection slug |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/replicate/v1/collections/collection_slug?collection_slug=text-to-image&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [Get Collection](https://replicate.com/docs/reference/http#collections.get)

---

## Usage Examples

### Example 1: Generate an Image

Create an image using Stable Diffusion:

```bash
# Step 1: Create a prediction
# No ID needed - creates new prediction
curl -X POST "https://api.lowcodeapi.com/replicate/v1/predictions?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "version": "stability-ai/sdxl:39ed52f2a78e934b3ba6e2a89f5b1c712de7dfea535525255b1aa35c5565e08b",
    "input": {
      "prompt": "A serene mountain landscape at sunrise",
      "width": 768,
      "height": 768
    }
  }'

# Step 2: Check prediction status
# Replace PREDICTION_ID with the actual ID from Step 1
curl -X GET "https://api.lowcodeapi.com/replicate/v1/predictions/prediction_id?prediction_id=PREDICTION_ID&api_token=YOUR_API_TOKEN"
```

### Example 2: Train a Custom Model

Fine-tune a model with your data:

```bash
# Step 1: Create a training job
# No ID needed - creates new training
curl -X POST "https://api.lowcodeapi.com/replicate/v1/models/model_owner/model_name/versions/version_id/trainings?model_owner=replicate&model_name=sdxl&version_id=VERSION_ID&api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "input": {
      "data": "https://example.com/training-images.zip",
      "concept": "my-style"
    },
    "destination": "myuser/my-finetuned-model"
  }'

# Step 2: Check training status
# Replace TRAINING_ID with the actual training ID
curl -X GET "https://api.lowcodeapi.com/replicate/v1/trainings/training_id?training_id=TRAINING_ID&api_token=YOUR_API_TOKEN"
```

### Example 3: Upload and Use File

Upload a file for model input:

```bash
# Step 1: Upload a file
# No ID needed - uploads file
curl -X POST "https://api.lowcodeapi.com/replicate/v1/files?api_token=YOUR_API_TOKEN" \
  -F "[email protected]"

# Step 2: Use the file in a prediction
# No ID needed - creates prediction with file reference
curl -X POST "https://api.lowcodeapi.com/replicate/v1/predictions?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "version": "MODEL_VERSION",
    "input": {
      "image": "https://replicate.delivery/FILE_URL"
    }
  }'
```

## Complete Endpoint Reference

For a complete list of all 36 endpoints and their parameters, refer to:

- **OpenAPI Definition**: https://backend.lowcodeapi.com/replicate/definition
- **Official Replicate Documentation**: https://replicate.com/docs/reference/http

## Rate Limits & Best Practices

- **Rate Limit**: Refer to your Replicate plan
- **Best Practices**:
  - Use webhooks for long-running predictions instead of polling
  - Store prediction IDs for status checking
  - Use appropriate input/output sizes for faster processing
  - Cancel unused predictions to avoid unnecessary charges
  - Cache model version IDs to avoid repeated lookups
  - Optimize image sizes for faster uploads and processing
  - Check hardware requirements before running large models

## Error Handling

All responses are wrapped in a `data` key:
```json
{
  "data": {
    // Actual response from Replicate
  }
}
```