GeminiContextPack

Gemini API context optimizer using native PDF packaging — reduce reported input tokens by up to 99% in measured long-context workloads.

Overview

Offline, deterministic context packaging for Gemini. Compile any text into a verified PDF artifact (gemini-context-pack-v1 canonicalization), send it as a single inlineData: application/pdf part, and compare reported input tokens without hosted services or API keys at build time.

  • TypeScript ESM, node >=18, bun >=1
  • Bundled OFL fonts (no runtime CDN)
  • Verifiable: SHA-256 over canonical source, independent pdfjs-dist extraction

README (English) — README (한국어) — Architecture (A–J) — Validation Methodology — Responsible Use — Accounting and Claims

Install — GitHub Release tarball (no registry)

gh release download v0.1.0 --repo ianlyoo/GeminiContextPack --pattern "gemini-context-pack-*.tgz"
npm install ./gemini-context-pack-0.1.0.tgz

Alternative: npm pack then npm install ./gemini-context-pack-0.1.0.tgz

git clone https://github.com/ianlyoo/GeminiContextPack.git
cd GeminiContextPack
bun install --frozen-lockfile
bun run build
echo "hello world — deterministic example" > input.txt
node ./dist/cli.js compile --input input.txt --output out.pdf
node ./dist/cli.js inspect --pdf out.pdf
node ./dist/cli.js verify --pdf out.pdf --source input.txt

Benchmark: reported input tokens in measured workloads

Qualified evidence only. See evidence/results.json and evidence/manifest.json for traceability. No cost or invoice claim is made.

TargetPlain prompt_token_countPDF prompt_token_countPDF details (TEXT+IMAGE)Ratio PDF/PlainReduction
50005419402136 + 2660.0740.926
2000020704402136 + 2660.0190.981
5000051393402136 + 2660.0080.992

Limitations adjacent to benchmark (must be read with every number): Synthetic corpus, seed 42 deterministic lorem-style text with payload (not natural language); one run per condition (no statistical distribution); model gemini-2.5-flash primary with MEDIA_RESOLUTION_LOW (MEDIUM/HIGH variants exist as 532/1092 image tokens in raw); provider-reported input tokens only (usage.prompt_token_count); cache/wrapper/retrieval differ between plain and PDF (see raw evidence/raw/*.json); retrieval is substring match; no invoice data and no dollar cost is reported here; policy, model behavior, pricing, and tokenization may change.

Do not extrapolate beyond synthetic seed 42, single-run, gemini-2.5-flash/LOW setup. Reported input tokens are not an invoice. Every numeric field traces to raw evidence SHA and jsonPath — verify locally with bun run evidence:verify and bun run bench:offline -- --out /tmp/offline.json.

TypeScript API

import { compileContextWithBundledFonts } from "gemini-context-pack/node";
import { verifyContextPdf } from "gemini-context-pack";
import { toGeminiInlinePart } from "gemini-context-pack/gemini";

const source = "hello world — deterministic example";
const artifact = await compileContextWithBundledFonts(source);
const report = await verifyContextPdf(artifact.pdfBytes, source);
const part = toGeminiInlinePart(artifact);
// part = { inlineData: { mimeType: "application/pdf", data: "<base64>" } }

License and ownership

Owner: ianlyoo — License: Apache-2.0 — Version: 0.1.0 — Language: TypeScript

Not an official Google product. Not affiliated with Google. Gemini API behavior, pricing, and tokenization may change.