# Handling Files

URL: https://interfaze.ai/docs/handling-files

Pass files as base64, binary file object or URL in prompt with URL context understanding.

## File size limits

- URL in prompt: 80 MB
- Base64: 20 MB
- Binary file object: 20 MB

## URL

Pass a publicly accessible file URL directly in the prompt text. The model fetches and reads the file at inference time.

This is great for handling large files that don't fit in the context window.

**Interfaze SDK · typescript**

```typescript
const response = await interfaze.chat.completions.create({
    messages: [
        {
            role: "user",
            content: "Summarize this document for me: https://arxiv.org/pdf/2602.04101",
        },
    ],
});

console.log(response.choices[0]?.message.content);
```

**Vercel AI SDK · typescript**

```typescript
import { generateText } from "ai";

const { text } = await generateText({
    model: interfaze("interfaze-beta"),
    prompt: "Summarize this document for me: https://arxiv.org/pdf/2602.04101",
});

console.log(text);
```

**LangChain SDK · typescript**

```typescript
const response = await interfaze.invoke(
    "Summarize this document for me: https://arxiv.org/pdf/2602.04101"
);

console.log(response.content);
```

**Interfaze SDK · python**

```python
response = interfaze.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": "Summarize this document for me: https://arxiv.org/pdf/2602.04101",
        }
    ],
)

print(response.choices[0].message.content)
```

**LangChain SDK · python**

```python
response = interfaze.invoke(
    "Summarize this document for me: https://arxiv.org/pdf/2602.04101"
)

print(response.content)
```

## Base64

Follows the same pattern as OpenAI file handling SDK.

Read a local file, encode it as base64, and pass it in the message content using the `file` content type.

**Interfaze SDK · typescript**

```typescript
import { inputs } from "interfaze";

const response = await interfaze.chat.completions.create({
    messages: [
        {
            role: "user",
            content: [
                // reads the local file and builds the data URI for you
                inputs.file(await inputs.fromPath("document.pdf"), { filename: "document.pdf" }),
                {
                    type: "text",
                    text: "Summarize this document.",
                },
            ],
        },
    ],
});

console.log(response.choices[0]?.message.content);
```

**Vercel AI SDK · typescript**

```typescript
import { generateText } from "ai";
import fs from "fs";

const fileBuffer = fs.readFileSync("document.pdf");
const base64Data = fileBuffer.toString("base64");

const { text } = await generateText({
    model: interfaze("interfaze-beta"),
    messages: [
        {
            role: "user",
            content: [
                {
                    type: "file",
                    data: base64Data,
                    mediaType: "application/pdf",
                },
                {
                    type: "text",
                    text: "Summarize this document.",
                },
            ],
        },
    ],
});

console.log(text);
```

**LangChain SDK · typescript**

```typescript
import { HumanMessage } from "@langchain/core/messages";
import fs from "fs";

const fileBuffer = fs.readFileSync("document.pdf");
const base64Data = fileBuffer.toString("base64");

const response = await interfaze.invoke([
    new HumanMessage({
        content: [
            {
                type: "file",
                file: {
                    filename: "document.pdf",
                    file_data: `data:application/pdf;base64,${base64Data}`,
                },
            },
            {
                type: "text",
                text: "Summarize this document.",
            },
        ],
    }),
]);

console.log(response.content);
```

**Interfaze SDK · python**

```python
from interfaze import inputs

response = interfaze.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": [
                # reads the local file and builds the data URI for you
                inputs.file(inputs.from_path("document.pdf"), filename="document.pdf"),
                {
                    "type": "text",
                    "text": "Summarize this document.",
                },
            ],
        }
    ],
)

print(response.choices[0].message.content)
```

**LangChain SDK · python**

```python
import base64
from langchain_core.messages import HumanMessage

with open("document.pdf", "rb") as f:
    base64_data = base64.b64encode(f.read()).decode("utf-8")

response = interfaze.invoke([
    HumanMessage(content=[
        {
            "type": "file",
            "file": {
                "filename": "document.pdf",
                "file_data": f"data:application/pdf;base64,{base64_data}",
            },
        },
        {
            "type": "text",
            "text": "Summarize this document.",
        },
    ])
])

print(response.content)
```

## Binary File Object

Read a file as a binary `Buffer` or `Blob` (TypeScript) / `bytes` (Python) and pass it directly in the message. The SDK handles serialization automatically.

LangChain content parts take a string, so encode the bytes as a data URI before passing them along.

**Interfaze SDK · typescript**

```typescript
import { inputs } from "interfaze";
import fs from "fs";

const fileBuffer = fs.readFileSync("document.pdf");

const response = await interfaze.chat.completions.create({
    messages: [
        {
            role: "user",
            content: [
                inputs.file(await inputs.dataUrl(fileBuffer, "application/pdf"), { filename: "document.pdf" }),
                {
                    type: "text",
                    text: "Summarize this document.",
                },
            ],
        },
    ],
});

console.log(response.choices[0]?.message.content);
```

**Vercel AI SDK · typescript**

```typescript
import { generateText } from "ai";
import fs from "fs";

const fileBuffer = fs.readFileSync("document.pdf");

const { text } = await generateText({
    model: interfaze("interfaze-beta"),
    messages: [
        {
            role: "user",
            content: [
                {
                    type: "file",
                    data: fileBuffer,
                    mediaType: "application/pdf",
                },
                {
                    type: "text",
                    text: "Summarize this document.",
                },
            ],
        },
    ],
});

console.log(text);
```

**LangChain SDK · typescript**

```typescript
import { HumanMessage } from "@langchain/core/messages";
import fs from "fs";

const fileBuffer = fs.readFileSync("document.pdf");

const response = await interfaze.invoke([
    new HumanMessage({
        content: [
            {
                type: "file",
                file: {
                    filename: "document.pdf",
                    file_data: `data:application/pdf;base64,${fileBuffer.toString("base64")}`,
                },
            },
            {
                type: "text",
                text: "Summarize this document.",
            },
        ],
    }),
]);

console.log(response.content);
```

**Interfaze SDK · python**

```python
from interfaze import inputs

with open("document.pdf", "rb") as f:
    file_bytes = f.read()

response = interfaze.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": [
                inputs.file(inputs.data_url(file_bytes, "application/pdf"), filename="document.pdf"),
                {
                    "type": "text",
                    "text": "Summarize this document.",
                },
            ],
        }
    ],
)

print(response.choices[0].message.content)
```

**LangChain SDK · python**

```python
import base64
from langchain_core.messages import HumanMessage

with open("document.pdf", "rb") as f:
    file_bytes = f.read()

response = interfaze.invoke([
    HumanMessage(content=[
        {
            "type": "file",
            "file": {
                "filename": "document.pdf",
                "file_data": f"data:application/pdf;base64,{base64.b64encode(file_bytes).decode('utf-8')}",
            },
        },
        {
            "type": "text",
            "text": "Summarize this document.",
        },
    ])
])

print(response.content)
```
