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.
What the model sees
Section titled “What the model sees”| 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:
mistralrs serve --agent -m <model>Download, list, or delete files
Section titled “Download, list, or delete files”| 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.
URL inputs
Section titled “URL inputs”file_url works only in the Responses API. The server downloads the file itself, with these limits:
httpandhttpsonly, 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.
Examples
Section titled “Examples”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)from mistralrs import Architecture, ChatCompletionRequest, InputFile, Runner, Which
runner = Runner( which=Which.Plain( model_id="Qwen/Qwen3-4B", arch=Architecture.Qwen3, ),)
sales = InputFile.from_text( "sales.csv", "region,revenue\nnorth,120\nsouth,95\nwest,180\n", "text/csv",)request = ChatCompletionRequest( messages=[ { "role": "user", "content": "Which region has the highest revenue? Use the attached CSV.", } ], model="default", input_files=[sales],)
response = runner.send_chat_completion_request(request)print(response.choices[0].message.content)use anyhow::Result;use mistralrs::{ InputFile, IsqBits, ModelBuilder, RequestBuilder, TextMessageRole, TextMessages,};
#[tokio::main]async fn main() -> Result<()> { let model = ModelBuilder::new("Qwen/Qwen3-4B") .with_auto_isq(IsqBits::Four) .build() .await?;
let sales = InputFile::from_text_with_mime( "sales.csv", "text/csv", "region,revenue\nnorth,120\nsouth,95\nwest,180\n", ); let messages = TextMessages::new().add_message( TextMessageRole::User, "Which region has the highest revenue? Use the attached CSV.", ); let request = RequestBuilder::from(messages).with_input_file(sales);
let response = model.send_chat_request(request).await?; println!( "{}", response.choices[0].message.content.as_deref().unwrap_or("") );
Ok(())}Full examples:
Attach a file without uploading it
Section titled “Attach a file without uploading it”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 base64from 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 base64from 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)