Token Lab검색

← 모든 튜토리얼
개발자 가이드 / 04

AI 페이로드 검사: JSON, Base64, 이미지와 오디오

중첩 필드에서 디코딩된 바이트와 안전한 로컬 미리보기까지 추적합니다.

전송 형식과 내용 구분

JSON은 요청 구조입니다. Base64는 바이너리를 텍스트로 표현하는 방법이며 암호화나 압축이 아닙니다. Data URL은 data:image/png;base64, 같은 미디어 유형과 접두사를 추가합니다.

n바이트의 패딩된 Base64는 4 × ceil(n / 3) 문자가 필요합니다. 3 MiB 파일은 JSON과 접두사를 제외해도 4 MiB가 됩니다. 이는 요청 크기이지 모델의 미디어 토큰 요금이 아닙니다.

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.

실행 가능한 예제 검사

이미지와 오디오 예제를 불러와 messages와 content를 펼치고 크기를 비교하세요. 이미지 URL과 input_audio.data를 찾을 수 있습니다. 예제에는 생성된 PNG와 0.5초 WAV 음이 들어 있으며 직접 재생해야 소리가 납니다.

인식된 필드를 디코딩하고 파일 시그니처를 확인한 뒤 로컬 Blob URL로 지원 형식을 표시합니다. 아래 JSON은 자리표시자가 포함된 구조 예제이므로 유효한 미디어는 내장 샘플을 사용하세요. 부모 크기에는 자식이 포함됩니다.

{
  "messages": [{
    "role": "user",
    "content": [
      {"type": "text", "text": "Describe this image."},
      {"type": "image_url", "image_url": {
        "url": "data:image/png;base64,<base64-data>"
      }}
    ]
  }]
}
도구에서 실행 →

불일치를 안전하게 디버깅

선언된 MIME과 실제 바이트가 다를 수 있습니다. Base64 디코딩 성공이 파일 유효성을 보장하지는 않습니다. 재생이 안 되면 선언된 유형만 바꾸지 말고 실제 형식과 코덱을 확인하세요.

외부 URL은 자동으로 가져오지 않으며 HTML, SVG, 알 수 없는 콘텐츠는 실행하지 않습니다. 미리보기는 브라우저 지원에 달려 있고 API 스키마 검증도 아닙니다. 공급자 필드 규격을 확인하고 실제 usage로 과금하세요.

참고 자료 및 구현

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