# Segmind Storage

Segmind Storage allows you to upload files as assets and get URLs that can be used with other models. This is particularly useful when you need to provide image inputs to various AI models without repeatedly uploading the same file.

## Upload Asset API

Upload files to Segmind Storage and receive a URL that can be used across different models.

### Endpoint

```
POST https://workflows-api.segmind.com/upload-asset
```

### Headers

| Header         | Value                               | Required | Description             |
| -------------- | ----------------------------------- | -------- | ----------------------- |
| `accept`       | `application/json, text/plain, */*` | Yes      | Accepted response types |
| `x-api-key`    | `SG_XXX`                            | Yes      | Your Segmind API key    |
| `content-type` | `application/json`                  | Yes      | Request content type    |

### Request Body

The request body should be a JSON object with the following structure:

```json
{
  "data_urls": ["data:image/jpeg;base64,..."]
}
```

| Field       | Type             | Description                                               |
| ----------- | ---------------- | --------------------------------------------------------- |
| `data_urls` | Array of strings | Array of base64-encoded data URLs for the files to upload |

### Data URL Format

Files should be provided as base64-encoded data URLs in the format:

```
data:<mime-type>;base64,<base64-encoded-content>
```

Supported formats include:

* Images: `data:image/jpeg;base64,`, `data:image/png;base64,`, `data:image/webp;base64,`
* Other file types as supported by the models you intend to use

### Code Examples

Upload files to Segmind Storage using your preferred programming language.

{% tabs %}
{% tab title="cURL" %}

```bash
curl 'https://workflows-api.segmind.com/upload-asset' \
  -H 'accept: application/json, text/plain, */*' \
  -H 'x-api-key: SG_YOUR_API_KEY_HERE' \
  -H 'content-type: application/json' \
  --data-raw '{"data_urls":["data:image/jpeg;base64,/9j/4AAQSkZJRg..."]}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import base64

api_key = "SG_YOUR_API_KEY_HERE"
url = "https://workflows-api.segmind.com/upload-asset"

# Read and encode your image file
with open("image.jpg", "rb") as image_file:
    encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
    data_url = f"data:image/jpeg;base64,{encoded_string}"

data = {
    "data_urls": [data_url]
}

headers = {
    'x-api-key': api_key,
    'accept': 'application/json, text/plain, */*',
    'content-type': 'application/json'
}

response = requests.post(url, json=data, headers=headers)
result = response.json()

# Get the uploaded asset URL
asset_url = result['urls'][0]
print(f"Asset uploaded successfully: {asset_url}")
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
const axios = require('axios');
const fs = require('fs');

const api_key = "SG_YOUR_API_KEY_HERE";
const url = "https://workflows-api.segmind.com/upload-asset";

// Read and encode your image file
const imageBuffer = fs.readFileSync('image.jpg');
const base64String = imageBuffer.toString('base64');
const dataUrl = `data:image/jpeg;base64,${base64String}`;

(async () => {
    const data = {
        data_urls: [dataUrl]
    };

    const headers = {
        'x-api-key': api_key,
        'accept': 'application/json, text/plain, */*',
        'content-type': 'application/json'
    };

    try {
        const response = await axios.post(url, data, { headers });
        const assetUrl = response.data.urls[0];
        console.log(`Asset uploaded successfully: ${assetUrl}`);
    } catch (error) {
        console.error('Error:', error.response ? error.response.data : error.message);
    }
})();
```

{% endtab %}
{% endtabs %}

### Response

The API returns a JSON response containing the URLs of the uploaded assets:

```json
{
  "urls": [
    "https://storage.segmind.com/assets/..."
  ]
}
```

These URLs can then be used as inputs for various models on the Segmind platform.

### Use Cases

1. **Reusable Image Inputs**: Upload an image once and use the URL across multiple model runs
2. **Batch Processing**: Upload multiple images and process them with different models
3. **Workflow Integration**: Use uploaded assets in PixelFlow workflows
4. **Model Chaining**: Pass asset URLs between different models in a pipeline

### Best Practices

* Store the returned URLs for reuse to avoid uploading the same file multiple times
* Ensure your base64 encoding is correct to prevent upload failures
* Use appropriate MIME types in your data URLs for proper file handling
* Keep your API key secure and never expose it in client-side code

### Rate Limits

Asset uploads are subject to the standard Segmind API rate limits. Refer to the [Rate Limits](/api-reference/rate-limits.md) documentation for more information.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.segmind.com/api-reference/segmind-storage.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
