跳至內容
English
回應

檔案分析 ​

使用 Responses API 分析圖像與檔案。

Responses API 透過 input 陣列中的內容區塊支援多模態輸入。圖像使用 input_image,文件與其他檔案使用 input_file。

端點與驗證方式同建立回應。

請先確認所選模型支援對應媒體類型。file_id 必須來自同一服務與帳戶可讀取的上傳結果;本頁未定義上傳端點,不可直接使用其他供應商的檔案 ID。網址須可由服務端存取,本機路徑不能當作遠端檔案網址。

目前本地網關的 /v1/files 上傳路由尚未實作。首次串接請使用本頁的 URL 或 Base64 輸入方式;只有已確認部署環境支援上傳,且已取得同帳戶可讀取的檔案 ID 時,才使用 file_id 範例。

內容區塊類型 ​

類型說明
input_text隨媒體輸入附上的文字提示
input_image透過 image_url 或 file_id 輸入圖像;可選 detail:auto、low、high、original
input_file透過 file_url、file_id 或 file_data 輸入檔案;可選 detail:auto、low、high

input_image ​

欄位類型必填說明
typestring是固定為 input_image
image_urlstring否完整 URL 或 Base64 資料 URL
file_idstring否先前上傳的檔案 ID
detailstring否auto(預設)、low、high 或 original

input_image 的 image_url 與 file_id 請擇一提供。

input_file ​

欄位類型必填說明
typestring是固定為 input_file
file_urlstring否待分析檔案的 URL
file_idstring否先前上傳的檔案 ID
file_datastring否內嵌檔案內容
filenamestring否檔案顯示名稱
detailstring否auto(預設)、low 或 high

input_file 的 file_url、file_id 與 file_data 請擇一提供。以 file_data 傳入內容時,同時提供含副檔名的 filename。

詳細程度

GPT-5.6 及後續模型的 detail: auto 使用高品質呈現,可能增加輸入 Token 用量。使用 low 可降低成本,high 則提供更高品質。

圖像分析 ​

透過 URL 分析圖像:

json
{
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {"type": "input_text", "text": "What is in this image?"},
        {
          "type": "input_image",
          "image_url": "https://example.com/image.jpg",
          "detail": "auto"
        }
      ]
    }
  ]
}

使用先前上傳的檔案 ID 分析圖像:

json
{
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {"type": "input_text", "text": "Describe this image in detail."},
        {
          "type": "input_image",
          "file_id": "file-abc123",
          "detail": "high"
        }
      ]
    }
  ]
}

檔案分析 ​

透過 URL 分析 PDF 或文件:

json
{
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {"type": "input_text", "text": "Summarize the key points in this document."},
        {
          "type": "input_file",
          "file_url": "https://example.com/report.pdf",
          "detail": "auto"
        }
      ]
    }
  ]
}

請求範例 ​

執行方式見多語言範例說明。先設定 API_KEY,並替換模型、檔案網址及 ID 占位值;四種方式會顯示相同請求的原始回應。

bash
curl --fail-with-body --silent --show-error --max-time 180 \
  --request POST \
  --url "https://api.tokatlas.ai/v1/responses" \
  --header "Authorization: Bearer $API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "What is in this file?"
        },
        {
          "type": "input_file",
          "file_url": "https://www.example.com/document.pdf",
          "detail": "auto"
        }
      ]
    }
  ]
}'
python
import os
import requests

headers = {
    'Authorization': 'Bearer ' + os.environ["API_KEY"],
    'Content-Type': 'application/json',
}
payload = {'model': 'gpt-5',
 'input': [{'role': 'user',
            'content': [{'type': 'input_text', 'text': 'What is in this file?'},
                        {'type': 'input_file',
                         'file_url': 'https://www.example.com/document.pdf',
                         'detail': 'auto'}]}]}
response = requests.request(
    'POST', 'https://api.tokatlas.ai/v1/responses', headers=headers,
    json=payload,
    timeout=180,
)
response.raise_for_status()
print(response.text)
js
if (!process.env.API_KEY) throw new Error("Set API_KEY first.");
const response = await fetch("https://api.tokatlas.ai/v1/responses", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "gpt-5",
  "input": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_text",
          "text": "What is in this file?"
        },
        {
          "type": "input_file",
          "file_url": "https://www.example.com/document.pdf",
          "detail": "auto"
        }
      ]
    }
  ]
}),
  signal: AbortSignal.timeout(180_000),
});
if (!response.ok) {
  throw new Error(`HTTP ${response.status}: ${await response.text()}`);
}
console.log(await response.text());
java
import java.net.URI;
import java.net.http.*;
import java.time.Duration;

public class Example {
    public static void main(String[] args) throws Exception {
        String apiKey = System.getenv("API_KEY");
        if (apiKey == null || apiKey.isBlank()) {
            throw new IllegalArgumentException("Set API_KEY first.");
        }
        String payload = String.join("\n",
            "{",
            "  \"model\": \"gpt-5\",",
            "  \"input\": [",
            "    {",
            "      \"role\": \"user\",",
            "      \"content\": [",
            "        {",
            "          \"type\": \"input_text\",",
            "          \"text\": \"What is in this file?\"",
            "        },",
            "        {",
            "          \"type\": \"input_file\",",
            "          \"file_url\": \"https://www.example.com/document.pdf\",",
            "          \"detail\": \"auto\"",
            "        }",
            "      ]",
            "    }",
            "  ]",
            "}"
        );
        HttpClient client = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(30)).build();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.tokatlas.ai/v1/responses"))
            .timeout(Duration.ofSeconds(180))
            .header("Authorization", "Bearer " + apiKey)
            .header("Content-Type", "application/json")
            .method("POST", HttpRequest.BodyPublishers.ofString(payload))
            .build();
        HttpResponse<String> response = client.send(
            request, HttpResponse.BodyHandlers.ofString());
        if (response.statusCode() < 200 || response.statusCode() >= 300) {
            throw new IllegalStateException("HTTP " + response.statusCode() + ": "
                + response.body());
        }
        System.out.println(response.body());
    }
}

回應範例 ​

json
{
  "code": 200,
  "data": {
    "id": "resp_686eef60237881a2bd1180bb8b13de430e34c516d176ff86",
    "object": "response",
    "status": "completed",
    "model": "gpt-5",
    "output": [
      {
        "type": "message",
        "status": "completed",
        "role": "assistant",
        "content": [
          {
            "type": "output_text",
            "text": "The document covers quarterly financial results, including revenue growth of 12% year-over-year...",
            "annotations": []
          }
        ]
      }
    ],
    "usage": {
      "input_tokens": 8438,
      "output_tokens": 398,
      "total_tokens": 8836
    }
  }
}

相關主題 ​