> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aiandgpu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# File Analysis

export const ClaudeChatResponse = ({successJson, title = "Sync Chat Response", streaming = false, groupId = ""}) => {
  const prefix = groupId ? `[${groupId}] ` : "";
  const error400 = `{
    "type": "error",
    "error": {
      "type": "invalid_request_error",
      "message": "parameter 'ARGUMENT' is required"
    }
  }`;
  const error401 = `{
    "type": "error",
    "error": {
      "type": "authentication_error",
      "message": "Invalid API Key"
    }
  }`;
  const error402 = `{
    "type": "error",
    "error": {
      "type": "insufficient_balance",
      "message": "Insufficient balance"
    }
  }`;
  const error403 = `{
    "type": "error",
    "error": {
      "type": "quota_exceeded",
      "message": "Quota exceeded"
    }
  }`;
  const error404 = `{
    "type": "error",
    "error": {
      "type": "invalid_request_error",
      "message": "Invalid URL"
    }
  }`;
  const error429 = `{
    "type": "error",
    "error": {
      "type": "rate_limit_error",
      "message": "Too many requests"
    }
  }`;
  const error500 = `{
    "type": "error",
    "error": {
      "type": "internal_server_error",
      "message": "Internal server error"
    }
  }`;
  return <>
      <h3>{title}</h3>

      <CodeGroup>
        <CodeBlock language={streaming ? "text" : "json"} filename={streaming ? `${prefix}200 - Success (SSE)` : `${prefix}200 - Success`}>
          {successJson}
        </CodeBlock>
        <CodeBlock language="json" filename={`${prefix}400 - Bad Request`}>
          {error400}
        </CodeBlock>
        <CodeBlock language="json" filename={`${prefix}401 - Unauthorized`}>
          {error401}
        </CodeBlock>
        <CodeBlock language="json" filename={`${prefix}402 - Insufficient Balance`}>
          {error402}
        </CodeBlock>
        <CodeBlock language="json" filename={`${prefix}403 - Quota Exceeded`}>
          {error403}
        </CodeBlock>
        <CodeBlock language="json" filename={`${prefix}404 - Invalid URL`}>
          {error404}
        </CodeBlock>
        <CodeBlock language="json" filename={`${prefix}429 - Too Many Requests`}>
          {error429}
        </CodeBlock>
        <CodeBlock language="json" filename={`${prefix}500 - Internal Server Error`}>
          {error500}
        </CodeBlock>
      </CodeGroup>
    </>;
};

