Python 88.3%
TypeScript 7.6%
Shell 4.1%
1#!/usr/bin/env python32# STATUS: LIVE_VERIFIED — executed 2026-09-19 (exit 0 in 3.0s)3# Image understanding via Chat Completions image_url (data URL). Images must have >= 512 pixels (8x8 -> 400 invalid_image).4import base64, os, pathlib, struct, sys, zlib5ROOT = pathlib.Path(__file__).resolve().parents[3]; sys.path.insert(0, str(ROOT))6from scripts import live # noqa: E4027from openai import OpenAI # noqa: E40289def png(w, h):10 raw = b"".join(b"\x00" + b"\xff\xff\xff" * w for _ in range(h))11 def chunk(t, d): return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xFFFFFFFF)12 return b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", w, h, 8, 2, 0, 0, 0)) + chunk(b"IDAT", zlib.compress(raw)) + chunk(b"IEND", b"")13url = "data:image/png;base64," + base64.b64encode(png(32, 32)).decode()14client = OpenAI(api_key=os.environ["XAI_API_KEY"], base_url="https://api.x.ai/v1")15c = client.chat.completions.create(model="grok-4.3", max_completion_tokens=32, messages=[{"role": "user", "content": [{"type": "image_url", "image_url": {"url": url, "detail": "low"}}, {"type": "text", "text": "Reply with OK."}]}])16live.log_request("xai", "POST", "/v1/chat/completions", 200, 0.0006, "example xai/chat/image_input.py")17print(c.choices[0].message.content, "image_tokens:", c.usage.prompt_tokens_details.model_extra.get("image_tokens") if c.usage.prompt_tokens_details.model_extra else c.usage.prompt_tokens_details)18