What it is

Needleglass is a client-side lab for anyone who packs long context into a language model and wants to see what that pack actually costs, how it is tokenized, and whether the fact they care about is even findable.

A fictional River Glass help-center corpus is retrieved around a single warranty sentence — the needle. The lab tokenizes the packed chat with the official OpenAI BPE encodings (the same ranks as tiktoken), prices the call from published list rates snapshotted on 27 November 2026, and plots a transparent U-shaped findability prior based on Liu et al., 2023, “Lost in the Middle.” There is no API key, no backend, and no telemetry. Every control works in one click.

Who it is for

Developers, students, and evaluators who ship retrieval-augmented or long-context prompts and need a fast, honest way to inspect tokens, cost, overflow, and position effects — without signing in to a model vendor.

What a person does, how the AI method responds, and why that matters

  1. Open the live app. The default “Bloated retrieval” pack on GPT-4o is 16,080 input tokens, $44.20 for 1,000 calls, 12.6% of the window, and 35% findability because the warranty sits in the middle.
  2. Drag Needle depth to 100%. Tokens and cost stay at 16,080 and $44.20; findability rises to 91%. The AI method here is exact BPE tokenization plus a documented position prior — not a hidden model call.
  3. Try Lean retrieve (4,115 tokens, $14.29, 93%), Japanese pack (the same warranty is 35 o200k tokens in Japanese vs 24 in English), and Window overflow (GPT-4o drops 26 early passages, including the needle, and findability falls to 0%; switch to GPT-5.4 and the needle fits).
  4. Read claim support on a sample answer: a verbatim warranty sentence is supported (80%); an invented sentence is unsupported (14%). Open Method & limits for sources and the paraphrase failure case.

The AI method

  • Byte Pair Encoding with public o200k_base and cl100k_base ranks, including official ChatML wrappers, via the MIT-licensed gpt-tokenizer library. Counts are exact for these encodings, not estimates.
  • A research-inspired findability prior shaped like the U-curve in Liu et al. 2023. Midpoint floor 0.38, mild length penalty, zero if the needle was truncated. This is a lab prior, not a measured accuracy for any one model.
  • Lexical claim support using verbatim phrase coverage, with a lighter lexical backup.

Needleglass does not call a generative model API. The AI is in the tokenizer, the retrieval packing, and the evaluation methods you can inspect and rerun locally.

Representative inputs and outputs

  • Input: the default bloated pack, GPT-4o, needle depth 50%, 400 completion tokens, 1,000 calls.
  • Output: 16,080 input tokens, $44.20, 12.6% window fill, 35% findability, needle kept.
  • Input: same pack, needle depth 100%.
  • Output: 16,080 tokens, $44.20, 91% findability.
  • Input: overflow preset on GPT-4o.
  • Output: 124,648 tokens fitted, 26 passages dropped, findability 0%.
  • Input: the English vs Japanese warranty sentences in the encoding lab.
  • Output: 24 vs 35 tokens on o200k_base (51 tokens for the Japanese sentence on cl100k_base).

Limitations and a failure case

  • The findability number is a published-pattern prior, not a benchmark of GPT-4o or GPT-5.4 accuracy.
  • Claim support can under-score a true paraphrase that shares little wording. That is an honest limit of a lexical method, and it is why the lab does not claim to detect hallucinations in general.
  • Only public OpenAI encodings are bundled. Other vendors are omitted rather than silently estimated.
  • The first overflow pack can take a moment to tokenize on a slow machine; later packs are cached.
  • GPT-5.4 long-context multipliers apply only when input exceeds 272,000 tokens; the default presets do not reach that threshold.

Testing

Unit tests cover tokenization (including the public “tiktoken is great!” example), packing and truncation, official pricing and the GPT-5.4 long-context multiplier, the U-shaped prior, claim support and the paraphrase failure, share-link round-trips, and every preset. Headless Chrome E2E covers every slider and preset, asserts that hero readouts update immediately, checks 390×844 for zero horizontal overflow, and requires zero console errors.

Stack, credits, and work completed during the event

  • Stack: vanilla JS, HTML, CSS, a static GitHub Pages deploy.
  • Tokenization: gpt-tokenizer (MIT), ranks compatible with OpenAI tiktoken.
  • Prices and windows: official OpenAI model and pricing pages, 27 November 2026.
  • Findability shape: Liu et al., 2023, arXiv:2307.03172.
  • Fonts (SIL OFL): Atkinson Hyperlegible, Newsreader, JetBrains Mono.
  • This project was created during AI OpenBuild 2026. There is no pre-existing codebase. An AI coding assistant helped write and test the lab; Mohammad Hoque directed the concept, sources, and review.

Team

Mohammad Hoque — sole builder: concept, implementation, tests, design, and documentation.

Judge testing instructions

  1. Open https://mogzz2008.github.io/needleglass/ — no account, no API key.
  2. Confirm the default hero: 16,080 tokens, $44.20, 12.6%, 35%.
  3. Drag Needle depth to 100%. Tokens and cost stay put; findability becomes 91%.
  4. Click Lean retrieve, Japanese pack, and Window overflow. On overflow, switch the model to GPT-5.4 and watch the needle return.
  5. Open Method & limits. Copy the share link or export JSON if you like.
  6. Sound is off by default.

Built With

Share this project:

Updates

Submission history