ファイル入力への対応は API エンドポイントによって異なります。Responses API は、以下のファイル形式を input_file 項目として受け付けます。Chat Completions は、file コンテンツパートとして PDF ファイルのみを受け付けます。
| 入力方法 | Responses API | Chat Completions |
|---|---|---|
Base64 エンコードされたファイルデータ(file_data) | 以下に示す対応ファイル形式 | PDF のみ |
アップロード済みファイルの ID(file_id) | 以下に示す対応ファイル形式 | PDF のみ |
外部ファイルの URL(file_url) | 以下に示す対応ファイル形式 | 非対応 |
PDF 以外のファイルを入力するには、Responses API を使用してください。Chat Completions でファイル内のテキストを使用するには、アプリケーションでファイルを読み込み、その内容を text コンテンツパートとして送信してください。
仕組み
Responses API では、input_file の処理方法はファイル形式によって次のように異なります。
- PDF ファイル:
gpt-4o以降のモデルなど、画像認識機能を備えたモデルでは、API がテキストとページ画像の両方を抽出し、モデルに送信します。 - PDF 以外のドキュメントとテキストファイル (
.docx、.pptx、.txt、コードファイルなど):API はテキストのみを抽出します。 - スプレッドシートファイル (
.xlsx、.csv、.tsvなど):API は、スプレッドシート専用のデータ補強処理を実行します(後述)。
タスクに応じて、次の関連ツールも利用できます。
- 大きなファイルから情報を取得する場合は、ファイルを
input_fileとして直接渡す代わりに、ファイル検索を使用してください。 - 集計、結合、グラフ作成、カスタム計算など、スプレッドシートを中心に詳細な分析を行うタスクには、ホスト型シェルを使用してください。
PDF 以外のファイルに含まれる画像とグラフの制限
PDF 以外のファイルでは、Responses API は埋め込まれた画像やグラフを抽出してモデルのコンテキストに取り込むことはありません。
グラフや図を忠実に保持するには、まずファイルを PDF に変換し、
その PDF を input_file として送信してください。
スプレッドシートのデータ補強処理の仕組み
スプレッドシート形式のファイル(.xlsx、.xls、.csv、.tsv、
.iif など)に対して、Responses API はスプレッドシート専用のデータ補強処理を行います。
API はシート全体をモデルに渡す代わりに、各シートの先頭から最大 1,000 行を解析し、モデルが生成した要約とヘッダーのメタデータを追加します。これにより、モデルはコンパクトに構造化されたデータを使って処理できます。
PDF の詳細度
Responses API で PDF を入力する場合、input_file 項目の任意の detail フィールドを
auto、low、または high に設定すると、API によるページ画像の処理方法を制御できます。
省略した場合、detail のデフォルト値は auto です。GPT-5.6 以降のモデルでは、
auto にすると high が使われ、それ以前のモデルでは low が使われます。入力トークン数を抑えるには low を、
情報量の多いグラフ、小さな文字、図などの視覚的な細部を
より詳しく読み取るには high を使用してください。
detail の設定が影響するのは、PDF のページ画像の処理のみです。
PDF から抽出されたテキストは引き続き含まれます。Chat Completions のファイル入力は detail に対応していません。
詳細度を明示的に高く設定した Responses API の最小限のリクエスト本文は、次のようになります。
{
"model": "gpt-4.1",
"input": [
{
"role": "user",
"content": [
{
"type": "input_file",
"filename": "document.pdf",
"file_data": "data:application/pdf;base64,...",
"detail": "high"
},
{
"type": "input_text",
"text": "Summarize this document."
}
]
}
]
}
対応するファイル形式
次の表は、Responses API が input_file 項目として受け付ける
主なファイル形式を示しています。拡張子と MIME タイプの全一覧は、
このページの後半にあります。Chat Completions は、file_data と file_id のどちらも
.pdf(application/pdf)にのみ対応しています。
| カテゴリ | 主な拡張子 |
|---|---|
| PDF ファイル | .pdf |
| テキストとコード | .txt、.md、.json、.html、.xml、コードファイル |
| 書式付きドキュメント | .doc、.docx、.rtf、.odt |
| プレゼンテーション | .ppt、.pptx |
| スプレッドシート | .csv、.xls、.xlsx |
ファイル URL
外部 URL を指定して、ファイルを入力できます。
curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"input": [
{
"role": "user",
"content": [
{
"type": "input_text",
"text": "Analyze the letter and provide a summary of the key points."
},
{
"type": "input_file",
"file_url": "https://www.berkshirehathaway.com/letters/2024ltr.pdf"
}
]
}
]
}'Chat Completions はファイル URL に対応していません。この方法を利用するには、Responses API を使用してください。
ファイルのアップロード
次の例では、Files API でファイルをアップロードし、モデルへのリクエストでそのファイル ID を参照します。
curl https://api.openai.com/v1/files \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F purpose="user_data" \
-F file="@draconomicon.pdf"
curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"input": [
{
"role": "user",
"content": [
{
"type": "input_file",
"file_id": "file-6F2ksmvXxt4VdoqmHRw6kL"
},
{
"type": "input_text",
"text": "What is the first dragon in the book?"
}
]
}
]
}'curl https://api.openai.com/v1/files \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-F purpose="user_data" \
-F file="@draconomicon.pdf"
curl "https://api.openai.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"messages": [
{
"role": "user",
"content": [
{
"type": "file",
"file": {
"file_id": "file-6F2ksmvXxt4VdoqmHRw6kL"
}
},
{
"type": "text",
"text": "What is the first dragon in the book?"
}
]
}
]
}'Base64 エンコードされたファイル
ファイル入力は、Base64 エンコードされたファイルデータとして送信することもできます。
curl "https://api.openai.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"input": [
{
"role": "user",
"content": [
{
"type": "input_file",
"filename": "draconomicon.pdf",
"file_data": "...base64 encoded PDF bytes here..."
},
{
"type": "input_text",
"text": "What is the first dragon in the book?"
}
]
}
]
}'curl "https://api.openai.com/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{
"model": "gpt-6-astra",
"messages": [
{
"role": "user",
"content": [
{
"type": "file",
"file": {
"filename": "draconomicon.pdf",
"file_data": "...base64 encoded bytes here..."
}
},
{
"type": "text",
"text": "What is the first dragon in the book?"
}
]
}
]
}'利用時の注意点
ファイル入力を使用する際は、次の制約に注意してください。
- トークン使用量: PDF の解析では、抽出されたテキストとページ画像の両方がコンテキストに含まれるため、トークン使用量が増えることがあります。Responses API では、
detailをauto(デフォルト)、low、またはhighに設定することで、PDF のページ画像を視覚的にどこまで詳しく処理するかを制御できます。大規模にデプロイする前に、料金とトークン使用量への影響を確認してください。料金の詳細をご覧ください。 - ファイルサイズの制限: 1 回のリクエストに複数のファイルを含めることができますが、各ファイルは 50 MB 未満である必要があります。リクエストに含まれる全ファイルの合計サイズの上限は 50 MB です。
- 対応モデル: テキストとページ画像を含む PDF の解析には、
gpt-4o以降のモデルなど、画像認識機能を備えたモデルが必要です。 - ファイルのアップロード目的: ファイルのアップロード時には、対応する任意の目的を指定できますが、モデルへの入力として渡す予定のファイルには
user_dataを使用してください。
対応するファイル形式の全一覧
この一覧は Responses API に適用されます。Chat Completions は、file_data と file_id のどちらも .pdf
(application/pdf)にのみ対応しています。
| カテゴリ | 拡張子 | MIME タイプ |
|---|---|---|
| PDF ファイル | PDF ファイル(.pdf) | application/pdf |
| スプレッドシート | Excel シート(.xla, .xlb, .xlc, .xlm, .xls, .xlsx, .xlt, .xlw) | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel |
| スプレッドシート | CSV / TSV / IIF(.csv, .tsv, .iif)、Google Sheets | text/csv, application/csv, text/tsv, text/x-iif, application/x-iif, application/vnd.google-apps.spreadsheet |
| 書式付きドキュメント | Word/ODT/RTF ドキュメント(.doc, .docx, .dot, .odt, .rtf)、Pages、Google Docs | application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/msword, application/rtf, text/rtf, application/vnd.oasis.opendocument.text, application/vnd.apple.pages, application/vnd.google-apps.document, application/vnd.apple.iwork |
| プレゼンテーション | PowerPoint スライド(.pot, .ppa, .pps, .ppt, .pptx, .pwz, .wiz)、Keynote、Google Slides | application/vnd.openxmlformats-officedocument.presentationml.presentation, application/vnd.ms-powerpoint, application/vnd.apple.keynote, application/vnd.google-apps.presentation, application/vnd.apple.iwork |
| テキストとコード | テキスト・コード形式(.asm, .bat, .c, .cc, .conf, .cpp, .css, .cxx, .def, .dic, .eml, .h, .hh, .htm, .html, .ics, .ifb, .in, .js, .json, .ksh, .list, .log, .markdown, .md, .mht, .mhtml, .mime, .mjs, .nws, .pl, .py, .rst, .s, .sql, .srt, .text, .txt, .vcf, .vtt, .xml) | application/javascript, application/typescript, text/xml, text/x-shellscript, text/x-rst, text/x-makefile, text/x-lisp, text/x-asm, text/vbscript, text/css, message/rfc822, application/x-sql, application/x-scala, application/x-rust, application/x-powershell, text/x-diff, text/x-patch, application/x-patch, text/plain, text/markdown, text/x-java, text/x-script.python, text/x-python, text/x-c, text/x-c++, text/x-golang, text/html, text/x-php, application/x-php, application/x-httpd-php, application/x-httpd-php-source, text/x-ruby, text/x-sh, text/x-bash, application/x-bash, text/x-zsh, text/x-tex, text/x-csharp, application/json, text/x-typescript, text/javascript, text/x-go, text/x-rust, text/x-scala, text/x-kotlin, text/x-swift, text/x-lua, text/x-r, text/x-R, text/x-julia, text/x-perl, text/x-objectivec, text/x-objectivec++, text/x-erlang, text/x-elixir, text/x-haskell, text/x-clojure, text/x-groovy, text/x-dart, text/x-awk, application/x-awk, text/jsx, text/tsx, text/x-handlebars, text/x-mustache, text/x-ejs, text/x-jinja2, text/x-liquid, text/x-erb, text/x-twig, text/x-pug, text/x-jade, text/x-tmpl, text/x-cmake, text/x-dockerfile, text/x-gradle, text/x-ini, text/x-properties, text/x-protobuf, application/x-protobuf, text/x-sql, text/x-sass, text/x-scss, text/x-less, text/x-hcl, text/x-terraform, application/x-terraform, text/x-toml, application/x-toml, application/graphql, application/x-graphql, text/x-graphql, application/x-ndjson, application/json5, application/x-json5, text/x-yaml, application/toml, application/x-yaml, application/yaml, text/x-astro, text/srt, application/x-subrip, text/x-subrip, text/vtt, text/x-vcard, text/calendar |
次のステップ
次は、以下のリソースも参考にしてください。