# Fal.ai Integration via LowCodeAPI

## Overview

Fal.ai Platform APIs provide programmatic access to AI model resources including model metadata, pricing information, usage tracking, and analytics. Build powerful AI applications with access to state-of-the-art models for text generation, image creation, and more.

## Base Endpoint

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

## Authentication

LowCodeAPI handles authentication automatically. You only need to:

1. **Sign up** at [Fal.ai Dashboard](https://fal.ai/dashboard)
2. **Get your API Key** from the dashboard
3. **Connect your account** in LowCodeAPI dashboard
4. **Use your `api_token`** in all requests

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

**Auth Type**: API Key (Bearer Token)

## API Categories

- **AI Cloud** - Cloud-based AI model inference and management

## Common Endpoints

### Category: Models

#### List Models

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

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

**Description**: Retrieve a list of available AI models with metadata including model information, availability, and basic details

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `limit` | number | No | Maximum number of models to return |
| `offset` | number | No | Number of models to skip for pagination |
| `search` | string | No | Search query to filter models by name or description |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

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

**Official Documentation**: [https://docs.fal.ai/platform-apis/for-models](https://docs.fal.ai/platform-apis/for-models)

---

#### Get Model Details

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

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

**Description**: Get detailed information about a specific model including metadata, capabilities, and configuration

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_id` | string | Yes | The unique identifier of the model |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/falai/v1/models/model_id?model_id=fal-ai/flux-pro&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.fal.ai/platform-apis/for-models](https://docs.fal.ai/platform-apis/for-models)

---

### Category: Pricing

#### Get Pricing Information

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

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

**Description**: Retrieve pricing information for models including cost per request, usage tiers, and billing details

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `model_id` | string | No | Filter pricing by specific model ID |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/falai/v1/pricing?model_id=fal-ai/flux-pro&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.fal.ai/platform-apis/for-models](https://docs.fal.ai/platform-apis/for-models)

---

### Category: Usage

#### Get Usage Statistics

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

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

**Description**: Retrieve usage statistics and tracking information for API requests including request counts, costs, and usage patterns

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `start_date` | string | No | Start date for usage statistics (ISO 8601 format) |
| `end_date` | string | No | End date for usage statistics (ISO 8601 format) |
| `model_id` | string | No | Filter usage by specific model ID |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/falai/v1/usage?start_date=2024-01-01&end_date=2024-01-31&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.fal.ai/platform-apis/for-models](https://docs.fal.ai/platform-apis/for-models)

---

### Category: Compute

#### List Compute Instances

**Method**: `GET` | **LowCodeAPI Path**: `/v1/compute/instances`

**Full URL**:
```
https://api.lowcodeapi.com/falai/v1/compute/instances?api_token={api_token}
```

**Description**: List all compute instances with their current status, configuration, and lifecycle information

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `status` | string | No | Filter instances by status (active, stopped, etc.) |
| `limit` | number | No | Maximum number of instances to return |
| `offset` | number | No | Number of instances to skip |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X GET "https://api.lowcodeapi.com/falai/v1/compute/instances?status=active&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.fal.ai/platform-apis/for-compute](https://docs.fal.ai/platform-apis/for-compute)

---

#### Create Compute Instance

**Method**: `POST` | **LowCodeAPI Path**: `/v1/compute/instances`

**Full URL**:
```
https://api.lowcodeapi.com/falai/v1/compute/instances?api_token={api_token}
```

**Description**: Create a new compute instance with specified configuration and type

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `instance_type` | string | Yes | Type of compute instance to create |
| `name` | string | No | Name for the compute instance |
| `config` | object | No | Configuration options for the instance |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/falai/v1/compute/instances?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "instance_type": "gpu-1x-a10g",
    "name": "my-ai-instance",
    "config": {
      "max_workers": 4
    }
  }'
```

**Official Documentation**: [https://docs.fal.ai/platform-apis/for-compute](https://docs.fal.ai/platform-apis/for-compute)

---

#### Start Compute Instance

**Method**: `POST` | **LowCodeAPI Path**: `/v1/compute/instances/instance_id/start`

**Full URL**:
```
https://api.lowcodeapi.com/falai/v1/compute/instances/instance_id/start?instance_id={instance_id}&api_token={api_token}
```

**Description**: Start a stopped compute instance and make it available for use

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `instance_id` | string | Yes | The unique identifier of the compute instance |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/falai/v1/compute/instances/instance_id/start?instance_id=abc123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.fal.ai/platform-apis/for-compute](https://docs.fal.ai/platform-apis/for-compute)

---

#### Stop Compute Instance

**Method**: `POST` | **LowCodeAPI Path**: `/v1/compute/instances/instance_id/stop`

**Full URL**:
```
https://api.lowcodeapi.com/falai/v1/compute/instances/instance_id/stop?instance_id={instance_id}&api_token={api_token}
```

**Description**: Stop a running compute instance to pause its operation

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `instance_id` | string | Yes | The unique identifier of the compute instance |
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/falai/v1/compute/instances/instance_id/stop?instance_id=abc123&api_token=YOUR_API_TOKEN"
```

**Official Documentation**: [https://docs.fal.ai/platform-apis/for-compute](https://docs.fal.ai/platform-apis/for-compute)

---

### Category: Batch

#### Batch Requests

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

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

**Description**: Combine multiple API calls into a single HTTP request to reduce connections and improve performance

**Query Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `api_token` | string | Yes | Your LowCodeAPI authentication token |

**Body Parameters**:

| Parameter | Type | Required | Description |
|-----------|------|----------|-------------|
| `requests` | array | Yes | Array of API requests to batch process |

**Example Request**:
```bash
curl -X POST "https://api.lowcodeapi.com/falai/v1/batch?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {
        "method": "GET",
        "path": "/v1/models",
        "params": {"limit": 10}
      },
      {
        "method": "GET",
        "path": "/v1/pricing",
        "params": {"model_id": "fal-ai/flux-pro"}
      }
    ]
  }'
