Token LabBuscar

← Todos los tutoriales
GUÍA PARA DESARROLLADORES / 04

Inspecciona un payload de IA: JSON, Base64, imágenes y audio

Sigue los campos anidados hasta los bytes decodificados y las vistas previas locales.

Distingue transporte y contenido

JSON describe la estructura. Base64 representa datos binarios como texto; no cifra ni comprime. Una URL de datos añade el tipo de medio y un prefijo como data:image/png;base64, antes del contenido.

Para n bytes, Base64 con relleno ocupa 4 × ceil(n / 3) caracteres. Un archivo de 3 MiB se convierte en 4 MiB antes de añadir JSON y prefijos. Eso mide el tamaño de la solicitud, no los tokens de medios facturados.

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.

Inspecciona una muestra válida

Carga el ejemplo con imagen y audio. Expande messages y content, compara tamaños y localiza la URL de imagen e input_audio.data. La muestra contiene un PNG generado y un tono WAV de medio segundo; solo suena al reproducirlo.

El inspector decodifica campos reconocidos, comprueba firmas y usa URL Blob locales para previsualizar formatos compatibles. El JSON ilustrativo contiene un marcador: usa el ejemplo integrado para obtener medios válidos. El tamaño del padre ya incluye sus hijos.

{
  "messages": [{
    "role": "user",
    "content": [
      {"type": "text", "text": "Describe this image."},
      {"type": "image_url", "image_url": {
        "url": "data:image/png;base64,<base64-data>"
      }}
    ]
  }]
}
Probar en la herramienta →

Depura discrepancias con seguridad

El MIME declarado puede no coincidir con los bytes. Decodificar Base64 tampoco demuestra que el archivo sea válido. Si falla la reproducción, comprueba el formato y el códec reales, no solo la etiqueta.

Las URL externas no se descargan automáticamente. No se ejecutan HTML, SVG ni archivos desconocidos. La vista previa depende del navegador y no valida el esquema de la API. Verifica los campos del proveedor y usa su consumo real para facturar.

Referencias e implementación

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