# File Attachments

**Example request**

{% tabs %}
{% tab title="Python" %}

```python
import os
import base64
import anthropic
 
client = anthropic.Anthropic(
    api_key="<API_KEY>",,
    base_url='https://llm.onerouter.pro'
)
 
# Read files as base64
with open('./document.pdf', 'rb') as f:
    pdf_base64 = base64.b64encode(f.read()).decode('utf-8')
 
with open('./image.png', 'rb') as f:
    image_base64 = base64.b64encode(f.read()).decode('utf-8')
 
message = client.messages.create(
    model='claude-sonnet-4-5@20250929',
    max_tokens=1024,
    messages=[
        {
            'role': 'user',
            'content': [
                {
                    'type': 'document',
                    'source': {
                        'type': 'base64',
                        'media_type': 'application/pdf',
                        'data': pdf_base64,
                    },
                },
                {
                    'type': 'image',
                    'source': {
                        'type': 'base64',
                        'media_type': 'image/png',
                        'data': image_base64,
                    },
                },
                {
                    'type': 'text',
                    'text': 'Please summarize the PDF and describe the image.',
                },
            ],
        }
    ],
)
 
print('Response:', message.content[0].text)
```

{% endtab %}

{% tab title="TypeScript" %}

```typescript
import Anthropic from '@anthropic-ai/sdk';
import fs from 'node:fs';
 
const anthropic = new Anthropic({
  "<API_KEY>",
  baseURL: 'https://llm.onerouter.pro',
});
 
// Read files as base64
const pdfData = fs.readFileSync('./document.pdf');
const imageData = fs.readFileSync('./image.png');
 
const pdfBase64 = pdfData.toString('base64');
const imageBase64 = imageData.toString('base64');
 
const message = await anthropic.messages.create({
  model: 'anthropic/claude-sonnet-4.5',
  max_tokens: 1024,
  messages: [
    {
      role: 'user',
      content: [
        {
          type: 'document',
          source: {
            type: 'base64',
            media_type: 'application/pdf',
            data: pdfBase64,
          },
        },
        {
          type: 'image',
          source: {
            type: 'base64',
            media_type: 'image/png',
            data: imageBase64,
          },
        },
        {
          type: 'text',
          text: 'Please summarize the PDF and describe the image.',
        },
      ],
    },
  ],
});
 
console.log('Response:', message.content[0].text);
```

{% endtab %}
{% endtabs %}

### Supported file types

* Images: `image/jpeg`, `image/png`, `image/gif`, `image/webp`
* Documents: `application/pdf`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://infronai.gitbook.io/docs/llm-apis/anthropic-compatible-api/file-attachments.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
