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

# Working with Files

> Send PDFs, documents, and audio to models through /v1/chat/completions using the file and input_audio content types

You can attach files directly to a chat completion by adding a `file` or `input_audio` content part to a message, alongside `text` and `image_url`. This works for documents (PDF, and on some models TXT, CSV, DOCX, XLSX) and for audio.

## Sending a File

Add a content part with `type: "file"` to the `content` array of a message. Provide the file either as a base64-encoded data URL in `file_data`, or as a public URL in `file_id`.

<CodeGroup>
  ```json Base64 theme={"system"}
  {
    "model": "google/gemini-2.5-flash",
    "messages": [
      {
        "role": "user",
        "content": [
          { "type": "text", "text": "Summarize this document" },
          {
            "type": "file",
            "file": {
              "file_data": "data:application/pdf;base64,JVBERi0xLjQKJ..."
            }
          }
        ]
      }
    ]
  }
  ```

  ```json Public URL theme={"system"}
  {
    "model": "openai/gpt-4o-mini",
    "messages": [
      {
        "role": "user",
        "content": [
          { "type": "text", "text": "Summarize this document" },
          {
            "type": "file",
            "file": {
              "file_id": "https://example.com/report.pdf"
            }
          }
        ]
      }
    ]
  }
  ```
</CodeGroup>

<Note>
  A public URL is accepted in either `file_data` or `file_id` — both fields work the same way for a URL. `file_data` is the field to use for base64-encoded data.
</Note>

The response is a standard `chat.completion` object, the same shape you'd get from a text-only request — there's no separate annotations, file hash, or provider-specific metadata attached to file content.

## Supported Formats by Model

PDF input is broadly supported. Support for other document formats depends on the model:

| Format     | Availability                                                                          |
| ---------- | ------------------------------------------------------------------------------------- |
| PDF        | Supported across models (verified on Gemini 2.5 Flash, GPT-4o-mini, Claude Haiku 4.5) |
| TXT, CSV   | Supported on Gemini models                                                            |
| DOCX, XLSX | Depends on the model                                                                  |

Since support varies by model and can change as providers update their backends, use [tag routing](/features/tag-routing) to guarantee your request lands on a backend that supports file input, instead of hardcoding a model:

```json theme={"system"}
{
  "model": "anthropic/claude-sonnet-4",
  "messages": [{ "role": "user", "content": "..." }],
  "tags": ["chat_completions:pdf_input"]
}
```

## Sending Audio

Audio uses a dedicated `input_audio` content part instead of `file`. Provide base64-encoded audio data and its format:

```json theme={"system"}
{
  "model": "google/gemini-2.5-pro",
  "messages": [
    {
      "role": "user",
      "content": [
        { "type": "text", "text": "Transcribe and summarize this audio" },
        {
          "type": "input_audio",
          "input_audio": {
            "data": "base64_encoded_audio_data_here...",
            "format": "wav"
          }
        }
      ]
    }
  ]
}
```

Audio input (both `input_audio` and `type: "file"` with a `data:audio/...` data URL) is currently only supported on Gemini models. Use the `audio_input` tag to route to a backend that supports it:

```json theme={"system"}
{
  "tags": ["chat_completions:audio_input"]
}
```

<Info>
  To have the model *generate* audio back, see the `modalities` and `audio` parameters on [Create Chat Completion](/api-reference/text/create-chat-completion).
</Info>

## Choosing Models by File Capability

Query `/v1/models` and filter by the `pdf_input` or `audio_input` tags to find models that support the file type you need — see [Tag Routing](/features/tag-routing) for the full list of capability tags and how to filter or route by them.
