API REFERENCE
Images and PDFs
Send inline images and PDFs to compatible models through Chat Completions or Responses.
Choose a compatible model
Model pages list the input types accepted by Tokely. Images use base64 data URLs with image/png, image/jpeg or image/webp. Files use application/pdf. GPT-5.4 Mini supports both examples below.
Use user messages for images and PDFs. Each decoded file can be up to 10 MB; the entire JSON request, including base64 encoding, must fit within 16 MB. A request can include up to 20 images and 4 PDFs. Remote URLs, uploaded file IDs, audio and video input are not supported.
Input and output tokens are charged at the model’s listed rates. Image and PDF processing can consume more tokens than the text in your prompt. Requests require a funded balance.
Read an image
Encode a local image and send it as an image_url content part.
import os, base64
from openai import OpenAI
client = OpenAI(api_key=os.environ["TOKELY_API_KEY"], base_url="https://api.tokely.me/v1")
with open("image.png", "rb") as file:
image = "data:image/png;base64," + base64.b64encode(file.read()).decode()
response = client.chat.completions.create(
model="gpt-5.4-mini", max_tokens=1024,
messages=[{"role":"user","content":[
{"type":"text","text":"Describe this image."},
{"type":"image_url","image_url":{"url":image,"detail":"low"}}
]}]
)
print(response.choices[0].message.content)Read a PDF
Responses uses input_file with filename and file_data. Chat Completions uses a file part containing the same filename and file_data fields.
import os, base64
from openai import OpenAI
client = OpenAI(api_key=os.environ["TOKELY_API_KEY"], base_url="https://api.tokely.me/v1")
with open("invoice.pdf", "rb") as file:
pdf = "data:application/pdf;base64," + base64.b64encode(file.read()).decode()
response = client.responses.create(
model="gpt-5.4-mini", max_output_tokens=1024, store=False,
input=[{"role":"user","content":[
{"type":"input_text","text":"What is the invoice total?"},
{"type":"input_file","filename":"invoice.pdf","file_data":pdf}
]}]
)
print(response.output_text)