resolveMaxTokens (src/max-tokens.ts)

ClawRouter · src/max-tokens.ts · typescript · MIT
payments

Parses max token budget from chat payload for routing and billing.

// Source: https://github.com/BlockRunAI/ClawRouter | License: MIT | Copyright 2026 BlockRunAI
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Output-token budget parsing, shared by the proxy and the payment pre-auth
 * layer.
 *
 * Lives in its own module because both `proxy.ts` and `payment-preauth.ts` need
 * it and `proxy.ts` already imports `payment-preauth.ts` — defining it in either
 * one would make the import cycle.
 */

/** Output-token budget assumed when the request declares none. */
export const DEFAULT_MAX_TOKENS = 4096;

/**
 * Read the requested output-token budget from a parsed chat body.
 *
 * OpenAI deprecated `max_tokens` in favour of `max_completion_tokens`; we accept
 * both because this number is not cosmetic. It feeds the routing decision,
 *

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key