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

# Start multipart upload session

POST https://aihub.instabase.com/api/v2/batches/multipart-upload
Content-Type: application/json

Start a multipart upload session. Use this endpoint when you need to upload a file larger than 10 MB to a batch.

The multipart upload process consists of three steps:
1. Create a multipart upload session (this endpoint)
2. [Upload file parts](/api-sdk/api-reference/batches/upload-multipart-part) to the session
3. [Commit the session](/api-sdk/api-reference/batches/commit-multipart-upload-session) to finalize the upload


Reference: https://docs.instabase.com/api-sdk/api-reference/batches/create-multipart-upload-session

## Authentication

- `Authorization` header (bearer token, required) — Bearer HTTP authentication.

## Request

### Headers

- `IB-Context` (string, optional) — Typically your organization ID. See [Authorization and context identification](/api-sdk/authorization#ib-context-header) for details.

### Body (application/json)

This endpoint expects an object.

- `batch_id` (integer, required) — The batch ID to upload the file to.
- `filename` (string, required) — A file name for the uploaded file on the AI Hub filesystem, including the file extension. Maximum of 255 characters.
- `file_size` (integer, required) — The file size, in bytes. Can be an integer or a string.

## Response

### 201

The multipart upload session was initiated.

- `session_id` (string, required) — ID of the multipart upload session.
- `part_size` (integer, required) — The number of bytes each part should be when uploading to the session. Each part should match the part_size, except for the final part, which can be smaller than the part_size.

## Errors

### 404 Not Found Error

Batch with the specified ID doesn't exist.

- `any`

## Examples

**Request**

```json
{
  "batch_id": 98765,
  "filename": "project-report-final.pdf",
  "file_size": 15728640
}
```

**Response**

```json
{
  "session_id": "yGLRzUtS2vHm9IdxMrsKaMEOXG7hGBU7KEuvm2JujgBuO9ZAwtqTYmAYauf1RHI8bgEq7qm_UnCE5YNdMg7.1Lv_lrKRVPQ4fZpNVgF3wD5dbvz_bgbmx50a2.kcDZN7XjOI1z.NQ8_9JfOLhtYIgA6xMGLv5U0p6FitSDtFgW4-",
  "part_size": 10485760
}
```

**SDK Code**

```python with SDK
import os
from aihub import AIHub

client = AIHub(
    api_root="https://aihub.instabase.com/api",
    api_key="abcdefghijklmnopqrst1234567890",
    ib_context="john.doe_acme.com"
)

ai_hub_filename = "large-file.pdf"

# get file size
local_filepath = "/local/path/to/large-file.pdf"
file_size = os.path.getsize(local_filepath)

# create multipart upload session
response = client.batches.create_multipart_upload_session(
    batch_id=12345,
    filename=ai_hub_filename,
    file_size=file_size
)

print(f"Session ID: {response.session_id}")
print(f"Part size: {response.part_size}")

```

```python without SDK
import os
import requests

ai_hub_filename = "large-file.pdf"

# get file size
local_filepath = "/local/path/to/large-file.pdf"
file_size = os.path.getsize(local_filepath)

url = "https://aihub.instabase.com/api/v2/batches/multipart-upload"

headers = {
    "Authorization": "Bearer abcdefghijklmnopqrst1234567890",
    "IB-Context": "john.doe_acme.com"
}

# create the request payload
data = {
    "batch_id": 12345,
    "filename": ai_hub_filename,
    "file_size": file_size
}

# make the POST request
response = requests.post(url, headers=headers, json=data)

# handle the response
if response.status_code == 201:
    print(f"Session ID: {response.json()['session_id']}")
    print(f"Part size: {response.json()['part_size']}")
else:
    print(f"Error: {response.status_code} - {response.text}")

```

```javascript
const url = 'https://aihub.instabase.com/api/v2/batches/multipart-upload';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"batch_id":98765,"filename":"project-report-final.pdf","file_size":15728640}'
};

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://aihub.instabase.com/api/v2/batches/multipart-upload"

	payload := strings.NewReader("{\n  \"batch_id\": 98765,\n  \"filename\": \"project-report-final.pdf\",\n  \"file_size\": 15728640\n}")

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

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	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://aihub.instabase.com/api/v2/batches/multipart-upload")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"batch_id\": 98765,\n  \"filename\": \"project-report-final.pdf\",\n  \"file_size\": 15728640\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://aihub.instabase.com/api/v2/batches/multipart-upload")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"batch_id\": 98765,\n  \"filename\": \"project-report-final.pdf\",\n  \"file_size\": 15728640\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://aihub.instabase.com/api/v2/batches/multipart-upload', [
  'body' => '{
  "batch_id": 98765,
  "filename": "project-report-final.pdf",
  "file_size": 15728640
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://aihub.instabase.com/api/v2/batches/multipart-upload");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"batch_id\": 98765,\n  \"filename\": \"project-report-final.pdf\",\n  \"file_size\": 15728640\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "batch_id": 98765,
  "filename": "project-report-final.pdf",
  "file_size": 15728640
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://aihub.instabase.com/api/v2/batches/multipart-upload")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
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()
```