File

Files enable you to provide input data to tasks and retrieve generated output.

What are Files?

Input Files: Data you provide (documents, images, credentials, templates) Output Files: Results generated by AI agents (screenshots, reports, extracted data)

Key Properties

  • id: Unique file identifier
  • name: Original filename
  • size: File size in bytes
  • mimeType: File content type
  • presignedUrl: Temporary download URL
  • taskId: Associated task (for output files)

File Operations

1import { BrowserUseClient } from "browser-use-sdk";
2
3const client = new BrowserUseClient({ apiKey: "bu_..." });
4
5// Upload and use files
6const credFile = await client.files.upload("credentials.json");
7const templateFile = await client.files.upload("template.xlsx");
8
9// Use in tasks
10const task = await client.tasks.createTask({
11 llm: "browser-use-llm",
12 task: "Log into dashboard using credentials and fill template",
13 inputFiles: [credFile.id, templateFile.id]
14});
15
16const result = await task.complete();
17console.log("Task completed:", result.output);

Output Files

1import * as fs from "fs";
2
3// Tasks generate output files
4const task = await client.tasks.createTask({
5 llm: "browser-use-llm",
6 task: "Take screenshots and extract data to CSV"
7});
8
9const result = await task.complete();
10
11// Download output files
12for (const file of result.outputFiles) {
13 const data = await client.files.download(file.id);
14 fs.writeFileSync(`output/${file.name}`, data);
15}

File Management

1// List and manage files
2const files = await client.files.listFiles();
3const taskFiles = await client.files.listFiles({ taskId: "task_123" });
4const images = await client.files.listFiles({ mimeType: "image/*" });
5
6// Cleanup
7await client.files.deleteFile(fileId);

Supported Types & Limits

File Size Limit

Maximum file size: 10 MB (10,485,760 bytes)

Supported Content Types

Images:

  • image/jpeg, image/jpg
  • image/png
  • image/gif
  • image/webp
  • image/svg+xml

Documents:

  • application/pdf
  • application/msword (.doc)
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document (.docx)
  • application/vnd.ms-excel (.xls)
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (.xlsx)

Text:

  • text/plain
  • text/csv
  • text/markdown

Presigned URL Upload Flow

For large files, use presigned URLs to upload directly to storage:

1// 1. Get presigned URL
2const presigned = await client.files.getPresignedUrl(sessionId, {
3 fileName: "large-document.pdf",
4 contentType: "application/pdf",
5 sizeBytes: 5000000 // 5MB
6});
7
8// 2. Upload directly to storage using presigned URL
9await fetch(presigned.url, {
10 method: "POST",
11 body: formData // Include presigned.fields
12});
13
14// 3. Use the file in your task
15const task = await client.tasks.createTask({
16 sessionId: sessionId,
17 task: "Process the uploaded document",
18 inputFiles: [presigned.fileName]
19});

Presigned URLs expire after 120 seconds. Generate a new URL if your upload takes longer.


Next Steps