> ## 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.

# Image to Text

export const OpenAIApiResponse = ({successJson, successTitle = "200 - Success", streaming = false}) => {
  const error400 = `{
    "error": {
        "code": "invalid_params",
        "message": "parameter 'ARGUMENT' is required",
        "param": null,
        "type": "invalid_request_error"
    }
}`;
  const error401 = `{
    "error": {
        "code": "auth_invalid",
        "message": "Invalid API Key",
        "param": null,
        "type": "authentication_error"
    }
}`;
  const error402 = `{
    "error": {
        "code": "insufficient_quota",
        "message": "You exceeded your current quota, please check your plan and billing details.",
        "param": null,
        "type": "insufficient_quota_error"
    }
}`;
  const error403 = `{
    "error": {
        "code": "permission_error",
        "message": "You have no permission to access the model.",
        "type": "permission_error",
        "param": null
    }
}`;
  const error404 = `{
    "error": {
        "code": "invalid_request_error",
        "message": "Invalid URL",
        "param": null,
        "type": "invalid_request_error"
    }
}`;
  const error429 = `{
    "error": {
        "code": "rate_limit_exceeded",
        "message": "Rate limit reached",
        "param": null,
        "type": "rate_limit_error"
    }
}`;
  const error500 = `{
    "error": {
        "code": "server_error",
        "message": "Internal server error",
        "param": null,
        "type": "server_error"
    }
}`;
  return <>
      <h2>Response Examples</h2>

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

export const OpenAIImageToText = ({model = "gpt-4.1"}) => {
  const curlExample = `curl --request POST \\
  --url https://aiandgpu.com/v1/chat/completions \\
  --header 'Authorization: Bearer <YOUR_API_KEY>' \\
  --header 'Content-Type: application/json' \\
  --data '{
    "model": "${model}",
    "messages": [
      {
        "role": "user",
        "content": [
          {
            "type": "text",
            "text": "What is in this image?"
          },
          {
            "type": "image_url",
            "image_url": {
              "url": "https://robohash.org/OYK.png"
            }
          }
        ]
      }
    ],
    "max_tokens": 300
  }'`;
  const pythonExample = `import requests

url = "https://aiandgpu.com/v1/chat/completions"

payload = {
    "model": "${model}",
    "messages": [
        {
            "role": "user",
            "content": [
                {
                    "type": "text",
                    "text": "What is in this image?"
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://robohash.org/OYK.png"
                    }
                }
            ]
        }
    ],
    "max_tokens": 300
}

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/chat/completions', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <YOUR_API_KEY>',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    model: '${model}',
    messages: [
      {
        role: 'user',
        content: [
          {
            type: 'text',
            text: 'What is in this image?'
          },
          {
            type: 'image_url',
            image_url: {
              url: 'https://robohash.org/OYK.png'
            }
          }
        ]
      }
    ],
    max_tokens: 300
  })
});

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/chat/completions"

\tpayload := strings.NewReader(\`{
\t\t"model": "${model}",
\t\t"messages": [{"role": "user", "content": [{"type": "text", "text": "What is in this image?"}, {"type": "image_url", "image_url": {"url": "https://robohash.org/OYK.png"}}]}],
\t\t"max_tokens": 300
\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}",
  "messages": [
    {
      "role": "user",
      "content": [
        {"type": "text", "text": "What is in this image?"},
        {"type": "image_url", "image_url": {"url": "https://robohash.org/OYK.png"}}
      ]
    }
  ],
  "max_tokens": 300
}
""";

HttpRequest request = HttpRequest.newBuilder()
    .uri(URI.create("https://aiandgpu.com/v1/chat/completions"))
    .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}',
    'messages' => [
        [
            'role' => 'user',
            'content' => [
                ['type' => 'text', 'text' => 'What is in this image?'],
                ['type' => 'image_url', 'image_url' => ['url' => 'https://robohash.org/OYK.png']]
            ]
        ]
    ],
    'max_tokens' => 300
]);

curl_setopt_array($curl, [
    CURLOPT_URL => "https://aiandgpu.com/v1/chat/completions",
    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}"",
    ""messages"": [
        {
            ""role"": ""user"",
            ""content"": [
                {""type"": ""text"", ""text"": ""What is in this image?""},
                {""type"": ""image_url"", ""image_url"": {""url"": ""https://robohash.org/OYK.png""}}
            ]
        }
    ],
    ""max_tokens"": 300
}";

var request = new HttpRequestMessage(HttpMethod.Post, "https://aiandgpu.com/v1/chat/completions");
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>

<OpenAIImageToText model="gpt-5.4" />

<OpenAIApiResponse
  successJson={`{
    "id": "chatcmpl-DHn277SUYf3XHpo4m5jzujnOapJq7",
    "object": "chat.completion",
    "created": 1773132431,
    "model": "gpt-5.4",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "assistant",
                "content": "This image appears to be a cartoon drawing of a blue robot. The robot has a cylindrical head with a red button or light on top, a horizontal slit for a mouth, and a rectangular body with rounded shoulders. The style is whimsical and animated.",
                "refusal": null,
                "annotations": []
            },
            "logprobs": null,
            "finish_reason": "stop"
        }
    ],
    "usage": {
        "prompt_tokens": 268,
        "completion_tokens": 51,
        "total_tokens": 319,
        "prompt_tokens_details": {
            "cached_tokens": 0,
            "audio_tokens": 0
        },
        "completion_tokens_details": {
            "reasoning_tokens": 0,
            "audio_tokens": 0,
            "accepted_prediction_tokens": 0,
            "rejected_prediction_tokens": 0
        }
    },
    "system_fingerprint": "fp_7a7fd0eb44"
}`}
/>

## Parameters

### Core Parameters

| Field                             | Type                    | Required | Range                                                        | Description                                                                                                                                                              |
| :-------------------------------- | :---------------------- | :------- | :----------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `model`                           | `string`                | ✅        | -                                                            | Model ID used to generate the response.                                                                                                                                  |
| `messages`                        | `array<object>`         | ✅        | -                                                            | A list of messages comprising the conversation so far. Depending on the model you use, different message types (modalities) are supported, like text, images, and audio. |
| `>messages.role`                  | `enum`                  | ✅        | `user` <br /> `assistant` <br /> `system` <br /> `developer` | The role of the message sender. Can be `user` `model`.                                                                                                                   |
| `>messages.name`                  | `string`                | -        | -                                                            | An optional name for the participant. Provides the model information to differentiate between participants of the same role.                                             |
| `>messages.content`               | `string\|array<object>` | ✅        | -                                                            | The contents of the developer message.                                                                                                                                   |
| `>messages.content.type`          | `string`                | -        | `text` <br /> `image_url`                                    | The type of the content part.                                                                                                                                            |
| `>messages.content.text`          | `string`                | -        | -                                                            | The text content.                                                                                                                                                        |
| `>messages.content.image_url`     | `object`                | -        | -                                                            | The image URL content.                                                                                                                                                   |
| `>messages.content.image_url.url` | `string`                | -        | -                                                            | The URL of the image.                                                                                                                                                    |
| `max_tokens`                      | `integer`               | -        | -                                                            | An upper bound for the number of tokens that can be generated for a completion, including visible output tokens and reasoning tokens.                                    |
| `stream`                          | `boolean`               | -        | -                                                            | Whether to stream the response back incrementally. Defaults to false.                                                                                                    |
