Mga image at file
Magpadala ng mga image kasama ng message: aling mga model ang tumatanggap, ang mga tinatanggap na anyo at ang mga limitasyon.
POST https://api.shannon-ai.com/v1/chat/completions
Naglalakbay ang image sa loob ng user message, bilang isang bahagi ng content nito. Binabasa ng sample ang isang lokal na file at ipinapadala ito bilang data URL.
import base64
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.shannon-ai.com/v1")
with open("photo.jpg", "rb") as f:
image = base64.b64encode(f.read()).decode()
response = client.chat.completions.create(
model="shannon-3",
messages=[{
"role": "user",
"content": [
{"type": "text", "text": "What is in this picture?"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + image}},
],
}],
)
print(response.choices[0].message.content) import fs from "node:fs";
import OpenAI from "openai";
const client = new OpenAI({ apiKey: "YOUR_API_KEY", baseURL: "https://api.shannon-ai.com/v1" });
const image = fs.readFileSync("photo.jpg").toString("base64");
const response = await client.chat.completions.create({
model: "shannon-3",
messages: [{
role: "user",
content: [
{ type: "text", text: "What is in this picture?" },
{ type: "image_url", image_url: { url: "data:image/jpeg;base64," + image } },
],
}],
});
console.log(response.choices[0].message.content); # Linux: base64 -w0 photo.jpg macOS: base64 -i photo.jpg
IMAGE=$(base64 -w0 photo.jpg)
curl https://api.shannon-ai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d @- <<EOF
{
"model": "shannon-3",
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is in this picture?"},
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,${IMAGE}"}}
]
}]
}
EOF {
"id": "chatcmpl-8d1f3a5c7e9b4d2f6a8c0e2b4d6f8a1c",
"object": "chat.completion",
"created": 1791590400,
"model": "shannon-3",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "A grey cat asleep on a windowsill, with a potted fern beside it.",
"reasoning_content": null
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 286,
"completion_tokens": 19,
"total_tokens": 305
}
} Aling mga model ang tumatanggap ng image
| Mga model | Binabasa |
|---|---|
shannon-3, shannon-3-pro, shannon-3.1, shannon-3.1-pro | Mga image, at mga dokumento: PDF, Word, PowerPoint, Excel at plain-text file. |
shannon-1.6-lite, shannon-1.6-pro | Mga image. |
shannon-2-lite, shannon-2-pro | Mga image, sa mga request na nagpapadala rin ng tools o response_format. |
Kimi-K3-3BIT-REAP, MiniMax-M3-3BIT-REAP, Kimi-K2.6-W4A16-AUTOROUND-REAP, inkling-W4A16-AUTOROUND-REAP, MiMo-V2.5-W8A16 | Mga image. |
DeepSeek-V4-Pro-0813-3BIT-REAP, GLM-5.2-3BIT-REAP, Nemotron3Ultra-3BIT-REAP, DeepSeek-V4-Flash-0731-W4A16-AUTOROUND-REAP, Laguna-S-2.1-W4A16-AUTOROUND-REAP, MiMo-V2.5-Pro-W8A16, Hy3-W8A16 | Text. Ang request na may image ay sinasagot ng status na 400. |
shannon-coder-1 | Text. |
Iniuulat ng GET /v1/models ang image input kada id bilang capabilities.vision. Mga model at presyo
- Binabasa ng mga Shannon model ang mga file ng huling user message. Ilagay ang image sa message na nagtatanong tungkol dito.
- Pinananatili rin ng pamilyang Shannon 3 sa tanaw ang ilang image at dokumento ng mga naunang user message kapag ipinadala ang mga ito inline, at nagbabasa ng itinakdang pinakamataas na bilang ng image kada request, na binibilang mula sa una.
- Binabasa ng mga hosted open-weight model ang mga image ng bawat message ng conversation.
Mga tinatanggap na anyo
Ipinapadala ang file sa isa sa dalawang paraan: sa loob ng request bilang base64, o bilang address na kinukuha ng API. Kasama ng request naglalakbay ang bawat file; walang upload endpoint ang API.
| Endpoint | Sa loob ng request (base64) | Sa pamamagitan ng address |
|---|---|---|
/v1/chat/completions | {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64,…"}} | {"type": "image_url", "image_url": {"url": "https://…"}} |
/v1/responses | {"type": "input_image", "image_url": "data:image/jpeg;base64,…"} | {"type": "input_image", "image_url": "https://…"} |
/v1/messages | {"type": "image", "source": {"type": "base64", "media_type": "image/jpeg", "data": "…"}} | {"type": "image", "source": {"type": "url", "url": "https://…"}} |
Ang parehong user message sa bawat format:
{
"role": "user",
"content": [
{"type": "text", "text": "What is in this picture?"},
{
"type": "image_url",
"image_url": {
"url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD…"
}
}
]
} {
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this picture?"},
{
"type": "input_image",
"image_url": "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD…"
}
]
} {
"role": "user",
"content": [
{"type": "text", "text": "What is in this picture?"},
{
"type": "image",
"source": {
"type": "base64",
"media_type": "image/jpeg",
"data": "/9j/4AAQSkZJRgABAQAAAQABAAD…"
}
}
]
} - Ang data URL ay may anyong
data:<media type>;base64,<data>. Kinakailangan ang bahaging;base64. - Sa
/v1/chat/completionsat/v1/responses, angimage_urlay maaaring mismong string o object na{"url": "…"}. - Ang uri ng file ay mula sa data URL o sa
media_type. Kung wala, binabasa ang image bilangimage/png. - Kasama sa laki ng request body ang mga inline file, na maaaring umabot sa 32 MiB.
- Tinatanggap para sa compatibility:
image_url.detail.
Mga limitasyon para sa mga remote file
Kapag nagpadala ka ng address, kinukuha ng API ang file bago tumakbo ang model, sa loob ng mga limitasyong ito:
| Limitasyon | Patakaran |
|---|---|
| Laki | Hanggang 8 MiB kada file. |
| Oras | 20 segundo para sumagot. |
| Mga redirect | Hanggang 5 lamang. |
| Address | http:// o https://, na walang user name o password sa address, sa host na may pampublikong address. |
| Reply ng host | Isang status sa saklaw na 200 at body na hindi walang laman. Ang uri ng file ay binabasa mula sa Content-Type. |
| Hinihingi bilang | User-Agent: ShannonBot/1.0 (+https://shannon-ai.com) |
Paano binibilang sa tokens ang mga image
Sa mga hosted open-weight model, ang image ay binibilang na isang token kada 28 × 28 pixel patch: ang lapad na hinati sa 28, itinataas sa susunod na buong numero, beses ang taas na hinati sa 28, itinataas sa susunod na buong numero. Bahagi ng usage.prompt_tokens ang resulta at sinisingil ito bilang input.
- 1024 × 1024
- 1,369 tokens
- 1920 × 1080
- 2,691 tokens
- 512 × 512
- 361 tokens
- Kinukuha muna ang remote image, kaya binibilang ang tunay na laki nito.
- Ang image na hindi mabasa ang laki ay binibilang na 1,024 token.
- Parehong patakaran ang ginagamit ng mga counting endpoint para sa mga data URL. Hindi nila kinukuha ang remote address at binibilang ito bilang 1,024 token. Pagbibilang ng token
- Para sa Shannon model, basahin sa
usageng reply kung magkano ang naging halaga ng request na may mga image.
Mga dokumento at iba pang file
Nagbabasa rin ng mga dokumento ang pamilyang Shannon 3 (shannon-3, shannon-3-pro, shannon-3.1, shannon-3.1-pro). Kinukuha ang text ng dokumento at ibinibigay sa model kasama ng iyong message.
| Dokumento | Media type |
|---|---|
application/pdf | |
| Word | application/vnd.openxmlformats-officedocument.wordprocessingml.document |
| PowerPoint | application/vnd.openxmlformats-officedocument.presentationml.presentation |
| Excel | application/vnd.openxmlformats-officedocument.spreadsheetml.sheet |
Ang dokumento ay bahagi ng user message, tulad ng image:
| Endpoint | Sa loob ng request (base64) | Sa pamamagitan ng address |
|---|---|---|
/v1/chat/completions, /v1/messages | {"type": "document", "source": {"type": "base64", "media_type": "application/pdf", "data": "…"}} | {"type": "document", "source": {"type": "url", "url": "https://…"}} |
/v1/responses | {"type": "input_file", "file_data": "data:application/pdf;base64,…"} | {"type": "input_file", "file_url": "https://…"} |
{
"model": "shannon-3",
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": "JVBERi0xLjcKJeLjz9MK…"
}
},
{"type": "text", "text": "Summarise this report in five points."}
]
}
]
} {
"model": "shannon-3",
"input": [
{
"role": "user",
"content": [
{
"type": "input_file",
"file_data": "data:application/pdf;base64,JVBERi0xLjcKJeLjz9MK…"
},
{
"type": "input_text",
"text": "Summarise this report in five points."
}
]
}
]
} {
"model": "shannon-3",
"messages": [
{
"role": "user",
"content": [
{
"type": "document",
"source": {
"type": "base64",
"media_type": "application/pdf",
"data": "JVBERi0xLjcKJeLjz9MK…"
}
},
{"type": "text", "text": "Summarise this report in five points."}
]
}
]
} - Ibigay ang tunay na media type ng file. Kung wala, binabasa ang dokumento bilang
application/pdf. - Ang plain-text file, gaya ng CSV, ay binabasa bilang text at ikinakabit sa parehong paraan.
- Kapag hindi mabasa ang dokumento, o ibang uri ang file, sinasabihan ang model at maaari nitong sabihin sa sagot nito.
200pa rin ang status. - Sa bawat ibang model, inaalis ang document part sa binabasa ng model, at sinasagot ang request mula sa natitira.
- Ang dokumentong ipinadala sa pamamagitan ng address ay kinukuha sa ilalim ng mga limitasyon para sa mga remote file sa itaas.
Mga error
| Status | Type | Mensahe | Kailan |
|---|---|---|---|
400 | invalid_request_error | <id> does not accept image input | Nagpadala ng image sa isang hosted open-weight model na text lang ang tinatanggap. Walang kinukuha mula sa iyong balance. |
400 | invalid_request_error | audio and video input are not supported by any hosted model | Nagpadala ng audio o video part sa isang hosted open-weight model. |
413 | invalid_request_error | Failed to buffer the request body: … | Mas malaki sa 32 MiB ang request body, kasama ang mga inline file nito. Dala ng error ang code: "request_too_large". |
Sumasagot ang Shannon model ng status na 200 anuman ang mga file na dala ng request: inaalis ang part na hindi nito binabasa. Paghawak ng Error