> ## Documentation Index
> Fetch the complete documentation index at: https://docs.vlm.run/llms.txt
> Use this file to discover all available pages before exploring further.

# Files

> Upload a local file once and pass its url in any content part

`POST /openai/files` uploads a local file and returns a file object with a signed `url`. Pass that `url` in any `*_url` content part instead of a base64 data URI. The route needs an API key: an anonymous call returns `401`.

The upload follows the OpenAI Files request shape: a multipart form with `file` and an optional `purpose`. The reply adds `url`, which the OpenAI Files API does not return.

```python Python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
from openai import OpenAI

client = OpenAI(
    base_url="https://gateway.vlm.run/openai",
    api_key="<VLMRUN_API_KEY>",
)
uploaded = client.files.create(file=open("invoice.pdf", "rb"), purpose="assistants")

response = client.chat.completions.create(
    model="paddleocr/pp-ocrv6",
    messages=[{"role": "user", "content": [
        {"type": "document_url", "document_url": {"url": uploaded.url}},
    ]}],
)
print(response.choices[0].message.content)
```

```typescript Node.js theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import fs from "fs";
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://gateway.vlm.run/openai",
  apiKey: process.env.VLMRUN_API_KEY,
});
const uploaded = await client.files.create({
  file: fs.createReadStream("invoice.pdf"),
  purpose: "assistants",
});
const { url } = uploaded as typeof uploaded & { url: string };

const response = await client.chat.completions.create({
  model: "paddleocr/pp-ocrv6",
  messages: [{ role: "user", content: [
    { type: "document_url", document_url: { url } },
  ] }],
});
console.log(response.choices[0].message.content);
```

```bash cURL theme={"theme":{"light":"github-light","dark":"dark-plus"}}
curl https://gateway.vlm.run/openai/files \
  -H "Authorization: Bearer $VLMRUN_API_KEY" \
  -F "file=@invoice.pdf" \
  -F "purpose=assistants"
```

The request uploads `invoice.pdf`, then reads it page by page with `paddleocr/pp-ocrv6` through the returned `url`.

## The file object

```json theme={"theme":{"light":"github-light","dark":"dark-plus"}}
{
  "id": "4b7a4f23-b0f1-4d0b-bc75-e5cd629a09f7",
  "object": "file",
  "bytes": 78,
  "created_at": 1795215875,
  "filename": "image-20261120-S1D3bH8w0HY-tiny.png",
  "purpose": "assistants",
  "url": "https://storage.googleapis.com/vlm-userdata-prod/files/...?X-Goog-Expires=604800&..."
}
```

| Field | Type | Description |
| - | - | - |
| `id` | `string` | The file id. Send it to `GET /openai/files/{file_id}` for a new `url`. |
| `object` | `string` | Always `file`. |
| `bytes` | `integer` | The file size. |
| `created_at` | `integer` | The upload time, in Unix seconds. |
| `filename` | `string` | The stored name: the file kind, the upload date, and a random tag before your file name, for example `image-20261120-S1D3bH8w0HY-scan.png`. |
| `purpose` | `string` | `assistants` (default), `batch`, `fine-tune`, `vision`, or `datasets`. The Gateway stores it and does not act on it. |
| `url` | `string` | A signed URL that reads the file. It expires 604800 seconds, or 7 days, after the call that returned it. |

## Use the url

* **Chat Completions:** in an `image_url`, `video_url`, `document_url`, or `file_url` part.
* **Embeddings:** in any `*_url` part the model accepts.
* **Transcriptions:** in the `url` form field of [`POST /openai/audio/transcriptions`](https://docs.vlm.run/gateway/api-reference/post-audio-transcriptions).

A file id is not a content part. When a `url` expires, call `GET /openai/files/{file_id}` with the same key for a new one.

```bash theme={"theme":{"light":"github-light","dark":"dark-plus"}}
curl https://gateway.vlm.run/openai/files/<FILE_ID> \
  -H "Authorization: Bearer $VLMRUN_API_KEY"
```

The request returns the same file object with a fresh `url`.

## Access and cost

| Caller | `POST /openai/files` | `GET /openai/files/{file_id}` |
| - | - | - |
| API key | Yes | Yes, for files of the same account |
| Upload token from the MCP `create_upload_token` tool | One upload, then the token is spent | No |
| No key, or `vlmrun` | `401` | `401` |

An upload is not billed. The call that reads the `url` bills as usual. An MCP client with no API key gets an upload token from [`create_upload_token`](https://docs.vlm.run/gateway/mcp-tools). The token is valid for one upload.

## Errors

| Status | When |
| - | - |
| `401` | No API key, or an unknown, expired, or spent upload token. The reply carries `WWW-Authenticate: Bearer`. |
| `403` | The key's user account is not active. |
| `404` | No file with that id for your account. `error.type` is `file_not_found`. |
| `415` | The file type is not accepted. The message lists the accepted extensions: images, video, audio, PDF, Office documents, and archives. A `.txt` file is refused. |
| `4xx` | The file service refused the upload for another reason. The status and message are the service's. |
| `502` | The file service failed or did not answer. The body is the [internal error](https://docs.vlm.run/gateway/error-codes.md#internal-server-error-500) with a `request_id`. Retry with backoff. |

## Next steps

> [card] [Supported Inputs](https://docs.vlm.run/gateway/multimodal-inputs.md)
>
> Content part types and per-modality limits.

> [card] [MCP Tools](https://docs.vlm.run/gateway/mcp-tools.md)
>
> `create_upload_token` for agents with no API key.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.