Protocol | Parameter Description | Detailed Parameter and Call Example Description |
OpenAI Chat Completions ( /v1/chat/completions) | Content block type=image_urlimage_url.url: Supports public network https://URL or a Base64 data URL.image_url.detail: Supports auto, low, high, and original. | |
OpenAI Responses ( /v1/responses) | Content block type=input_imageimage_url: Supports a public network https://URL or a Base64 data URL.detail: Supports auto, low, high, and original. | |
Anthropic ( /v1/messages) | Content block type=imagesource.type: Supports url and base64.source.url: Public network https://URL.source.media_type:image/jpeg,image/png,image/webp,image/gifsource.data: Pure Base64 encoding without the data: prefix. |
url field of image_url. In the Responses protocol, image data is placed in the image_url field of input_image. The key differences between the two methods are as follows:Writing back | URL Method | Base64 Method |
Scenario | The image is stored in a publicly accessible location, such as COS or CDN. | The image is stored locally or on a private network, or is temporarily generated by a program. |
Request body size | Extremely small (contains only the image URL) | Approximately 1.33 times the size of the original file. |
Public network accessibility requirement | Must be publicly accessible | No requirements |
Transmission time | Faster (only a short URL is sent), but TokenHub needs to download the image additionally, which is affected by the response speed of the image server. | Slower (the request body is approximately 1.33 times the size of the original image), but no external network access is required, making it suitable for private network/local environments. |
{"type": "image_url","image_url": {"url": "https://example.com/photo.jpg"}}
{"type": "input_image","image_url": "https://example.com/photo.jpg"}
{"type": "image","source": {"type": "url","url": "https://example.com/photo.jpg"}}
image_url.url in the format data:<mime>;base64,<encoded data>. Common image MIME types: image/jpeg, image/png, image/webp.{"type": "image_url","image_url": {"url": "data:image/jpeg;base64,<BASE64_DATA>"}}
{"type": "input_image","image_url": "data:image/jpeg;base64,<BASE64_DATA>"}
{"type": "image","source": {"type": "base64","media_type": "image/jpeg","data": "<BASE64_DATA>"}}
POST /v1/chat/completions) with the hy4 model. Images are passed in through the image_url type block in content, supporting both single-image and multi-image inputs.curl -X POST 'https://tokenhub-intl.tencentcloudmaas.com/v1/chat/completions' \\-H 'Authorization: Bearer YOUR_API_KEY' \\-H 'Content-Type: application/json' \\-d '{"model": "hy4","messages": [{"role": "user", "content": [{"type": "image_url", "image_url": {"url": "YOUR_IMAGE_URL"}},{"type": "text", "text": "Please describe the content of this image and state how many animals are in it."}]}],"stream": false}'
from openai import OpenAIclient = OpenAI(api_key="YOUR_API_KEY",base_url="https://tokenhub-intl.tencentcloudmaas.com/v1",)response = client.chat.completions.create(model="hy4",messages=[{"role": "user","content": [{"type": "image_url", "image_url": {"url": "YOUR_IMAGE_URL"}},{"type": "text", "text": "Please describe the content of this image and state how many animals are in it."},],}],)print(response.choices[0].message.content)
import base64from openai import OpenAIclient = OpenAI(api_key="YOUR_API_KEY",base_url="https://tokenhub-intl.tencentcloudmaas.com/v1",)# Replace example.jpg with the path to your local imagewith open("example.jpg", "rb") as f:base64_image = base64.b64encode(f.read()).decode("utf-8")response = client.chat.completions.create(model="hy4",messages=[{"role": "user","content": [{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{base64_image}"}},{"type": "text", "text": "Please describe the content of this image and state how many animals are in it."},],}],)print(response.choices[0].message.content)
{"id": "REPLACED_ID","object": "chat.completion","model": "hy4","created": 1787628534,"choices": [{"index": 0,"message": {"role": "assistant","content": "There are three orange kittens in this image, lying on the windowsill and basking in the sun, with a clear sky in the background."},"finish_reason": "stop"}],"usage": {"prompt_tokens": 1158,"completion_tokens": 36,"total_tokens": 1194}}
image_url blocks side by side in the content array. The maximum number of input images is constrained by the context window, with no hard limit on the number of images.curl -X POST 'https://tokenhub-intl.tencentcloudmaas.com/v1/chat/completions' \\-H 'Authorization: Bearer YOUR_API_KEY' \\-H 'Content-Type: application/json' \\-d '{"model": "hy4","messages": [{"role": "user", "content": [{"type": "image_url", "image_url": {"url": "YOUR_IMAGE_URL"}},{"type": "image_url", "image_url": {"url": "YOUR_IMAGE_URL_2"}},{"type": "text", "text": "Please describe the content of these two images separately"}]}],"stream": false}'
from openai import OpenAIclient = OpenAI(api_key="YOUR_API_KEY",base_url="https://tokenhub-intl.tencentcloudmaas.com/v1",)response = client.chat.completions.create(model="hy4",messages=[{"role": "user","content": [{"type": "image_url", "image_url": {"url": "YOUR_IMAGE_URL"}},{"type": "image_url", "image_url": {"url": "YOUR_IMAGE_URL_2"}},{"type": "text", "text": "Please describe the content of these two images separately"},],}],)print(response.choices[0].message.content)
import base64from openai import OpenAIclient = OpenAI(api_key="YOUR_API_KEY",base_url="https://tokenhub-intl.tencentcloudmaas.com/v1",)def load_b64(path):# Replace the path with your local imagewith open(path, "rb") as f:return base64.b64encode(f.read()).decode("utf-8")# Replace example_a.jpg / example_b.jpg with the paths to your local imagesimage_a = load_b64("example_a.jpg")image_b = load_b64("example_b.jpg")response = client.chat.completions.create(model="hy4",messages=[{"role": "user","content": [{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_a}"}},{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_b}"}},{"type": "text", "text": "Please describe the content of these two images separately"},],}],)print(response.choices[0].message.content)
{"id": "REPLACED_ID","object": "chat.completion","model": "hy4","created": 1787628932,"choices": [{"index": 0,"message": {"role": "assistant","content": "### Image 1\\n- Color: This image consists of two solid colors. The upper half is blue (a pure or vivid blue with high saturation and brightness), and the lower half is red (a pure or vivid red with high saturation and brightness).\\n- Composition: It uses a horizontal two-part composition (top-bottom split). The entire image is divided by a horizontal straight line (approximately at the vertical midpoint of the image) into two equal rectangular areas. The upper area is filled with blue, and the lower area is filled with red. The two color areas are roughly equal in size, creating a simple top-bottom color separation effect.\\n\\n\\n### Image 2\\n- Color: This image also consists of two solid colors. The left half is green (a vivid green or grass green with high saturation), and the right half is yellow (a bright yellow or lemon yellow with high saturation).\\n- Composition: It uses a vertical two-part composition (left-right split). The entire image is divided by a vertical straight line (approximately at the horizontal midpoint of the image) into two equal rectangular areas. The left area is filled with green, and the right area is filled with yellow. The two color areas are roughly equal in size, creating a simple left-right color separation effect.\\n"},"finish_reason": "stop"}],"usage": {"prompt_tokens": 569,"completion_tokens": 231,"total_tokens": 800}}
pip install openai.text and image_url in the content array is the order in which the model receives them.16000 ÷ 1058 ≈ 15 images16000 ÷ 602 ≈ 26 imagesTransfer Method | Recommended Size per Image | Request Body Size Limit |
URL method | Recommended not to exceed 10 MB | Not exceed 100 MB |
Base64 method | Recommended not to exceed 10 MB | Not exceed 100 MB (Base64 encoding increases the data size by about 1.33 times. In multi-image scenarios, pay attention to the accumulated size.). |
Apakah halaman ini membantu?
Anda juga dapat Menghubungi Penjualan atau Mengirimkan Tiket untuk meminta bantuan.
masukan