Skip to main content

Overview

You can send files to your agent by including them as base64-encoded parts in the request.

File Part Structure

{
  "type": "file",
  "name": "data.csv",
  "mimeType": "text/csv",
  "base64": "YSxiCjIsMTIzCi0zLDQxMjQKMSw3Cg=="
}

Fields

  • type - Always "file" for file uploads
  • name - Filename (e.g., "data.csv", "image.png")
  • mimeType - MIME type (e.g., "text/csv", "image/png", "application/pdf")
  • base64 - Base64-encoded file content

Complete Example

# The base64 string below decodes to a CSV file with content:
# a,b
# 2,123
# -3,4124
# 1,7

curl -N \
  -H "Content-Type: application/json" \
  -X POST http://127.0.0.1:8080/query \
  -d @- <<'EOF'
{
  "kwargs": {
    "session_id": "my-session"
  },
  "parts": [
    {
      "type": "file",
      "name": "test.csv",
      "mimeType": "text/csv",
      "base64": "YSxiCjIsMTIzCi0zLDQxMjQKMSw3Cg=="
    },
    {
      "type": "text",
      "text": "What's the sum of the first column"
    }
  ]
}
EOF

Encoding Files to Base64

With Python

import base64

with open('data.csv', 'rb') as f:
    encoded = base64.b64encode(f.read()).decode('utf-8')
    print(encoded)

With Bash

base64 -i data.csv

With JavaScript

// In Node.js
const fs = require('fs');
const content = fs.readFileSync('data.csv');
const encoded = content.toString('base64');
console.log(encoded);

// In Browser
const file = document.getElementById('fileInput').files[0];
const reader = new FileReader();
reader.onload = (e) => {
  const base64 = e.target.result.split(',')[1];
  console.log(base64);
};
reader.readAsDataURL(file);

Supported File Types

Your agent can receive any file type. Common examples:
  • Text files - .txt, .csv, .json, .md
  • Images - .png, .jpg, .gif, .webp
  • Documents - .pdf, .docx, .xlsx
  • Code files - .py, .js, .html, .css
The maximum file size depends on your deployment configuration and API limits.

Multiple Files

You can send multiple files in a single request:
{
  "parts": [
    {
      "type": "file",
      "name": "data1.csv",
      "mimeType": "text/csv",
      "base64": "..."
    },
    {
      "type": "file",
      "name": "data2.csv",
      "mimeType": "text/csv",
      "base64": "..."
    },
    {
      "type": "text",
      "text": "Compare these two files"
    }
  ],
  "kwargs": {}
}

Next Steps