export const ClaudeFileAnalysis = ({model = "claude-haiku-4-5-20251001"}) => {
  const curlExample = `curl --request POST \\
  --url https://aiandgpu.com/v1/messages \\
  --header 'Authorization: Bearer <YOUR_API_KEY>' \\
  --header 'Content-Type: application/json' \\
  --data '{
    "model": "${model}",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Summarize the key points of this document."
                },
                {
                    "type": "document",
                    "source": {
                        "type": "url",
                        "url": "https://pdfobject.com/pdf/sample.pdf"
                    }
                }
            ]
        }
    ]
}'`;
  const pythonExample = `import requests

url = "https://aiandgpu.com/v1/messages"

payload = {
    "model": "${model}",
    "max_tokens": 1024,
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "Summarize the key points of this document."
                },
                {
                    "type": "document",
                    "source": {
                        "type": "url",
                        "url": "https://pdfobject.com/pdf/sample.pdf"
                    }
                }
            ]
        }
    ]
}

headers = {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())`;
  const jsExample = `const response = await fetch('https://aiandgpu.com/v1/messages', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <YOUR_API_KEY>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: '${model}',
    max_tokens: 1024,
    messages: [
      {
        role: 'user',
        content: [
          {
            type: 'text',
            text: 'Summarize the key points of this document.'
          },
          {
            type: 'document',
            source: {
              type: 'url',
              url: 'https://pdfobject.com/pdf/sample.pdf'
            }
          }
        ]
      }
    ]
  })
});

const data = await response.json();
console.log(data);`;
  const goExample = `package main

import (
\t"fmt"
\t"io"
\t"net/http"
\t"strings"
)

func main() {
\turl := "https://aiandgpu.com/v1/messages"

\tpayload := strings.NewReader(\`{
\t\t"model": "${model}",
\t\t"max_tokens": 1024,
\t\t"messages": [
\t\t\t{
\t\t\t\t"role": "user",
\t\t\t\t"content": [
\t\t\t\t\t{"type": "text", "text": "Summarize the key points of this document."},
\t\t\t\t\t{"type": "document", "source": {"type": "url", "url": "https://pdfobject.com/pdf/sample.pdf"}}
\t\t\t\t]
\t\t\t}
\t\t]
\t}\`)

\treq, _ := http.NewRequest("POST", url, payload)

\treq.Header.Add("Authorization", "Bearer <YOUR_API_KEY>")
\treq.Header.Add("Content-Type", "application/json")

\tres, _ := http.DefaultClient.Do(req)
\tdefer res.Body.Close()

\tbody, _ := io.ReadAll(res.Body)
\tfmt.Println(string(body))
}`;
  const javaExample = `import java.net.http.*;
import java.net.URI;

HttpClient client = HttpClient.newHttpClient();

String body = """
{
  "model": "${model}",
  "max_tokens": 1024,
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "Summarize the key points of this document."},
        {"type": "document", "source": {"type": "url", "url": "https://pdfobject.com/pdf/sample.pdf"}}
      ]
    }
  ]
}
""";

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://aiandgpu.com/v1/messages"))
    .header("Authorization", "Bearer <YOUR_API_KEY>")
    .header("Content-Type", "application/json")
    .POST(HttpRequest.BodyPublishers.ofString(body))
    .build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());`;
  const phpExample = `<?php

$curl = curl_init();

$payload = json_encode([
    'model' => '${model}',
    'max_tokens' => 1024,
    'messages' => [
        [
            'role' => 'user',
            'content' => [
                ['type' => 'text', 'text' => 'Summarize the key points of this document.'],
                [
                    'type' => 'document',
                    'source' => [
                        'type' => 'url',
                        'url' => 'https://pdfobject.com/pdf/sample.pdf'
                    ]
                ]
            ]
        ]
    ]
]);

curl_setopt_array($curl, [
    CURLOPT_URL => "https://aiandgpu.com/v1/messages",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => $payload,
    CURLOPT_HTTPHEADER => [
        "Authorization: Bearer <YOUR_API_KEY>",
        "Content-Type: application/json",
    ],
]);

$response = curl_exec($curl);
curl_close($curl);

echo $response;`;
  const csharpExample = `using System.Net.Http;
using System.Text;

var client = new HttpClient();

var payload = @"{
    ""model"": ""${model}"",
    ""max_tokens"": 1024,
    ""messages"": [
        {
            ""role"": ""user"",
            ""content"": [
                {""type"": ""text"", ""text"": ""Summarize the key points of this document.""},
                {
                    ""type"": ""document"",
                    ""source"": {
                        ""type"": ""url"",
                        ""url"": ""https://pdfobject.com/pdf/sample.pdf""
                    }
                }
            ]
        }
    ]
}";

var request = new HttpRequestMessage(HttpMethod.Post, "https://aiandgpu.com/v1/messages");
request.Headers.Add("Authorization", "Bearer <YOUR_API_KEY>");
request.Content = new StringContent(payload, Encoding.UTF8, "application/json");

var response = await client.SendAsync(request);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);`;
  return <>
      <h2>Request Examples</h2>

      <CodeGroup>
        <CodeBlock language="shellscript" filename="cURL">{curlExample}</CodeBlock>
        <CodeBlock language="python" filename="Python">{pythonExample}</CodeBlock>
        <CodeBlock language="javascript" filename="JavaScript">{jsExample}</CodeBlock>
        <CodeBlock language="go" filename="Go">{goExample}</CodeBlock>
        <CodeBlock language="java" filename="Java">{javaExample}</CodeBlock>
        <CodeBlock language="php" filename="PHP">{phpExample}</CodeBlock>
        <CodeBlock language="csharp" filename="C#">{csharpExample}</CodeBlock>
      </CodeGroup>
    </>;
};

## Authorization

