> 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.

# Commit or abort multipart session

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

After uploading all parts to a multipart upload session, use this endpoint to commit and close the session, or abort the session.

When committing, provide all the uploaded parts in the correct order. When aborting, the session and all uploaded parts are discarded.


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

## Authentication

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

## Request

### Path parameters

- `session_id` (string, required) — The session ID obtained from the Start multipart upload session response.

### 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.

- `action` (enum, required) — Set to `commit` to finalize the upload or `abort` to cancel it.
  - Allowed values: `commit`, `abort`
- `parts` (list of V2BatchesMultipartUploadSessionsSessionIdPostRequestBodyContentApplicationJsonSchemaPartsItems, optional) — Required when action is `commit`. List of all uploaded parts in order.

## Response

### 201

The multipart upload session was successfully committed or aborted.

## Types

### V2BatchesMultipartUploadSessionsSessionIdPostRequestBodyContentApplicationJsonSchemaPartsItems

- `part_num` (integer, required) — The part number of the uploaded part.
- `part_id` (string, required) — The part ID returned when the part was uploaded.

## Examples

**Request**

```json
{
  "action": "commit"
}
```

**Response**

```json
{}
```

**SDK Code**

```python with SDK
from aihub import AIHub

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

# This assumes the `session_id` variable was set when the
# "Start multipart upload session" API/SDK operation was called earlier.
parts = [
    {"part_num": 1, "part_id": "12345"},
    {"part_num": 2, "part_id": "12346"},
    {"part_num": 3, "part_id": "12347"}
]

# commit the session
client.batches.commit_multipart_upload_session(
    session_id=session_id,
    action="commit",
    parts=parts
)
print("Multipart upload completed successfully")

```

```python without SDK
import requests

# This assumes the `session_id` and `parts` variables were set when the
# "Start multipart upload session" API/SDK operation was called earlier.
session_endpoint = f"https://aihub.instabase.com/api/v2/batches/multipart-upload/sessions/{session_id}"
parts = [
    {"part_num": 1, "part_id": "12345"},
    {"part_num": 2, "part_id": "12346"},
    {"part_num": 3, "part_id": "12347"}
]

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

# commit the session
data = {
    "action": "commit",
    "parts": parts
}

response = requests.post(session_endpoint, headers=headers, json=data)

if response.status_code == 201:
    print("Multipart upload completed successfully")
else:
    print(f"Error: {response.status_code} - {response.text}")

```

```python with SDK - Complete Workflow
import os
from aihub import AIHub

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

batch_id = 12345
local_filename = "large-file.pdf"
local_file_path = f"/local/path/to/{local_filename}"
file_size = os.path.getsize(local_file_path)

# Step 1: Create session
ai_hub_filename = "upload.pdf"
response = client.batches.create_multipart_upload_session(
    batch_id=batch_id,
    filename=ai_hub_filename,
    file_size=file_size
)

session_id = response.session_id
part_size = response.part_size

# Step 2: Upload parts
parts = []
part_num = 1

with open(local_file_path, "rb") as local_file:
    while True:
        part_data = local_file.read(part_size)
        if not part_data:
            break

        response = client.batches.upload_multipart_part(
            session_id=session_id,
            part_num=part_num,
            part_data=part_data)

        parts.append({
            "part_num": part_num,
            "part_id": response.part_id
        })
        part_num += 1

# Step 3: Commit session
client.batches.commit_multipart_upload_session(
    session_id=session_id,
    action="commit",
    parts=parts
)
print("Multipart upload completed successfully")

```

```javascript
const url = 'https://aihub.instabase.com/api/v2/batches/multipart-upload/sessions/session_id';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"action":"commit"}'
};

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/sessions/session_id"

	payload := strings.NewReader("{\n  \"action\": \"commit\"\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/sessions/session_id")

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  \"action\": \"commit\"\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/sessions/session_id")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"action\": \"commit\"\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/sessions/session_id', [
  'body' => '{
  "action": "commit"
}',
  '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/sessions/session_id");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"action\": \"commit\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = ["action": "commit"] 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/sessions/session_id")! 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()
```