Image understanding
Send an image with a question using the image_url content part.
Use a model whose endpoint advertises vision. The OpenAI image part can carry a supported public image URL or an inline data URL; route restrictions still apply. Prefer PNG or JPEG for cross-route compatibility. Check the model's endpoint for the inputs it takes.
Run a request
Use Python 3 or Node 22, and export TOKENHUB_API_KEY from your secret store. Download the sample, or replace it with your own file of the same format. Each model request uses your account's paid allowance.
curl --fail "https://aihub.belive.sg/docs/examples/receipt.jpg" -o receipt.jpgpython3 - <<'PY' import base64, json from pathlib import Path encoded = base64.b64encode(Path("receipt.jpg").read_bytes()).decode("ascii") body = { "model": "qwen/qwen3.8-flash", "provider": {"only": ["alibaba-model-studio"]}, "max_tokens": 4000, "messages": [{"role": "user", "content": [ {"type": "text", "text": "Read this receipt and list the items."}, {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + encoded}}, ]}], } Path("request.json").write_text(json.dumps(body)) PY curl --fail-with-body "https://tokenhub-api.belive.sg/api/v1/chat/completions" \ -H "Authorization: Bearer $TOKENHUB_API_KEY" \ -H "Content-Type: application/json" \ --data-binary @request.json
import base64, json from pathlib import Path encoded = base64.b64encode(Path("receipt.jpg").read_bytes()).decode("ascii") body = { "model": "qwen/qwen3.8-flash", "provider": {"only": ["alibaba-model-studio"]}, "max_tokens": 4000, "messages": [{"role": "user", "content": [ {"type": "text", "text": "Read this receipt and list the items."}, {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + encoded}}, ]}], } import os, urllib.request request = urllib.request.Request( "https://tokenhub-api.belive.sg/api/v1/chat/completions", data=json.dumps(body).encode(), headers={"Authorization": "Bearer " + os.environ["TOKENHUB_API_KEY"], "Content-Type": "application/json"}, ) with urllib.request.urlopen(request, timeout=120) as response: result = json.load(response) print(result["choices"][0]["message"]["content"]) print(result.get("usage")) print(response.headers.get("X-Generation-Id"))
import { readFile } from "node:fs/promises"; const encoded = (await readFile("receipt.jpg")).toString("base64"); const apiKey = process.env.TOKENHUB_API_KEY; if (!apiKey) throw new Error("Set TOKENHUB_API_KEY"); const response = await fetch("https://tokenhub-api.belive.sg/api/v1/chat/completions", { method: "POST", headers: { Authorization: "Bearer " + apiKey, "Content-Type": "application/json" }, body: JSON.stringify({ model: "qwen/qwen3.8-flash", provider: { only: ["alibaba-model-studio"] }, max_tokens: 4000, messages: [{ role: "user", content: [ { type: "text", text: "Read this receipt and list the items." }, {"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + encoded}}, ] }], }), }); if (!response.ok) throw new Error("HTTP " + response.status + ": " + await response.text()); const result = await response.json(); console.log(result.choices[0].message.content, result.usage); console.log(response.headers.get("X-Generation-Id"));
The response is a normal Chat Completion: read the assistant content, reported usage and X-Generation-Id.
Uploaded images
An uploaded PNG/JPEG can be referenced through the object form image_url.url using tokenhub://files/<id>. The file must belong to the same workspace and remain uploaded and unexpired. Follow the upload workflow; this is not a generic PDF or audio attachment.
Choose a model and route
Read GET /api/v1/models in your environment. architecture.input_modalities describes a model, while each endpoint's capabilities identifies the serving route: vision for images, audio_input, video_input or file_input. Check the Models page for available routes. The examples pin a declared route; use a different eligible route only with its own supported request form.
Limits, cost and failures
Base64 increases the request size. The synchronous chat body limit defaults to 20 MiB, and provider format, duration, page and context limits also apply. Keep inline samples small; an uploaded video uses a different path described below. A model's context limit is not a universal media-size limit.
Media input can contribute input tokens or a modality-specific meter. Read the selected route's price table and the resulting usage; do not estimate solely from text length. Key caps and model restrictions still apply.
Malformed input can return 400, an oversized body 413, and an unsuitable route 400 or a routing refusal. See Errors before retrying; after a timeout, reconcile before resubmitting.
Support and limits
Each protocol has its own media block: URL and data inputs and uploaded file IDs have their own schemas and size limits, and a model's page lists its input modalities. PDFs, audio and video are refused on routes that do not take them.
Gateway validation, defaults and response forms are in the operation index and the OpenAPI schemas.
Error codes and recovery are in Errors and recovery. Keep the request or job ID from each response: it identifies the call in Activity and for support.