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