```

**Official Documentation**: [https://docs.fal.ai/platform-apis](https://docs.fal.ai/platform-apis)

---

## Usage Examples

### Example 1: Model Discovery and Pricing

This example shows how to discover available models and check their pricing:

```bash
# Step 1: List all available models
# No ID required - this returns a list of models
curl -X GET "https://api.lowcodeapi.com/falai/v1/models?limit=20&api_token=YOUR_API_TOKEN"

# Step 2: Get detailed information about a specific model
# Replace MODEL_ID with an ID from Step 1 (e.g., fal-ai/flux-pro)
curl -X GET "https://api.lowcodeapi.com/falai/v1/models/model_id?model_id=MODEL_ID&api_token=YOUR_API_TOKEN"

# Step 3: Check pricing for the model
# Use the same MODEL_ID from Step 2
curl -X GET "https://api.lowcodeapi.com/falai/v1/pricing?model_id=MODEL_ID&api_token=YOUR_API_TOKEN"
```

### Example 2: Compute Instance Management

This example demonstrates creating and managing compute instances:

```bash
# Step 1: Create a new compute instance
# The response will contain the new instance ID
curl -X POST "https://api.lowcodeapi.com/falai/v1/compute/instances?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "instance_type": "gpu-1x-a10g",
    "name": "my-ai-workflow"
  }'

# Step 2: Start the compute instance
# Replace INSTANCE_ID with the ID returned from Step 1
curl -X POST "https://api.lowcodeapi.com/falai/v1/compute/instances/instance_id/start?instance_id=INSTANCE_ID&api_token=YOUR_API_TOKEN"

# Step 3: Monitor the instance
# Use the same INSTANCE_ID
curl -X GET "https://api.lowcodeapi.com/falai/v1/compute/instances/instance_id/monitor?instance_id=INSTANCE_ID&metrics=cpu,memory&api_token=YOUR_API_TOKEN"

# Step 4: Stop the instance when done
# Use the same INSTANCE_ID
curl -X POST "https://api.lowcodeapi.com/falai/v1/compute/instances/instance_id/stop?instance_id=INSTANCE_ID&api_token=YOUR_API_TOKEN"
```

### Example 3: Usage Analytics and Batch Operations

This example shows how to track usage and perform batch operations:

```bash
# Step 1: Get usage statistics for a specific time period
# No ID required - uses date range filtering
curl -X GET "https://api.lowcodeapi.com/falai/v1/usage?start_date=2024-01-01&end_date=2024-01-31&api_token=YOUR_API_TOKEN"

# Step 2: Get analytics data with metrics
# No ID required - uses date range and metric filters
curl -X GET "https://api.lowcodeapi.com/falai/v1/analytics?start_date=2024-01-01&end_date=2024-01-31&metric=requests&api_token=YOUR_API_TOKEN"

# Step 3: Perform multiple requests in a single batch
# This reduces HTTP connections and improves performance
curl -X POST "https://api.lowcodeapi.com/falai/v1/batch?api_token=YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "requests": [
      {"method": "GET", "path": "/v1/models", "params": {"limit": 5}},
      {"method": "GET", "path": "/v1/pricing"},
      {"method": "GET", "path": "/v1/usage", "params": {"start_date": "2024-01-01"}}
    ]
  }'
```

## Complete Endpoint Reference

For a complete list of all endpoints and their parameters, refer to:
- **OpenAPI Definition**: `https://backend.lowcodeapi.com/falai/definition`
- **Official Provider Documentation**: [https://docs.fal.ai/platform-apis](https://docs.fal.ai/platform-apis)

## Rate Limits & Best Practices

- **Rate limits** are based on your account tier
- **Instance management**: Stop instances when not in use to save costs
- **Batch requests**: Use batch operations to reduce HTTP overhead
- **Monitoring**: Regularly check usage statistics to optimize costs

## Error Handling

Standard HTTP status codes apply:
- **200** - Success
- **400** - Bad request
- **401** - Authentication failed
- **429** - Rate limit exceeded
- **500** - Server error