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

# Upload File

POST https://platform.labric.co/api/v1/tools/upload-file
Content-Type: multipart/form-data

Upload a job artifact file.

Intended for use by jobs running in sandboxes. Accepts a multipart/form-data
file upload, stores it in GCS, and returns the created file record. When a
job_execution_id is provided, records provenance linking the file to that execution.

Reference: https://docs.labric.co/api-reference/labric-api/tools/upload-file

## OpenAPI Specification

```yaml
openapi: 3.1.0
info:
  title: openapi-tools
  version: 1.0.0
paths:
  /api/v1/tools/upload-file:
    post:
      operationId: upload_file
      summary: Upload File
      description: >-
        Upload a job artifact file.


        Intended for use by jobs running in sandboxes. Accepts a
        multipart/form-data

        file upload, stores it in GCS, and returns the created file record. When
        a

        job_execution_id is provided, records provenance linking the file to
        that execution.
      tags:
        - tools
      parameters:
        - name: Authorization
          in: header
          description: Bearer authentication
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LabricUploadFileSchema'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
        '422':
          description: Unprocessable Content
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidationErrorSchema'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorSchema'
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  type: string
                  format: binary
                job_execution_id:
                  type:
                    - string
                    - 'null'
                  format: uuid
              required:
                - file
servers:
  - url: https://platform.labric.co
    description: https://platform.labric.co
components:
  schemas:
    LabricUploadFileSchema:
      type: object
      properties:
        file_id:
          type: string
          description: The ID of the uploaded file.
        file_name:
          type: string
          description: The original file name.
        size_kilobytes:
          type:
            - integer
            - 'null'
          description: File size in kilobytes.
      required:
        - file_id
        - file_name
        - size_kilobytes
      title: LabricUploadFileSchema
    ErrorSchema:
      type: object
      properties:
        detail:
          type: string
      required:
        - detail
      title: ErrorSchema
    ValidationErrorSchema:
      type: object
      properties:
        detail:
          type: array
          items:
            type: object
            additionalProperties:
              description: Any type
      required:
        - detail
      description: Shape of Ninja's built-in 422 request-validation error response.
      title: ValidationErrorSchema
  securitySchemes:
    ApiKeyAuth:
      type: http
      scheme: bearer

```

## Examples



**Request**

```json
{
  "file": "<file: artifact_build_20240612.zip>"
}
```

**Response**

```json
{
  "file_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
  "file_name": "artifact_build_20240612.zip",
  "size_kilobytes": 2048
}
```

**SDK Code**

```python
import requests

url = "https://platform.labric.co/api/v1/tools/upload-file"

files = { "file": "open('artifact_build_20240612.zip', 'rb')" }
payload = { "job_execution_id":  }
headers = {"Authorization": "Bearer <api_key>"}

response = requests.post(url, data=payload, files=files, headers=headers)

print(response.json())
```

```javascript
const url = 'https://platform.labric.co/api/v1/tools/upload-file';
const form = new FormData();
form.append('file', 'artifact_build_20240612.zip');
form.append('job_execution_id', '');

const options = {method: 'POST', headers: {Authorization: 'Bearer <api_key>'}};

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://platform.labric.co/api/v1/tools/upload-file"

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

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

	req.Header.Add("Authorization", "Bearer <api_key>")

	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://platform.labric.co/api/v1/tools/upload-file")

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

request = Net::HTTP::Post.new(url)
request["Authorization"] = 'Bearer <api_key>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"artifact_build_20240612.zip\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"job_execution_id\"\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://platform.labric.co/api/v1/tools/upload-file")
  .header("Authorization", "Bearer <api_key>")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"artifact_build_20240612.zip\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"job_execution_id\"\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://platform.labric.co/api/v1/tools/upload-file', [
  'multipart' => [
    [
        'name' => 'file',
        'filename' => 'artifact_build_20240612.zip',
        'contents' => null
    ]
  ]
  'headers' => [
    'Authorization' => 'Bearer <api_key>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://platform.labric.co/api/v1/tools/upload-file");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <api_key>");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"file\"; filename=\"artifact_build_20240612.zip\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"job_execution_id\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Authorization": "Bearer <api_key>"]
let parameters = [
  [
    "name": "file",
    "fileName": "artifact_build_20240612.zip"
  ],
  [
    "name": "job_execution_id",
    "value": 
  ]
]

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://platform.labric.co/api/v1/tools/upload-file")! 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()
```