> For the complete documentation index, see [llms.txt](https://docs.cortecs.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.cortecs.ai/examples/document-inputs.md).

# Document Inputs

**Document inputs** let multimodal models analyze files together with text prompts. Common use cases include summarization, information extraction, question answering, and document comparison.

To explore available models, visit [cortecs.ai](https://cortecs.ai/serverlessModels?tags=Document) and filter by the **Document** tag.

{% hint style="info" %}
Supported document formats, file sizes, and page limits depend on the model and provider. The examples below send a PDF as Base64-encoded data.
{% endhint %}

## OpenAI Chat Completions API

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

```python
import base64
from pathlib import Path

from openai import OpenAI

client = OpenAI(
    base_url="https://api.cortecs.ai/v1",
    api_key="<API_KEY>",
)

pdf_base64 = base64.b64encode(
    Path("path/to/document.pdf").read_bytes()
).decode("utf-8")

completion = client.chat.completions.create(
    model="<MODEL_NAME>",
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "file",
                    "file": {
                        "filename": "document.pdf",
                        "file_data": f"data:application/pdf;base64,{pdf_base64}",
                    },
                },
                {
                    "type": "text",
                    "text": "Summarize the key points in this document.",
                },
            ],
        }
    ],
)

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

{% endtab %}

{% tab title="Node.js" %}

```javascript
import fs from "fs";
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.cortecs.ai/v1",
  apiKey: "<API_KEY>"
});

const pdfBase64 = fs
  .readFileSync("path/to/document.pdf")
  .toString("base64");

const completion = await client.chat.completions.create({
  model: "<MODEL_NAME>",
  messages: [
    {
      role: "user",
      content: [
        {
          type: "file",
          file: {
            filename: "document.pdf",
            file_data: `data:application/pdf;base64,${pdfBase64}`
          }
        },
        {
          type: "text",
          text: "Summarize the key points in this document."
        }
      ]
    }
  ]
});

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

{% endtab %}

{% tab title="Curl" %}

```bash
pdf_base64=$(base64 < path/to/document.pdf | tr -d '\n')

curl 'https://api.cortecs.ai/v1/chat/completions' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API_KEY>' \
  -d '{
    "model": "<MODEL_NAME>",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "file",
            "file": {
              "filename": "document.pdf",
              "file_data": "data:application/pdf;base64,'"${pdf_base64}"'"
            }
          },
          {
            "type": "text",
            "text": "Summarize the key points in this document."
          }
        ]
      }
    ]
  }'
```

{% endtab %}
{% endtabs %}

## OpenAI Responses API

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

```python
import base64
from pathlib import Path

from openai import OpenAI

client = OpenAI(
    base_url="https://api.cortecs.ai/v1",
    api_key="<API_KEY>",
)

pdf_base64 = base64.b64encode(
    Path("path/to/document.pdf").read_bytes()
).decode("utf-8")

response = client.responses.create(
    model="<MODEL_NAME>",
    input=[
        {
            "role": "user",
            "content": [
                {
                    "type": "input_file",
                    "filename": "document.pdf",
                    "file_data": f"data:application/pdf;base64,{pdf_base64}",
                },
                {
                    "type": "input_text",
                    "text": "Summarize the key points in this document.",
                },
            ],
        }
    ],
)

print(response.output_text)
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
import fs from "fs";
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://api.cortecs.ai/v1",
  apiKey: "<API_KEY>"
});

const pdfBase64 = fs
  .readFileSync("path/to/document.pdf")
  .toString("base64");

const response = await client.responses.create({
  model: "<MODEL_NAME>",
  input: [
    {
      role: "user",
      content: [
        {
          type: "input_file",
          filename: "document.pdf",
          file_data: `data:application/pdf;base64,${pdfBase64}`
        },
        {
          type: "input_text",
          text: "Summarize the key points in this document."
        }
      ]
    }
  ]
});

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

{% endtab %}

{% tab title="Curl" %}

```bash
pdf_base64=$(base64 < path/to/document.pdf | tr -d '\n')

curl 'https://api.cortecs.ai/v1/responses' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API_KEY>' \
  -d '{
    "model": "<MODEL_NAME>",
    "input": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_file",
            "filename": "document.pdf",
            "file_data": "data:application/pdf;base64,'"${pdf_base64}"'"
          },
          {
            "type": "input_text",
            "text": "Summarize the key points in this document."
          }
        ]
      }
    ]
  }'
```

{% endtab %}
{% endtabs %}

## Anthropic Messages API

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

```python
import base64
from pathlib import Path

from anthropic import Anthropic

client = Anthropic(
    base_url="https://api.cortecs.ai",
    api_key="<API_KEY>",
)

pdf_base64 = base64.b64encode(
    Path("path/to/document.pdf").read_bytes()
).decode("utf-8")

message = client.messages.create(
    model="<MODEL_NAME>",
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": [
                {
                    "type": "document",
                    "source": {
                        "type": "base64",
                        "media_type": "application/pdf",
                        "data": pdf_base64,
                    },
                },
                {
                    "type": "text",
                    "text": "Summarize the key points in this document.",
                },
            ],
        }
    ],
)

print("\n".join(block.text for block in message.content if block.type == "text"))
```

{% endtab %}

{% tab title="Node.js" %}

```javascript
import fs from "fs";
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://api.cortecs.ai",
  apiKey: "<API_KEY>"
});

const pdfBase64 = fs
  .readFileSync("path/to/document.pdf")
  .toString("base64");

const message = await client.messages.create({
  model: "<MODEL_NAME>",
  max_tokens: 1024,
  messages: [
    {
      role: "user",
      content: [
        {
          type: "document",
          source: {
            type: "base64",
            media_type: "application/pdf",
            data: pdfBase64
          }
        },
        {
          type: "text",
          text: "Summarize the key points in this document."
        }
      ]
    }
  ]
});

console.log(
  message.content
    .filter((block) => block.type === "text")
    .map((block) => block.text)
    .join("\n")
);
```

{% endtab %}

{% tab title="Curl" %}

```bash
pdf_base64=$(base64 < path/to/document.pdf | tr -d '\n')

curl 'https://api.cortecs.ai/v1/messages' \
  -H 'Content-Type: application/json' \
  -H 'Authorization: Bearer <API_KEY>' \
  -H 'anthropic-version: 2023-06-01' \
  -d '{
    "model": "<MODEL_NAME>",
    "max_tokens": 1024,
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "document",
            "source": {
              "type": "base64",
              "media_type": "application/pdf",
              "data": "'"${pdf_base64}"'"
            }
          },
          {
            "type": "text",
            "text": "Summarize the key points in this document."
          }
        ]
      }
    ]
  }'
```

{% endtab %}
{% endtabs %}
