Compare commits

...

3 Commits

Author SHA1 Message Date
Alex
9e7f9423ea docs: Update file upload API to use unified /kickoff endpoint
The /kickoff endpoint now auto-detects content type:
- JSON body for normal kickoff
- multipart/form-data for file uploads

Removed references to separate /kickoff/multipart endpoint.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-30 10:55:18 -07:00
Alex
36dfeb36ec docs: Add API usage patterns for file uploads in flows
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-30 09:46:29 -07:00
Alex
7f81c017f9 docs: Add file upload support documentation for flows
Document how to use crewai-files types in flow state for file uploads,
including CrewAI Platform integration with automatic file upload UI.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-03-28 23:39:30 -07:00
2 changed files with 85 additions and 0 deletions

View File

@@ -134,6 +134,10 @@ result = flow.kickoff(
)
```
<Note type="info" title="CrewAI Platform Integration">
When deployed on CrewAI Platform, `ImageFile`, `PDFFile`, and other file-typed fields in your flow state automatically get a file upload UI. Users can drag and drop files directly in the Platform interface. Files are stored securely and passed to agents using provider-specific optimizations (inline base64, file upload APIs, or URL references depending on the provider).
</Note>
### With Standalone Agents
Pass files directly to agent kickoff:

View File

@@ -341,6 +341,87 @@ flow.kickoff()
By providing both unstructured and structured state management options, CrewAI Flows empowers developers to build AI workflows that are both flexible and robust, catering to a wide range of application requirements.
### File Inputs
When using structured state, you can include file-typed fields using classes from `crewai-files`. This enables file uploads as part of your flow's input:
```python
from crewai.flow.flow import Flow, start
from crewai_files import ImageFile, PDFFile
from pydantic import BaseModel
class OnboardingState(BaseModel):
document: PDFFile # File upload
cover_image: ImageFile # Image upload
title: str = "" # Text input
class OnboardingFlow(Flow[OnboardingState]):
@start()
def process_upload(self):
# Access files directly from state
print(f"Processing: {self.state.title}")
return self.state.document
```
When deployed on **CrewAI Platform**, file-typed fields automatically render as file upload dropzones in the UI. Users can drag and drop files, which are then passed to your flow.
**Kicking off with files via API:**
The `/kickoff` endpoint auto-detects the request format:
- **JSON body** → normal kickoff
- **multipart/form-data** → file upload + kickoff
API users can also pass URL strings directly to file-typed fields—Pydantic coerces them automatically.
### API Usage
#### Option 1: Multipart kickoff (recommended)
Send files directly with the kickoff request:
```bash
# With files (multipart) — same endpoint
curl -X POST https://your-deployment.crewai.com/kickoff \
-H 'Authorization: Bearer YOUR_TOKEN' \
-F 'inputs={"company_name": "Einstein"}' \
-F 'cnh_image=@/path/to/document.jpg'
```
Files are automatically stored and converted to `FileInput` objects. The agent receives the file with provider-specific optimization (inline base64, file upload API, or URL reference depending on the LLM provider).
#### Option 2: JSON kickoff (no files)
```bash
# Without files (JSON) — same endpoint
curl -X POST https://your-deployment.crewai.com/kickoff \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"inputs": {"company_name": "Einstein"}}'
```
#### Option 3: Separate upload + kickoff
Upload files first, then reference them:
```bash
# Step 1: Upload
curl -X POST https://your-deployment.crewai.com/files \
-H 'Authorization: Bearer YOUR_TOKEN' \
-F 'file=@/path/to/document.jpg' \
-F 'field_name=cnh_image'
# Returns: {"url": "https://...", "field_name": "cnh_image"}
# Step 2: Kickoff with URL
curl -X POST https://your-deployment.crewai.com/kickoff \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-d '{"inputs": {"company_name": "Einstein"}, "inputFiles": {"cnh_image": "https://..."}}'
```
#### On CrewAI Platform
When using the Platform UI, file-typed fields automatically render as drag-and-drop upload zones. No API calls needed—just drop the file and click Run.
## Flow Persistence
The @persist decorator enables automatic state persistence in CrewAI Flows, allowing you to maintain flow state across restarts or different workflow executions. This decorator can be applied at either the class level or method level, providing flexibility in how you manage state persistence.