* **Auth Type**: `Bearer Auth` (In: `header`)
* **Format**: `Authorization: Bearer <YOUR_API_KEY>`
* **Description**: Use `Bearer <YOUR_API_KEY>`. Format: `Authorization: Bearer sk-xxxxxx.`
* **API Key**: where <strong>API Key</strong> is your <a href="https://developer.aiandgpu.com" target="_blank" rel="noopener noreferrer">AGCloud API KEY</a>

<ClaudeFileAnalysis model="claude-sonnet-4-5-20250929-thinking" />

## Response Examples

<Expandable title="Sync Response Examples">
  <ClaudeChatResponse
    title=""
    successJson={`{
        "model": "claude-sonnet-4-5-20250929-thinking",
        "id": "msg_bdrk_01P8K5kQ7ZExgFzHmfc3Uj9b",
        "type": "message",
        "role": "assistant",
        "content": [
            {
                "type": "text",
                "text": "This image shows a cartoon-style robot or character with a pink/magenta color scheme. "
            }
        ],
        "stop_reason": "end_turn",
        "stop_sequence": null,
        "usage": {
            "input_tokens": 138,
            "cache_creation_input_tokens": 0,
            "cache_read_input_tokens": 0,
            "cache_creation": {
                "ephemeral_5m_input_tokens": 0,
                "ephemeral_1h_input_tokens": 0
            },
            "output_tokens": 146
        }
}`}
    groupId="sync"
  />
</Expandable>

<Expandable title="Sync Response Examples">
  <ClaudeChatResponse
    title=""
    successJson={`{
  "id": "9efa51cc-192e-458c-b6e2-65bac48917b2",
  "object": "task",
  "status": "pending",
  "created_at": 1773209182
}`}
    groupId="sync"
  />
</Expandable>

<Expandable title="Streaming Response Examples">
  <ClaudeChatResponse
    title=""
    successJson={`
event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"text","text":""}          }

event: ping
data: {"type": "ping"}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"你"}            }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"好！"}              }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"👋 "} }

...
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"有"} }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"什么我可以帮助"}               }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"你的吗？"} }

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"😊"}        }

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null},"usage":{"input_tokens":13,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":169}        }

event: message_stop
data: {"type":"message_stop"}
`}
    streaming
    groupId="stream"
  />
</Expandable>

### Async Chat Response Field Description

| Field        | Type     | Range                                                          | Description                                                               |
| :----------- | :------- | :------------------------------------------------------------- | :------------------------------------------------------------------------ |
| `id`         | `string` | -                                                              | The current chat task id.                                                 |
| `object`     | `string` | -                                                              | The type of object returned by the API. In this case it is always `task`. |
| `status`     | `string` | `pending` <br /> `processing` <br /> `success` <br /> `failed` | Current status of the task.                                               |
| `created_at` | `number` | -                                                              | Unix timestamp (in seconds) indicating when the task was created.         |

## Parameters

