SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
1.1 KB · 22 lines python
Raw Blame History
1#!/usr/bin/env python32# STATUS: LIVE_VERIFIED — executed 2026-09-18 (exit 0 in 0.7s)3# Chat Completions image input: content part {"type":"image_url","image_url":{"url": <URL or data URL>, "detail": "low|high|auto"}}.4import pathlib5import sys67ROOT = pathlib.Path(__file__).resolve().parents[3]8sys.path.insert(0, str(ROOT))9from scripts import live  # noqa: E4021011from openai import OpenAI  # noqa: E4021213PNG_1X1 = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg=="14client = OpenAI()15completion = client.chat.completions.create(16    model="gpt-4.1-nano", max_completion_tokens=32,17    messages=[{"role": "user", "content": [{"type": "text", "text": "Reply with OK."}, {"type": "image_url", "image_url": {"url": PNG_1X1, "detail": "low"}}]}],18)19live.log_request("openai", "POST", "/v1/chat/completions", 200, 0.000002, "example chat/image_input.py")20print(completion.choices[0].message.content, completion.usage.prompt_tokens, "prompt tokens incl. image")21assert completion.choices[0].finish_reason in ("stop", "length")22