File Upload & Custom Responses¶
File upload types and response helpers for files, HTML, and plain text.
UploadFile¶
UploadFile
dataclass
¶
An uploaded file from a multipart form request.
Attributes:
| Name | Type | Description |
|---|---|---|
filename |
str
|
Original filename from the upload. |
content_type |
str
|
MIME type of the uploaded file. |
content |
bytes
|
Raw bytes of the file content. |
size |
int
|
File size in bytes. |
Source code in src/agenticapi/interface/upload.py
FileResult¶
FileResult
dataclass
¶
Convenience wrapper for returning files from agent endpoints.
Handlers return this instead of constructing Starlette responses
directly. The framework converts it to the appropriate response type
based on the content field:
bytes→ inlineResponsewith the given media typestr→FileResponse(interpreted as a file path)- async/sync iterable →
StreamingResponse
Example
@app.agent_endpoint(name="export") async def export_csv(intent, context): csv_data = "name,value\nalice,42\nbob,17" return FileResult( content=csv_data.encode(), media_type="text/csv", filename="export.csv", )
Attributes:
| Name | Type | Description |
|---|---|---|
content |
bytes | str | Any
|
File data — bytes, a file path string, or an iterable for streaming. |
media_type |
str
|
MIME type of the response (e.g., "application/pdf", "image/png"). |
filename |
str | None
|
Suggested download filename. Sets the Content-Disposition header. |
headers |
dict[str, str] | None
|
Additional response headers. |
Source code in src/agenticapi/interface/response.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 | |
to_response ¶
Convert to the appropriate Starlette response type.
Returns:
| Type | Description |
|---|---|
Response
|
A Starlette Response, FileResponse, or StreamingResponse. |
Source code in src/agenticapi/interface/response.py
HTMLResult¶
HTMLResult
dataclass
¶
Convenience wrapper for returning HTML from agent endpoints.
Equivalent to FastAPI's HTMLResponse. The framework converts it
to a Starlette HTMLResponse automatically.
Example
@app.agent_endpoint(name="dashboard") async def dashboard(intent, context): return HTMLResult(content="
Dashboard
Welcome!
")Attributes:
| Name | Type | Description |
|---|---|---|
content |
str | bytes
|
HTML string or bytes. |
status_code |
int
|
HTTP status code (default 200). |
headers |
dict[str, str] | None
|
Additional response headers. |
Source code in src/agenticapi/interface/response.py
to_response ¶
Convert to a Starlette HTMLResponse.
Returns:
| Type | Description |
|---|---|
Response
|
An HTMLResponse with |
Source code in src/agenticapi/interface/response.py
PlainTextResult¶
PlainTextResult
dataclass
¶
Convenience wrapper for returning plain text from agent endpoints.
Equivalent to FastAPI's PlainTextResponse.
Example
@app.agent_endpoint(name="status") async def status(intent, context): return PlainTextResult(content="OK")
Attributes:
| Name | Type | Description |
|---|---|---|
content |
str | bytes
|
Text string or bytes. |
status_code |
int
|
HTTP status code (default 200). |
headers |
dict[str, str] | None
|
Additional response headers. |
Source code in src/agenticapi/interface/response.py
to_response ¶
Convert to a Starlette PlainTextResponse.
Returns:
| Type | Description |
|---|---|
Response
|
A PlainTextResponse with |