| Field            | Type                      | Required | Default | Description                                                                                                                                      |
| :--------------- | :------------------------ | :------- | :------ | :----------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`          | `string`                  | ✅        | -       | The model ID to use for this request.                                                                                                            |
| `messages`       | `array<object>`           | ✅        | -       | An array of message objects representing the conversation history. See [Messages Structure](#messages-array-structure).                          |
| `max_tokens`     | `integer`                 | ✅        | `4096`  | The maximum number of tokens the model can generate in the response. Range `1-32000`                                                             |
| `async`          | `boolean`                 | -        | `false` | Whether to return an asynchronous response. Only supported for non-streaming requests.                                                           |
| `stream`         | `boolean`                 | -        | `false` | If `true`, returns a stream of server-sent events (SSE) as the response is generated.                                                            |
| `system`         | `string \| array<object>` | -        | -       | System prompt that sets the behavior and context for the assistant.                                                                              |
| `temperature`    | `number`                  | -        | `1.0`   | Controls the randomness of the output. Lower values produce more focused responses, higher values produce more creative outputs. Range `0.0-1.0` |
| `top_p`          | `number`                  | -        | `1.0`   | Nucleus sampling parameter. The model considers tokens with top\_p cumulative probability mass. Range `0.0-1.0`                                  |
| `top_k`          | `integer`                 | -        | -       | Limits token selection to the K most probable tokens at each step.                                                                               |
| `stop_sequences` | `array<string>`           | -        | -       | An array of strings that will stop generation when encountered.                                                                                  |

<Warning>
  If both `stream` and `async` are true, `stream` takes precedence.
</Warning>

### Messages Array Structure

| Field                         | Type                        | Required                  | Description                                                                                                                                                 |
| :---------------------------- | :-------------------------- | :------------------------ | :---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `role`                        | `string`                    | ✅                         | The role of the message. Can be: `user` or `assistant`                                                                                                      |
| `content`                     | `string` \| `array<object>` | ✅                         | The content of the message. Can be a simple string for text-only messages, or an array of content blocks for multimodal content.                            |
| `>content.type`               | `string`                    | ✅                         | The type of the content block. Detail see [Content.Type](#content-type-description)                                                                         |
| `>content.text`               | `string`                    | ✅ if `type=text`          | The text content of the message.                                                                                                                            |
| `>content.source`             | `object`                    | ✅ if `type` not `text`    | The source of the document or image. see [Multimodal input](#multimodal-input)                                                                              |
| `>>content.source.type`       | `string`                    | ✅                         | The source type. Supported values: `base64`, `url`                                                                                                          |
| `>>content.source.media_type` | `string`                    | ✅ if `source.type=base64` | MIME type of the file. Supported values: `application/pdf`, `text/plain`, `text/markdown`, `text/csv`, `image/png`, `image/jpeg`, `image/gif`, `image/webp` |
| `>>content.source.data`       | `string`                    | ✅ if `source.type=base64` | The base64-encoded file data.                                                                                                                               |
| `>>content.source.url`        | `string`                    | ✅ if `source.type=url`    | The URL of the file to analyze.                                                                                                                             |

### Multimodal input

<CodeGroup>
  ```json Image with URL theme={null}
  {
      "model": "claude-haiku-4-5-20251001",
      "max_tokens": 1024,
      "messages": [
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "What is shown in this image?"
                  },
                  {
                      "type": "image",
                      "source": {
                          "type": "url",
                          "url": "https://robohash.org/13.png"
                      }
                  }
              ]
          }
      ]
  } 
  ```

  ```json PDF with URL theme={null}
  {
      "model": "claude-haiku-4-5-20251001",
      "max_tokens": 1024,
      "messages": [
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "Extract key information from pdf file."
                  },
                  {
                      "type": "document",
                      "source": {
                          "type": "url",
                          "url": "https://pdfobject.com/pdf/sample.pdf"
                      }
                  }
              ]
          }
      ]
  }
  ```

  ```json Base64 Image theme={null}
  {
      "model": "claude-haiku-4-5-20251001",
      "max_tokens": 1024,
      "messages": [
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "What is shown in this image?"
                  },
                  {
                      "type": "image",
                      "source": {
                          "type": "base64",
                          "media_type": "image/png",
                          "data": "base64_encoded_image_data"
                      }
                  }
              ]
          }
      ]
  } 
  ```

  ```json Base64 PDF theme={null}
  {
      "model": "claude-haiku-4-5-20251001",
      "max_tokens": 1024,
      "messages": [
          {
              "role": "user",
              "content": [
                  {
                      "type": "text",
                      "text": "Extract key words from this pdf fle."
                  },
                  {
                      "type": "document",
                      "source": {
                          "type": "base64",
                          "media_type": "application/pdf",
                          "data": "base64_encoded_pdf_data"
                      }
                  }
              ]
          }
      ]
  } 
  ```
</CodeGroup>

### Content Type Description

| Field       | Description                                                                                                                                     |
| :---------- | :---------------------------------------------------------------------------------------------------------------------------------------------- |
| `text`      | Plain text content for the user message or assistant response. Use with the `text` field.                                                       |
| `image`     | Image content provided via `source`. Supports base64-encoded data or a URL.                                                                     |
| `document`  | Document file provided via `source`. Use for processing PDF, plain text, Markdown, or CSV files. Supports base64-encoded data or a URL.         |
| `file`      | General file content provided via `source`. Automatically determines handling based on the `media_type`. Supports base64-encoded data or a URL. |
| `file_data` | Inline file data using base64 encoding. Provide the file content directly via `data` and `media_type` fields without a `source` wrapper.        |
