# Billable Tokens

- **Event:** [Global Codex Hackathon: [San Francisco]](https://cerebralvalley.ai/e/openai-hackathon-sanfrancisco)
- **When:** Thu, Apr 16 at 10:00 AM – 8:00 PM (PDT)
- **Where:** 1515 3rd Street, San Francisco, CA
- **Team:** [Richuang Lin](https://cerebralvalley.ai/u/richlin), [Brian Norris](https://cerebralvalley.ai/u/bnorris), [Marc Saouda](https://cerebralvalley.ai/u/marcsaouda), [Ali Rezaeian](https://cerebralvalley.ai/u/Alirzn), [rajprakash bale](https://cerebralvalley.ai/u/rajprakashbale)
- **Demo video:** https://youtu.be/1M6gtJtOY40
- **Gallery:** https://cerebralvalley.ai/e/openai-hackathon-sanfrancisco/hackathon/gallery
- **Page:** https://cerebralvalley.ai/e/openai-hackathon-sanfrancisco/hackathon/gallery/11

Adaptive Codex is a Python CLI on top of the OpenAI API that routes every coding turn to the cheapest viable GPT-5.4 tier while preserving conversation context across model switches. The result is a coding session with the cost discipline — cheap tasks go to cheap models, hard tasks still get the frontier model, and the router learns from what actually happened instead of what someone wrote in a regex. 

Key features:
1. Portable conversation state. The app owns raw API output items in SQLite and passes them forward as input[] on every call, so context survives model switches without previous_response_id — a turn handled by nano is visible to a later turn on the frontier model.
2. Plugin-scoped taxonomy and memory. Task families are registered per plugin via routing/taxonomy.py; each plugin gets its own FAISS index and MemoryStore implementation (Protocol-defined). Another team can drop in a plugin='testing' or plugin='sql' and reuse the whole loop without touching the core.
3. Smart Retrieval-augmented LM routing. Every prompt is embedded (text-embedding-3-small), SHA-256-hashed for dedup, and indexed in a per-plugin FAISS IndexIDMap2 wrapping IndexFlatIP (inner product = cosine similarity on normalized vectors). gpt-5.4-nano sees the top-k neighbors and returns a typed RoutingProposal with model, task_type, task_family, memory_key, reasoning, confidence — enforced via Pydantic AI structured output.
4. Graceful degradation at every layer. Embedding failure → zero vector. FAISS missing → no neighbors. LM failure → neighbor-majority fallback. The CLI never sees an exception from route() — an engineering team running this in production doesn't get paged because the classifier had a bad day.
5. Tool-item continuity. function_call / shell_call / local_shell_call / apply_patch_call items and their matching outputs are persisted verbatim, so tool context carries across model swaps as well.
6. Lightweight stack. Python CLI + SQLite (WAL) + FAISS + vanilla HTML/JS dashboard. No training pipeline, no orchestration framework, no platform migration.

---

Markdown version of https://cerebralvalley.ai/e/openai-hackathon-sanfrancisco/hackathon/gallery/11. Site index for agents: https://cerebralvalley.ai/llms.txt · full text: https://cerebralvalley.ai/llms-full.txt
