Token LabSearch

← All tutorials
DEVELOPER GUIDE / 04

Inspect an AI payload: JSON, Base64, images, and audio

Trace a multimodal request from nested fields to decoded bytes and safe local media previews.

Separate transport from content

JSON is the request structure. Base64 is a way to represent binary data as text, not encryption or compression. A Data URL adds a media type and prefix, such as data:image/png;base64, before the encoded bytes.

For n binary bytes, padded Base64 uses 4 × ceil(n / 3) characters. A 3 MiB file becomes 4 MiB of Base64 before the JSON and prefix are added. This is request size, not the model’s media-token charge.

Study guide & lesson outlineLEARNING CONTRACT

Understand → implement → investigate

Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.

  • Understand: state assumptions, shapes/units and a counterexample.
  • Implement: reproduce a numerical example and inspect boundaries.
  • Investigate: compare one alternative under a matched budget.

Inspect a real working sample

Load the image + audio example. Expand the messages and content fields; compare their sizes, then find the image URL and input_audio.data. The example contains a generated PNG and a half-second WAV tone. Play it only when you choose.

The inspector decodes recognized fields, checks file signatures, and previews supported formats through local Blob URLs. The illustrative JSON below contains a placeholder, so use the built-in sample for valid media. Parent field sizes already include their children.

{
  "messages": [{
    "role": "user",
    "content": [
      {"type": "text", "text": "Describe this image."},
      {"type": "image_url", "image_url": {
        "url": "data:image/png;base64,<base64-data>"
      }}
    ]
  }]
}
Try it in the tool →

Debug mismatches safely

A declared MIME type can disagree with the bytes. A successful Base64 decode also does not prove the media file is valid. If playback fails, verify the file’s actual format and codec rather than repeatedly changing the declared type.

External URLs are not fetched automatically. HTML, SVG, and unknown files are not executed. Preview support depends on the browser; this tool is not an API schema validator. Confirm provider-specific field names and use the provider’s actual usage for billing.

References & implementation

MATHEMATICAL REVIEW · 2026-10-26

Assumptions, implementation & acceptance

Base64 length is 4 ceil(n/3): byte lengths 0,1,2,3 produce 0,4,4,4 characters. Parent JSON size already includes children; summing both double-counts. Bytes are not model tokens.

Shared code, English mathematical explanation and key multilingual numeric passages reviewed. This is not a full translation proofread.

Pasted request JSON → Identify data URL and media type → Decode Base64 → bytes → Preview locally · avoid double-counting
Mechanism map: follow the transformations from top to bottom.

Before running: predict a boundary case

Base64 length is 4 ceil(n/3): byte lengths 0,1,2,3 produce 0,4,4,4 characters. Parent JSON size already includes children; summing both double-counts. Bytes are not model tokens.

Hint: isolate the assumption

Keep the baseline input fixed, change one parameter or boundary, and compare both the numerical result and the claimed units. A passing example verifies this fixture only.

Minimal executable example

Save the example and linked modules in one folder. Use Node.js 22 or newer, then run node base64-ai-payload-inspector.mjs. No third-party runtime dependencies.

const lengths=[0,1,2,3].map(n=>Buffer.alloc(n).toString('base64').length);
console.log(lengths); // [0,4,4,4]
console.log(Buffer.alloc(3*2**20).toString('base64').length/2**20); // 4 MiB of ASCII

Test and transfer

Base64 length is 4 ceil(n/3): byte lengths 0,1,2,3 produce 0,4,4,4 characters. Parent JSON size already includes children; summing both double-counts. Bytes are not model tokens.

Record input, code version, expected result and observed result in the notebook below. Then construct a counterexample that violates the assumption above and explain why the original conclusion no longer follows.

Download complete kit (.tar.gz) · Complete reference kit and regression checks

Predict, test and keep evidence

Before revealing an answer, predict one result. After the exercise, record the discrepancy and a transfer test. Saved locally across language editions.

Open notebook / export / clear →

The mathematical review scope is recorded per lesson. It does not establish empirical paper reproduction; report suspected errors in your notes. Review scope