Skip to content

OpenAI-compatible file inputs

You can attach files such as CSVs, JSON, logs, or source code to a request and ask the model about them. With code execution or shell turned on, the model can also open the files from Python or the command line, for example to load a CSV with pandas.

mistral.rs accepts files the same ways OpenAI does:

How Where it works
Upload once with POST /v1/files (purpose="user_data"), then reference the returned file_id Chat Completions file parts, Responses input_file parts
Send the contents inline as base64 or a data URL in file_data Chat Completions and Responses
Give a public http or https URL in file_url Responses only
Pass an InputFile in the Rust or Python SDK RequestBuilder::with_input_file(...), ChatCompletionRequest.input_files

Field-level details are in OpenAI compatibility and the HTTP file reference.

File type What the model gets
UTF-8 text: plain text, CSV, JSON, XML, Markdown, YAML, TOML, HTML, source code The file’s name, size, and type, plus the first 4,096 characters. Previews share a budget of 32,768 characters per request.
Anything else: PDFs, images, spreadsheets, archives Only the name, size, and type. mistral.rs doesn’t extract PDF text, run OCR, or summarize spreadsheets.

When a text file is longer than its preview, the model can read the rest itself. On the server, every request with attached files gets built-in tools to list the files and read any part of one, up to 64K characters per read, so you don’t need to turn anything else on. The model never sees base64.

With code execution or shell on, every attached file, binary or text, is also copied into the session’s working directory under its original name. That’s how the model can work with formats it can’t read directly, for example by opening a PDF or spreadsheet from Python. Skills can use the same files.

To get every tool at once, start the server with --agent:

Terminal window
mistralrs serve --agent -m <model>
Endpoint Returns
GET /v1/files Metadata for every stored file.
GET /v1/files/{id} One file’s metadata.
GET /v1/files/{id}/content The file’s bytes.
DELETE /v1/files/{id} Removes the file.

Uploaded files and files the tools wrote live in the same store. The server keeps each one for 30 minutes after it was uploaded or last used in a request, so upload shortly before you need a file.

file_url works only in the Responses API. The server downloads the file itself, with these limits:

  • http and https only, and the host must be public: local and private addresses are refused.
  • 30-second timeout, at most 3 redirects, and at most 64 MiB.

In Chat Completions, upload the file first or send it inline.

from openai import OpenAI
client = OpenAI(base_url="http://localhost:1234/v1", api_key="not-used")
with open("data.csv", "rb") as file:
uploaded = client.files.create(file=file, purpose="user_data")
response = client.responses.create(
model="default",
input=[
{
"role": "user",
"content": [
{"type": "input_file", "file_id": uploaded.id},
{"type": "input_text", "text": "Summarize this CSV."},
],
}
],
)
print(response.output_text)

Full examples:

To skip the separate upload, put the file’s contents in the request as a base64 data URL. In the Responses API, use an input_file part with filename and file_data:

import base64
from openai import OpenAI
client = OpenAI(base_url="http://localhost:1234/v1", api_key="not-used")
with open("notes.md", "rb") as file:
data = base64.b64encode(file.read()).decode("utf-8")
response = client.responses.create(
model="default",
input=[
{
"role": "user",
"content": [
{
"type": "input_file",
"filename": "notes.md",
"file_data": f"data:text/markdown;base64,{data}",
},
{"type": "input_text", "text": "Extract the action items."},
],
}
],
)
print(response.output_text)

In Chat Completions, use a file part with the same two fields nested under file:

import base64
from openai import OpenAI
client = OpenAI(base_url="http://localhost:1234/v1", api_key="not-used")
with open("report.json", "rb") as file:
data = base64.b64encode(file.read()).decode("utf-8")
completion = client.chat.completions.create(
model="default",
messages=[
{
"role": "user",
"content": [
{
"type": "file",
"file": {
"filename": "report.json",
"file_data": f"data:application/json;base64,{data}",
},
},
{"type": "text", "text": "What are the main anomalies?"},
],
}
],
)
print(completion.choices[0].message.content)