# File Upload

#### RAG File Upload

Uploads a file by URL to the AI backend for retrieval-augmented generation.

**Endpoint:** `POST /api/v1/files`

**Auth:** Required (`X-API-Key` or `Authorization: Bearer`)\
**Timeout:** 5 minutes

**Request body:**

| Parameter    | Type   | Required | Description                      |
| ------------ | ------ | -------- | -------------------------------- |
| `url`        | string | ✅        | Public URL to the file           |
| `store_name` | string | —        | Custom name for the vector store |

**Allowed file types:**

| Extension | MIME Type                                                                 |
| --------- | ------------------------------------------------------------------------- |
| `.pdf`    | `application/pdf`                                                         |
| `.txt`    | `text/plain`                                                              |
| `.doc`    | `application/msword`                                                      |
| `.docx`   | `application/vnd.openxmlformats-officedocument.wordprocessingml.document` |

#### Request:

```bash
curl -X POST https://qolaba-server-b2b.up.railway.app/api/v1/files \
  -H "Content-Type: application/json" \
  -H "x-api-key: YOUR_API_KEY" \
  -d '{
    "url": "https://example.com/document.pdf",
    "store_name": "my-store"
  }'
```

#### Response `200 OK`

```json
{
  "success": true,
  "store_name": "fileSearchStores/my-store-31ihhh9rmyef",
  "file_name": "document.pdf",
  "message": "File uploaded and indexed successfully",
  "token_count": 4200,
  "estimated_cost_usd": 0.0021,
  "creditUtilisation": 2
}
```

#### Response 400 Bad Request&#xD;

```json
{
  "success": false,
  "message": "File type '.csv' is not supported. Allowed types: .pdf, .txt, .doc, .docx",
  "error": "File type '.csv' is not supported. Allowed types: .pdf, .txt, .doc, .docx"
}
```

#### &#xD;

#### Using the store in Chat Completions

Pass the `store_name` from the upload response into `file_search_store_names`:

**Request body:**

| Parameter                 | Type      | Required | Description                      |
| ------------------------- | --------- | -------- | -------------------------------- |
| `messages`                | array     | ✅        | Chat messages                    |
| `model`                   | string    | —        | Model ID                         |
| `file_search_store_names` | string\[] | —        | Store names from `uploadRagFile` |
| `thread_id`               | string    | —        | Conversation thread ID           |
| `user_id`                 | string    | —        | User identifier                  |
| `webhookUrl`              | string    | —        | Webhook for async results        |
| `metadata`                | object    | —        | Extra key/value metadata         |

```bash
curl -N https://qolaba-server-b2b.up.railway.app/api/v1/chat/completions
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "google/gemini-2.5-flash",
    "messages": [
      { "role": "user", "content": "Summarize the uploaded document" }
    ],
    "file_search_store_names": ["fileSearchStores/my-store-31ihhh9rmyef"],
    "stream": false
  }'

```

{% embed url="<https://app.theneo.io/api-runner/qolaba/ml-apis/api-reference/chat-completions-copy>" %}
