> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.privategpt.dev/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.privategpt.dev/_mcp/server.

# Upload a file

POST /v1/files
Content-Type: multipart/form-data

Upload a file into the session's uploads directory. By default the file is stored under `uploads/{filename}` within the session scope; pass `path` to push it to a custom object-storage-style key (e.g. `data/2024/report.pdf`), relative to the uploads mount (`/mnt/user-data/uploads/` inside the sandbox). The relative path is returned as the file ID. Uploading a file to an existing key overwrites it.

Reference: https://docs.privategpt.dev/api-reference/files/upload-file-v-1-files-post

## Request

### Query parameters

- `scope_id` (string, required) — Session / container identifier (matches the `container` field in chat requests).
- `path` (string, optional, nullable) — Object-storage-style key for the uploaded file, relative to the uploads mount. Defaults to `uploads/{filename}`. Nested keys are supported and parent directories are created automatically. May be prefixed with `uploads/` for convenience. Must be relative (no leading `/`), must not contain `..` components, and must not end with `/`.
- `namespace` (string, optional, default: session) — Namespace for the file. Defaults to 'session'.

### Body (multipart/form-data)

This endpoint expects a multipart form containing a file.

- `file` (file, required) — file field.

## Response

### 200

Successful Response

- `id` (string, required) — Relative path of the file within the session, e.g. 'uploads/data.csv' or 'outputs/result.png'. Use this value as `file_id` in subsequent requests.
- `created_at` (datetime, required) — ISO-8601 timestamp when the file was created or last modified.
- `filename` (string, required) — Filename derived from the path.
- `mime_type` (string, required) — MIME type detected from the file content.
- `size_bytes` (integer, required) — File size in bytes.
- `downloadable` (boolean, required) — True for sandbox output files; False for uploaded input files.
- `scope` (FileScope, required) — Session scope this file belongs to.
- `type` ("file", optional, default: file) — Object type discriminator, always 'file'.
- `etag` (string, optional, nullable) — Content checksum (MD5 hex or S3 ETag). Present after stat; None if unavailable.
- `namespace` (string, optional, default: session) — Namespace this file belongs to (e.g. 'session', 'skills', or a custom namespace).

## Errors

### 401 Unauthorized Error

Unauthorized

- `any`

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional) — detail field.

## Types

### FileScope

Scope that a file belongs to (always a session).

- `id` (string, required) — Session / container identifier that owns this file.
- `type` (string, optional, default: session) — Namespace the file belongs to (e.g. 'session', 'skills', or a custom namespace).

### ValidationError

ValidationError schema.

- `loc` (list of ValidationErrorLocItems, required) — loc field.
- `msg` (string, required) — msg field.
- `type` (string, required) — type field.
- `input` (any, optional) — input field.
- `ctx` (ValidationErrorCtx, optional) — ctx field.

### ValidationErrorLocItems

### ValidationErrorCtx

ctx field.

## Examples

**Request**

```json
{
  "file": "<file: string>"
}
```

**Response**

```json
{
  "id": "uploads/data.csv",
  "created_at": "2024-01-15T10:30:00Z",
  "filename": "data.csv",
  "mime_type": "text/csv",
  "size_bytes": 4096,
  "downloadable": false,
  "scope": {
    "id": "session-abc123",
    "type": "session"
  },
  "type": "file"
}
```

**SDK Code**

```python
import requests

url = "https://api.example.com/v1/files"

querystring = {"scope_id":"scope_id"}

files = { "file": "open('string', 'rb')" }

response = requests.post(url, files=files, params=querystring)

print(response.json())
```

```javascript
const url = 'https://api.example.com/v1/files?scope_id=scope_id';
const form = new FormData();
form.append('file', 'string');

const options = {method: 'POST'};

options.body = form;

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.example.com/v1/files?scope_id=scope_id"

	payload := strings.NewReader("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")

	req, _ := http.NewRequest("POST", url, payload)

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.example.com/v1/files?scope_id=scope_id")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.example.com/v1/files?scope_id=scope_id")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.example.com/v1/files?scope_id=scope_id', [
  'multipart' => [
    [
        'name' => 'file',
        'filename' => 'string',
        'contents' => null
    ]
  ]
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.example.com/v1/files?scope_id=scope_id");
var request = new RestRequest(Method.POST);
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation
let parameters = [
  [
    "name": "file",
    "fileName": "string"
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.example.com/v1/files?scope_id=scope_id")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```