Skip to content
API referencePDF / documents

PDF / documents

Documents: supported formats, input methods, and limits of the selected API.

Model protocol

Base64 PDF

Claude Messages accepts a PDF in a document block with a base64 source, with and without a server prompt. For a large PDF, choose Opus/Sonnet with a 1M context window and respect the limits below. Chat Completions and Responses do not accept PDFs.

python
import base64
import anthropic

with open("report.pdf", "rb") as f:
    pdf_b64 = base64.standard_b64encode(f.read()).decode("utf-8")

client = anthropic.Anthropic(
    api_key=KEY,
    base_url="https://api.guardrelay.ai",
)
message = client.messages.create(
    model="claude-opus-5",
    max_tokens=1024,
    messages=[{
        "role": "user",
        "content": [
            {"type": "document", "source": {
                "type": "base64",
  • The PDF must be a standard, unencrypted document with no password.
  • The full HTTP request, including base64, must fit within 12 MiB.
  • server prompt also has a shared media budget: up to 4 items, 4 MiB of decoded data per item, and 8 MiB total.
  • Without an applied server prompt, Messages allows up to 600 pages only with a 1M context window; with a smaller window the maximum is 100 pages. server prompt independently remains subject to its 4 MiB per-item media limit.
  • Split a large or dense document across multiple requests.
  • PDFs and text/content document sources count as input tokens. An invalid or oversized PDF with an applied server prompt is rejected before billable processing.

Document inside tool_result

With an applied server prompt, the same document block can be nested in the tool_result.content array. Preserve the original tool_use_id; a PDF must have media_type: "application/pdf" and a base64 source. The same limits apply as for a regular user message.

Kimi, Composer and Grok

  • Kimi. Documents work differently: the file is uploaded with POST /v1/files first, then referenced in the chat request through an input_file block. Formats, limits, quota and file lifetime are covered on Kimi: Chat Completions.
  • Composer and Grok. No documents. A document or file block in content is not recognised and returns a local 400 before any charge. Put the text you need into the message as plain text, keeping the 200K window of Composer and the 256K window of Grok 4.7 and the 500K window of Grok 4.6 in mind.

Codex Files

On the separate Codex Base URL, upload, listing, metadata retrieval, download and deletion are confirmed: POST /codex/v1/files, GET /codex/v1/files, GET /codex/v1/files/{file_id}, GET /codex/v1/files/{file_id}/content and DELETE /codex/v1/files/{file_id}.

bash
curl https://api.guardrelay.ai/codex/v1/files \
  -H "Authorization: Bearer $GUARD_API_KEY" \
  -F "purpose=user_data" \
  -F "file=@notes.txt;type=text/plain"
  • Only the same owner can see a file; replacing your own key does not transfer it to another user.
  • Storage accepts a file up to 512 MiB. Direct materialization of a saved file_id in input_file is limited to 50 MiB.
  • purpose must be one of assistants, batch, evals, fine-tune, user_data, or vision.
  • In Responses, reference the saved file with an input_file block and its file_id; a deleted, expired or foreign id is unavailable.

PDF and MP4 with GLM Flash

glm-5.3-flash reads base64 PDF through all three APIs. MP4 is confirmed only through Chat Completions. No separate file upload is required or published.

FormatChatMessagesResponses
PNG✓✓✓
PDF✓✓✓
MP4✓——

Chat PDF:

json
{
  "type": "file",
  "file": {
    "filename": "report.pdf",
    "file_data": "data:application/pdf;base64,<base64>"
  }
}

Messages PDF:

json
{
  "type": "document",
  "source": {
    "type": "base64",
    "media_type": "application/pdf",
    "data": "<base64>"
  }
}

Responses PDF:

json
{
  "type": "input_file",
  "filename": "report.pdf",
  "file_data": "data:application/pdf;base64,<base64>"
}

Chat MP4:

json
{
  "type": "video_url",
  "video_url": {"url": "data:video/mp4;base64,<base64>"}
}

Guard does not publish a separate GLM file-size limit. Account for your HTTP client's limit and test the real file type required by your application before launch.

PDF with Gemini

Gemini reads a PDF in all three APIs: as embedded base64 data or as an https link, from which Google downloads the file itself.

APIPDF block
Messagesdocument with source.type: "base64", or source.type: "url" with an https address in url
Chat Completionsfile with file_data (a data address or base64 PDF) or file_url (an https address) and filename
Responsesinput_file with file_data or file_url and filename

Chat PDF:

json
{
  "type": "file",
  "file": {
    "filename": "report.pdf",
    "file_data": "data:application/pdf;base64,<base64>"
  }
}

Messages PDF:

json
{
  "type": "document",
  "source": {
    "type": "base64",
    "media_type": "application/pdf",
    "data": "<base64>"
  }
}

Responses PDF:

json
{
  "type": "input_file",
  "filename": "report.pdf",
  "file_data": "data:application/pdf;base64,<base64>"
}

PDF with Muse

Muse reads a PDF sent as embedded base64 data: a document block in Messages or an input_file block in Responses.

Sections

On this page