# Upload File

`POST https://api.vultrinference.com/v1/files`

Uploads a document once, to use in any number of requests by its `id`. The file is converted to text ahead of
time: its `status` is `processing` until then, `processed` when it can be used, or `error` with the reason in
`status_details`. Poll `GET /files/{id}` for the status. Reference a processed file as `{"type": "file", "file":
{"file_id": "file-..."}}` in chat, `{"type": "input_file", "file_id": "file-..."}` in Responses, or a document
block with `{"type": "file", "file_id": "file-..."}` as its source in Messages: the stored text is used, with no
conversion in the request. Documents only (the types listed under `chat-content-part`), up to 100 MB; at most
1,000 files per account; a file expires 30 days after upload. The file's text counts as prompt tokens in the
requests that use it.

## Body (multipart/form-data)

- `file` (string (binary), required): The document. Its type is read from its name, then its content.
- `purpose` (string): Stored and reported as given (OpenAI's `user_data`, `assistants` and so on). [default user_data, at most 32 characters]

## Responses

- `200`: OK (file-object)
- `400`: Bad Request, including a file that is not a document and an account at its file limit. The body is the error envelope. (error-payload)
- `401`: The API key is missing, unknown or not active. Send it as Authorization: Bearer <key>. (error-payload)
- `413`: The file is larger than 100 MB. (error-payload)

## Example

```bash
curl https://api.vultrinference.com/v1/files \
  -H "Authorization: Bearer $VULTR_INFERENCE_API_KEY" \
  -F "file=@file.pdf"
```

```python
import os
import requests

response = requests.post(
    "https://api.vultrinference.com/v1/files",
    headers={"Authorization": f"Bearer {os.environ['VULTR_INFERENCE_API_KEY']}"},
    files={"file": open("file.pdf", "rb")},
)
print(response.json())
```

```javascript
import { openAsBlob } from "node:fs";

const form = new FormData();
form.append("file", await openAsBlob("file.pdf"), "file.pdf");

const response = await fetch("https://api.vultrinference.com/v1/files", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.VULTR_INFERENCE_API_KEY}`,
  },
  body: form,
});
console.log(await response.json());
```
