Skip to content

Route documents over 32,000 characters to chunklaya - #113

Merged
myxamediyar merged 2 commits into
mainfrom
chunklaya-routing
Sep 23, 2026
Merged

myxamediyar merged 2 commits into
mainfrom
chunklaya-routing

Conversation

@myxamediyar

@myxamediyar myxamediyar commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Inputs over MAX_CHARS (32,000 characters) are answered by chunklaya, our own long-document service (myxamediyar/chunklaya, serve/), when CHUNKLAYA_URL and CHUNKLAYA_TOKEN are set and CHUNKLAYA_ENABLED is "true". Without them, those requests keep answering 400 input_too_long, so the change is safe to deploy before the secrets exist.

Routing

  • Only inputs over 32,000 characters are affected; everything at or under is untouched.
  • Explicit model: "jev" keeps the 32,000 ceiling; model: "chunklaya" selects the service for shorter text.
  • Results are labelled chunklaya/multilingual.
  • Ceilings: 4,000,000 characters per input, 20 inputs per request; tier: "smart" is refused with bad_tier.
  • Service refusals map to chunklaya_input (400), chunklaya_busy (429, Retry-After) and chunklaya_unavailable (503), in our own words. No fallback to Jev or the LLM chain.

Transport — a fourth Backend in src/jev.ts over the bearer transport Beam uses: URL and token from the environment, one document per request, 60 s deadline, no per-token provider cost. dimensions pack against its limits so all questions about a document go in one request.

Billing — zero rate in retail-rates.json (version 2026-09-23-chunklaya-v3), the spending price table and providerCallBound.

Surfaces — docs (LONG DOCUMENTS, parameters, error list), OpenAPI (model enum, error codes, limits), MCP enums, CLI (--model chunklaya), wrangler.example.toml, AGENTS.md.

Deploy — deploy.yml passes CHUNKLAYA_URL and CHUNKLAYA_TOKEN to the Worker when both are repository secrets, and omits them otherwise.

Checks — npm run typecheck clean; npm test 797 pass / 0 fail (8 new in test/chunklaya.test.ts); cd cli && node --test 27 pass.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added Chunklaya support for classifying long documents up to 4,000,000 characters.
    • Automatically routes oversized documents to Chunklaya when enabled and configured.
    • Added chunklaya as a supported model across the CLI, API, MCP tools, and classification workflows.
    • Added clear errors for invalid, busy, or unavailable Chunklaya requests.
    • Documented limits, configuration, and long-document behavior.
    • Added free-tier pricing support for Chunklaya.

An input over MAX_CHARS used to be refused with input_too_long. When
CHUNKLAYA_URL and CHUNKLAYA_TOKEN are set and CHUNKLAYA_ENABLED is "true",
it is now answered by chunklaya, our own long-document service (Laya behind
a chunk-and-index harness, github.com/myxamediyar/chunklaya, serve/), and
the result is labelled chunklaya/multilingual. Nothing at or under 32,000
characters changes; an explicit model "jev" keeps its ceiling; model
"chunklaya" selects it for shorter text. Unconfigured, the old 400 stands.

The service speaks System One, so it is a fourth Backend in src/jev.ts
through the bearer transport Beam already uses, with the URL and token read
from the environment, one document per request, a 60 s deadline, and no
per-token cost (the pod is billed by the hour). Its refusals are reported
as chunklaya_input, chunklaya_busy and chunklaya_unavailable in our own
words, and never fall back to Jev or the LLM chain. Ceilings: 4,000,000
characters per input, 20 inputs per request, no smart tier.

Dimensions pack against the backend's limits so every question about a
document travels in one request. Billing prices the model at zero in the
rate card, the spending table and the reservation bound. Docs, OpenAPI, MCP
and the CLI render the new model and codes from the same constants.

The deploy workflow passes CHUNKLAYA_URL and CHUNKLAYA_TOKEN to the Worker
when both exist as repository secrets, and leaves them out otherwise.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 23, 2026

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 15f681cf-0ed0-4cca-b6f9-3e7fe39231ee

📥 Commits

Reviewing files that changed from the base of the PR and between b52c5f0 and d9e89a1.

📒 Files selected for processing (18)
  • .github/workflows/deploy.yml
  • AGENTS.md
  • cli/classify.js
  • src/cost.ts
  • src/dimensions.ts
  • src/docs.ts
  • src/http/spending-classification.ts
  • src/index.ts
  • src/jev-observability.ts
  • src/jev.ts
  • src/mcp.ts
  • src/openapi.ts
  • src/retail-rates.json
  • src/server/token-pricing.ts
  • src/server/token-reservation.ts
  • src/spending/policy.ts
  • test/chunklaya.test.ts
  • wrangler.example.toml
 _____________________
< Git gud or git out. >
 ---------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

src/index.ts: keep the backend argument on classifyMany together with
main's funded-permit condition on the line after it.

tests/runtime-config.test.ts asserted the deploy step's secrets file by
its old literal; it now asserts what that literal stood for — the pooled
DATABASE_URL, the chunklaya pair only when both are set, and no unpooled
URL anywhere in the deploy step.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@myxamediyar
myxamediyar merged commit 4b40984 into main Sep 23, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant