# Scenario Integration via LowCodeAPI

## Overview

Scenario is an AI image generation platform for creating custom images and training models. The Scenario API provides comprehensive functionality for:

- **Image Generation** - Generate images using custom-trained AI models
- **Image Editing** - Edit, enhance, and modify images
- **Model Training** - Train custom AI models on your own images
- **Background Removal** - Remove backgrounds from images
- **Image Upscaling** - Enhance and upscale image resolution

## Base Endpoint

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

## Authentication

LowCodeAPI handles authentication automatically using Basic Auth with API Key and Secret. You only need to:

1. **Sign up** at [Scenario](https://scenario.com) to get your API Key and Secret
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 Scenario API key and secret
- Apply them to each request using Basic Authentication

**Auth Type**: Basic Auth (API Key + Secret)

## API Categories

- **Image Generation AI** - Custom AI image generation and editing

## Common Endpoints

### Category: Images Generation

#### Generate Image

**Method**: `POST` | **LowCodeAPI Path**: `/v1/images/generations`

**Full URL**:
```
https://api.lowcodeapi.com/scenario/v1/images/generations?api_token={api_token}
```

**Description**: Generate an image using a custom-trained model.

**Request Body**:
```json
{
  "model": "model-uuid",
  "prompt": "A futuristic cityscape at sunset",
  "num_images": 1,
  "width": 1024,
  "height": 1024,
  "steps": 30,
  "guidance_scale": 7.5
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `model` | string | Yes | UUID of the custom model to use |
| `prompt` | string | Yes | Text description of the image to generate |
| `num_images` | integer | No | Number of images to generate (default: 1) |
| `width` | integer | No | Image width in pixels (default: 1024) |
| `height` | integer | No | Image height in pixels (default: 1024) |
| `steps` | integer | No | Number of inference steps (default: 30) |
| `guidance_scale` | number | No | How strictly to follow prompt (default: 7.5) |
| `seed` | integer | No | Random seed for reproducibility |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/scenario/v1/images/generations?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model-uuid",
    "prompt": "A futuristic cityscape at sunset with neon lights",
    "num_images": 1,
    "width": 1024,
    "height": 1024,
    "steps": 30
  }'
```

**Official Documentation**: [Generate Image](https://docs.scenario.com/docs/generating-images)

---

### Category: Images Edition

#### Remove Background

**Method**: `PUT` | **LowCodeAPI Path**: `/v1/images/erase-background`

**Full URL**:
```
https://api.lowcodeapi.com/scenario/v1/images/erase-background?api_token={api_token}
```

**Description**: Remove the background from an image.

**Request Body**:
```json
{
  "image": "data:image/png;base64,iVBORw0KGgo...",
  "backgroundColor": "#FFFFFF",
  "format": "png",
  "returnImage": true
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `image` | string | Yes | Input image as a data URL |
| `backgroundColor` | string | No | Background color as hex code |
| `format` | string | No | Output format (png, jpg) |
| `returnImage` | boolean | No | Return image in response (default: true) |
| `assetId` | string | No | Asset ID for the image |
| `name` | string | No | Original file name |

**Example Request**:
```bash
curl -X PUT "https://api.lowcodeapi.com/scenario/v1/images/erase-background?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "data:image/png;base64,iVBORw0KGgo...",
    "format": "png",
    "returnImage": true
  }'
```

**Official Documentation**: [Remove Background](https://docs.scenario.com/docs/image-editing)

---

#### Inpaint Image

**Method**: `POST` | **LowCodeAPI Path**: `/v1/images/inpaint`

**Full URL**:
```
https://api.lowcodeapi.com/scenario/v1/images/inpaint?api_token={api_token}
```

**Description**: Edit or fill in parts of an image using AI.

**Request Body**:
```json
{
  "image": "data:image/png;base64,iVBORw0KGgo...",
  "mask": "data:image/png;base64,iVBORw0KGgo...",
  "prompt": "A beautiful flower garden",
  "model": "model-uuid"
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `image` | string | Yes | Original image as data URL |
| `mask` | string | Yes | Mask image as data URL (white = edit, black = keep) |
| `prompt` | string | Yes | Description of what to generate in masked area |
| `model` | string | Yes | UUID of the model to use |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/scenario/v1/images/inpaint?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "data:image/png;base64,iVBORw0KGgo...",
    "mask": "data:image/png;base64,iVBORw0KGgo...",
    "prompt": "A beautiful flower garden",
    "model": "model-uuid"
  }'
```

**Official Documentation**: [Inpaint](https://docs.scenario.com/docs/image-editing)

---

### Category: Models

#### Get All Models

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

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

**Description**: Retrieve all models in your account.

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

**Official Documentation**: [Get Models](https://docs.scenario.com/docs/models)

---

#### Train Model

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

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

**Description**: Train a custom AI model on your images.

**Request Body**:
```json
{
  "name": "My Custom Style",
  "images": ["data:image/png;base64,...", "data:image/png;base64,..."],
  "type": "style",
  "steps": 2000
}
```

**Request Body Fields**:

| Field | Type | Required | Description |
|-------|------|----------|-------------|
| `name` | string | Yes | Name for the model |
| `images` | array | Yes | Array of training images as data URLs |
| `type` | string | Yes | Model type: "style" or "object" |
| `steps` | integer | No | Number of training steps (default: 2000) |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/scenario/v1/models/train?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Custom Art Style",
    "images": ["data:image/png;base64,..."],
    "type": "style",
    "steps": 2000
  }'
```

**Official Documentation**: [Train Model](https://docs.scenario.com/docs/training)

---

## Usage Examples

### Example 1: Generate Custom Images

Generate images using a custom model:

```bash
# Step 1: List available models
# No ID needed - lists all models
curl -X GET "https://api.lowcodeapi.com/scenario/v1/models?api_token=YOUR_API_TOKEN"

# Step 2: Generate image with custom model
# No ID needed - starts generation
curl -X POST "https://api.lowcodeapi.com/scenario/v1/images/generations?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "model-uuid",
    "prompt": "A magical forest with glowing mushrooms",
    "num_images": 4,
    "width": 1024,
    "height": 1024
  }'
```

### Example 2: Edit Images

Remove background and inpaint:

```bash
# Step 1: Remove background from image
# No ID needed - processes image
curl -X PUT "https://api.lowcodeapi.com/scenario/v1/images/erase-background?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "data:image/png;base64,iVBORw0KGgo...",
    "format": "png",
    "returnImage": true
  }'

# Step 2: Inpaint to add elements
# No ID needed - edits image
curl -X POST "https://api.lowcodeapi.com/scenario/v1/images/inpaint?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "image": "data:image/png;base64,iVBORw0KGgo...",
    "mask": "data:image/png;base64,iVBORw0KGgo...",
    "prompt": "A serene mountain landscape",
    "model": "model-uuid"
  }'
```

### Example 3: Train Custom Model

Train your own AI model:

```bash
# Train a custom style model
# No ID needed - starts training
curl -X POST "https://api.lowcodeapi.com/scenario/v1/models/train?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "My Art Style",
    "images": [
      "data:image/png;base64,...",
      "data:image/png;base64,..."
    ],
    "type": "style",
    "steps": 3000
  }'

# Use the trained model for generation
curl -X POST "https://api.lowcodeapi.com/scenario/v1/images/generations?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "trained-model-uuid",
    "prompt": "A landscape in my art style"
  }'
```

## Complete Endpoint Reference

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

- **OpenAPI Definition**: https://backend.lowcodeapi.com/scenario/definition
- **Official Scenario Documentation**: https://docs.scenario.com/docs/getting-started

## Rate Limits & Best Practices

- **Rate Limit**: Refer to your Scenario plan for rate limits
- **Best Practices**:
  - Store model UUIDs for efficient generation
  - Use appropriate image dimensions for your use case
  - Provide high-quality training images for better models
  - Use descriptive prompts for better generation results
  - Monitor training progress for custom models
  - Test with fewer steps first, then increase for quality
  - Use background removal for clean image composites

## Error Handling

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

Common errors:
- **400**: Invalid request parameters or image format
- **401**: Invalid API credentials
- **404**: Model not found
- **429**: Rate limit exceeded
- **500**: Training or generation failed