Skip to content
繁體中文
Chat

File Analysis ​

Image, audio, and file analysis using the Chat Completions API.

The Chat Completions API supports multimodal input via content parts in the messages array. Supported part types in user messages include text, images, audio, and files.

Endpoint and authentication are the same as Create Chat Completion.

Confirm that the selected model supports the media type. A file_id must come from an upload accessible to the same service and account; this page does not define an upload endpoint, and another provider’s file ID is not interchangeable. URLs must be reachable by the server; local paths are not remote file URLs.

The current local gateway does not implement /v1/files uploads. Start with this page's URL or Base64 input examples. Use file_id examples only when your deployment provides uploads and you already have an ID accessible to the same account.

Content Part Types ​

TypeDescription
textText prompt (text field required)
image_urlImage input via URL or base64 data; optional detail: auto, low, high
input_audioAudio input via base64 data; format: wav or mp3
fileUse file_id, or file_data with filename; a filename alone does not supply file contents

Image Analysis ​

Analyze an image by URL:

json
{
  "model": "gpt-5",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this image?"},
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.jpg",
            "detail": "auto"
          }
        }
      ]
    }
  ],
  "max_completion_tokens": 300,
  "stream": false
}

Base64-encoded image:

json
{
  "model": "gpt-5",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "Describe this image."},
        {
          "type": "image_url",
          "image_url": {
            "url": "data:image/jpeg;base64,/9j/4AAQSkZJRg..."
          }
        }
      ]
    }
  ]
}

Audio Analysis ​

Send audio as a base64-encoded content part:

json
{
  "model": "gpt-4o-audio-preview",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "input_audio",
          "input_audio": {
            "data": "<base64-encoded-audio>",
            "format": "wav"
          }
        },
        {"type": "text", "text": "Transcribe and summarize this audio."}
      ]
    }
  ]
}

Supported audio formats: wav, mp3.

File Analysis ​

Analyze a document using a file ID from the Files API:

json
{
  "model": "gpt-5",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "Summarize this document"},
        {
          "type": "file",
          "file": {
            "file_id": "file-abc123"
          }
        }
      ]
    }
  ]
}

Request Example ​

See language setup. Set API_KEY and replace model, file URL, and ID placeholders first. Each version displays the raw response to the same request.

bash
curl --fail-with-body --silent --show-error --max-time 180 \
  --request POST \
  --url "https://api.tokatlas.ai/v1/chat/completions" \
  --header "Authorization: Bearer $API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "model": "gpt-5",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What is in this image?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.jpg"
          }
        }
      ]
    }
  ],
  "stream": false
}'
python
import os
import requests

headers = {
    'Authorization': 'Bearer ' + os.environ["API_KEY"],
    'Content-Type': 'application/json',
}
payload = {'model': 'gpt-5',
 'messages': [{'role': 'user',
               'content': [{'type': 'text', 'text': 'What is in this image?'},
                           {'type': 'image_url',
                            'image_url': {'url': 'https://example.com/image.jpg'}}]}],
 'stream': False}
response = requests.request(
    'POST', 'https://api.tokatlas.ai/v1/chat/completions', 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/chat/completions", {
  method: "POST",
  headers: {
    "Authorization": "Bearer " + process.env.API_KEY,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
  "model": "gpt-5",
  "messages": [
    {
      "role": "user",
      "content": [
        {
          "type": "text",
          "text": "What is in this image?"
        },
        {
          "type": "image_url",
          "image_url": {
            "url": "https://example.com/image.jpg"
          }
        }
      ]
    }
  ],
  "stream": false
}),
  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\",",
            "  \"messages\": [",
            "    {",
            "      \"role\": \"user\",",
            "      \"content\": [",
            "        {",
            "          \"type\": \"text\",",
            "          \"text\": \"What is in this image?\"",
            "        },",
            "        {",
            "          \"type\": \"image_url\",",
            "          \"image_url\": {",
            "            \"url\": \"https://example.com/image.jpg\"",
            "          }",
            "        }",
            "      ]",
            "    }",
            "  ],",
            "  \"stream\": false",
            "}"
        );
        HttpClient client = HttpClient.newBuilder()
            .connectTimeout(Duration.ofSeconds(30)).build();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.tokatlas.ai/v1/chat/completions"))
            .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());
    }
}

Response Example ​

json
{
  "code": 200,
  "data": {
    "id": "chatcmpl-B9MHDbslfkBeAs8l4bebGdFOJ6PeG",
    "object": "chat.completion",
    "created": 1741570283,
    "model": "gpt-5",
    "choices": [
      {
        "index": 0,
        "message": {
          "role": "assistant",
          "content": "The image shows a wooden boardwalk path running through a lush green field or meadow. The sky is bright blue with some scattered clouds.",
          "refusal": null
        },
        "finish_reason": "stop"
      }
    ],
    "usage": {
      "prompt_tokens": 1117,
      "completion_tokens": 46,
      "total_tokens": 1163,
      "prompt_tokens_details": {
        "image_tokens": 1100
      }
    }
  }
}