# Workflow Utilities

> Choose the Nth image from an image URL list for workflows.




## Overview

- **Endpoint**: `https://fal.run/fal-ai/workflow-utilities/pick-image-by-index`
- **Model ID**: `fal-ai/workflow-utilities/pick-image-by-index`
- **Category**: workflow
- **Kind**: inference


## Pricing

- **Price**: $0 per compute seconds

For more details, see [fal.ai pricing](https://fal.ai/pricing).

## API Information

This model can be used via our HTTP API or more conveniently via our client libraries.
See the input and output schema below, as well as the usage examples.


### Input Schema

The API accepts the following input parameters:


- **`image_urls`** (`list<string>`, _required_):
  Array of image URLs to select from
  - Array of string
  - Examples: ["https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg","https://storage.googleapis.com/falserverless/example_inputs/wan_s2v_cat.png"]

- **`index`** (`integer`, _required_):
  1-based position of the image to return. Value 1 returns the first image, 2 returns the second, and so on.
  - Examples: 1

- **`fallback_index`** (`FallbackIndexEnum`, _optional_):
  Behavior when `index` exceeds the length of `image_urls`. When `first-image`, returns the first image in the array. When `last-image`, returns the last image in the array. This input has no effect when `index` is within range, when `index` is below 1, or when `image_urls` is empty (the latter two cases still return validation errors). Default is `first-image`. Default value: `"first-image"`
  - Default: `"first-image"`
  - Options: `"first-image"`, `"last-image"`



**Required Parameters Example**:

```json
{
  "image_urls": [
    "https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg",
    "https://storage.googleapis.com/falserverless/example_inputs/wan_s2v_cat.png"
  ],
  "index": 1
}
```

**Full Example**:

```json
{
  "image_urls": [
    "https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg",
    "https://storage.googleapis.com/falserverless/example_inputs/wan_s2v_cat.png"
  ],
  "index": 1,
  "fallback_index": "first-image"
}
```


### Output Schema

The API returns the following output format:

- **`image`** (`Image`, _required_):
  The image at the requested position
  - Examples: {"url":"https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg"}

- **`images`** (`list<Image>`, _required_):
  Single-element array containing the selected image. Included so downstream nodes that expect an `images` reference (matching merge and other utilities) work without changes.
  - Array of Image
  - Examples: [{"url":"https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg"}]



**Example Response**:

```json
{
  "image": {
    "url": "https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg"
  },
  "images": [
    {
      "url": "https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg"
    }
  ]
}
```


## Usage Examples

### cURL

```bash
curl --request POST \
  --url https://fal.run/fal-ai/workflow-utilities/pick-image-by-index \
  --header "Authorization: Key $FAL_KEY" \
  --header "Content-Type: application/json" \
  --data '{
     "image_urls": [
       "https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg",
       "https://storage.googleapis.com/falserverless/example_inputs/wan_s2v_cat.png"
     ],
     "index": 1
   }'
```

### Python

Ensure you have the Python client installed:

```bash
pip install fal-client
```

Then use the API client to make requests:

```python
import fal_client

def on_queue_update(update):
    if isinstance(update, fal_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = fal_client.subscribe(
    "fal-ai/workflow-utilities/pick-image-by-index",
    arguments={
        "image_urls": ["https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg", "https://storage.googleapis.com/falserverless/example_inputs/wan_s2v_cat.png"],
        "index": 1
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)
```

### JavaScript

Ensure you have the JavaScript client installed:

```bash
npm install --save @fal-ai/client
```

Then use the API client to make requests:

```javascript
import { fal } from "@fal-ai/client";

const result = await fal.subscribe("fal-ai/workflow-utilities/pick-image-by-index", {
  input: {
    image_urls: ["https://storage.googleapis.com/falserverless/example_inputs/ltxv-image-input.jpg", "https://storage.googleapis.com/falserverless/example_inputs/wan_s2v_cat.png"],
    index: 1
  },
  logs: true,
  onQueueUpdate: (update) => {
    if (update.status === "IN_PROGRESS") {
      update.logs.map((log) => log.message).forEach(console.log);
    }
  },
});
console.log(result.data);
console.log(result.requestId);
```


## Additional Resources

### Documentation

- [Model Playground](https://fal.ai/models/fal-ai/workflow-utilities/pick-image-by-index)
- [API Documentation](https://fal.ai/models/fal-ai/workflow-utilities/pick-image-by-index/api)
- [OpenAPI Schema](https://fal.ai/api/openapi/queue/openapi.json?endpoint_id=fal-ai/workflow-utilities/pick-image-by-index)

### fal.ai Platform

- [Platform Documentation](https://docs.fal.ai)
- [Python Client](https://docs.fal.ai/clients/python)
- [JavaScript Client](https://docs.fal.ai/clients/javascript)
