curl https://api.anthropic.com/v1/messages \-H"content-type: application/json"\-H"x-api-key: $ANTHROPIC_API_KEY"\-H"anthropic-version: 2023-06-01"\-d '{"model":"claude-opus-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":[{"type":"document","source":{"type":"url","url":"https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"}},{"type":"text","text":"What are the key findings in this document?"}]}]}'
# Method 1: Fetch and encode a remote PDFcurl-s"https://assets.anthropic.com/m/1cd9d098ac3e6467/original/Claude-3-Model-Card-October-Addendum.pdf"| base64 |tr-d'\n'> pdf_base64.txt# Method 2: Encode a local PDF file# base64 document.pdf | tr -d '\n' > pdf_base64.txt# Create a JSON request file using the pdf_base64.txt contentjq -n--rawfile PDF_BASE64 pdf_base64.txt '{"model":"claude-opus-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":[{"type":"document","source":{"type":"base64","media_type":"application/pdf","data":$PDF_BASE64}},{"type":"text","text":"What are the key findings in this document?"}]}]}' > request.json# Send the API request using the JSON filecurl https://api.anthropic.com/v1/messages \-H"content-type: application/json"\-H"x-api-key: $ANTHROPIC_API_KEY"\-H"anthropic-version: 2023-06-01"\-d @request.json
# First, upload your PDF to the Files APIcurl-X POST https://api.anthropic.com/v1/files \-H"x-api-key: $ANTHROPIC_API_KEY"\-H"anthropic-version: 2023-06-01"\-H"anthropic-beta: files-api-2025-04-14"\-F"file=@document.pdf"# Then use the returned file_id in your messagecurl https://api.anthropic.com/v1/messages \-H"content-type: application/json"\-H"x-api-key: $ANTHROPIC_API_KEY"\-H"anthropic-version: 2023-06-01"\-H"anthropic-beta: files-api-2025-04-14"\-d '{"model":"claude-opus-4-20250514", "max_tokens":1024,"messages":[{"role":"user","content":[{"type":"document","source":{"type":"file","file_id":"file_abc123"}},{"type":"text","text":"What are the key findings in this document?"}]}]}'
# Create a JSON request file using the pdf_base64.txt contentjq -n--rawfile PDF_BASE64 pdf_base64.txt '{"model":"claude-opus-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":[{"type":"document","source":{"type":"base64","media_type":"application/pdf","data":$PDF_BASE64},"cache_control":{"type":"ephemeral"}},{"type":"text","text":"Which model has the highest human preference win rates across each use-case?"}]}]}' > request.json# Then make the API call using the JSON filecurl https://api.anthropic.com/v1/messages \-H"content-type: application/json"\-H"x-api-key: $ANTHROPIC_API_KEY"\-H"anthropic-version: 2023-06-01"\-d @request.json
# Create a JSON request file using the pdf_base64.txt contentjq -n--rawfile PDF_BASE64 pdf_base64.txt '{"requests":[{"custom_id":"my-first-request","params":{"model":"claude-opus-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":[{"type":"document","source":{"type":"base64","media_type":"application/pdf","data":$PDF_BASE64}},{"type":"text","text":"Which model has the highest human preference win rates across each use-case?"}]}]}},{"custom_id":"my-second-request","params":{"model":"claude-opus-4-20250514","max_tokens":1024,"messages":[{"role":"user","content":[{"type":"document","source":{"type":"base64","media_type":"application/pdf","data":$PDF_BASE64}},{"type":"text","text":"Extract 5 key insights from this document."}]}]}}]}' > request.json# Then make the API call using the JSON filecurl https://api.anthropic.com/v1/messages/batches \-H"content-type: application/json"\-H"x-api-key: $ANTHROPIC_API_KEY"\-H"anthropic-version: 2023-06-01"\-d @request.json