# Files

"Files" are used to upload documents that can be used with features like "**Fine-tuning**", and "**Inference Batch API**". You need to first create the file object using "**/v1/files**" and get the **presigned upload url**. Then upload the file through presigned url.

<table><thead><tr><th>Functionality</th><th width="173">Max File Size</th><th width="173">File Extension</th><th data-type="checkbox">File Format Required</th></tr></thead><tbody><tr><td>Fine-tuning</td><td>512 MB</td><td>.jsonl</td><td>true</td></tr><tr><td>Inference Batch API</td><td>100 MB</td><td>.jsonl</td><td>true</td></tr></tbody></table>

{% hint style="info" %}
The total storage limit for all files uploaded by a single organization is capped at **100 GB**.

For Fine-tuning, we only support data in the [**OpenAI fine-tuning format**](https://platform.openai.com/docs/guides/fine-tuning#preparing-your-dataset).&#x20;
{% endhint %}

The file upload API returns a **presigned upload URL,** and the file needs to be uploaded using this presigned URL. The presigned URL is valid for **2 hours**.

## Step 1: Create a File Object

In this step, you create a file object, which initializes the upload process by providing essential metadata like the file name and type. The "purpose" parameter can be set to either "fine-tune" or "batch".

{% hint style="info" %}
Please note that when passing the "**file\_name**" parameter, you need to include the **file extension**. Otherwise, we will default to treating it as a JSONL file.
{% endhint %}

**Example Request:**

{% hint style="info" %}
Replace `{{API_TOKEN}}` with your actual token.
{% endhint %}

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

```bash
curl --location 'https://api.netmind.ai/v1/files' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer {{API_TOKEN}}' \
--data '{"file_name":"text.jsonl","purpose":"fine-tune"}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import json

url = "https://api.netmind.ai/v1/files"

payload = json.dumps({
  "file_name": "text.jsonl",
  "purpose": "fine-tune"
})
headers = {
  'Content-Type': 'application/json',
  'Authorization': 'Bearer {{API_TOKEN}}'
}

response = requests.request("POST", url, headers=headers, data=payload)

print(response.text)
```

{% endtab %}
{% endtabs %}

**Example Response:**

```json
{
    "id": "c67b7...298f3",
    "presigned_url": "https://FAKE_PRESIGNED_URL/..."
}
```

***

## Step 2: Upload File Using Presigned URL

**Example Request:**

{% hint style="info" %}
Replace `{{`DATA\_FILE\_PATH`}}` with your actual data file path.
{% endhint %}

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

```bash
curl --location --request PUT 'https://FAKE_PRESIGNED_URL/...' \
--data '@{{DATA_FILE_PATH}}'
```

{% endtab %}

{% tab title="Python" %}

```python
import requests
import os


presigned_url = "https://FAKE_PRESIGNED_URL/..."
file_name = "{{DATA_FILE_PATH}}"
file_size = os.path.getsize(file_name)


with open(file_name, "rb") as f:
    response = requests.put(presigned_url, data=f)
    print(response.status_code)
    print(response.text)
```

{% endtab %}
{% endtabs %}

**Example Response:**

```json
{}
```
