Dashboard › opencode-lore › Distillation
4ce49ef7-9c2c-4abc-b079-89f92ba15082["lore_tm_v1_YMcuasyxL8fo6DaZ9ziP38kt22XO08azIIbDvKvg4uk","lore_tm_v1__E9wDTkIBYtKJ-USX0KfDUOyo9LZz_R0kKU4zAjrGfk"]
Date: Sep 16, 2026
packages/gateway/src/stream/openai-responses.ts near line 3074.tool_use “never leaks to the client” in the true-streaming path of packages/gateway/src/stream/openai-responses.ts near lines 2635–2642.packages/gateway/src/stream/openai-responses.ts near line 2802.packages/gateway/src/usage-validation.ts contains 324 lines of runtime validation for provider-reported token usage, with exported validators validateAnthropicUsage(), validateOpenAIUsage(), validateResponsesUsage(), and validateGeminiUsageMetadata(), plus exported helpers isRecord() and safeTokenSum().tokenCount() in packages/gateway/src/usage-validation.ts accepts only nonnegative safe integers; undefined is omitted, null is optionally omitted via allowNull, and invalid values throw through invalid(message). safeTokenSum() ignores undefined values and rejects addition that would exceed Number.MAX_SAFE_INTEGER.validateSubset() sums component counts with safeTokenSum(), rejects a positive component sum when its parent total is absent, and rejects a component sum greater than its parent total.validateAnthropicUsage() validates input_tokens, output_tokens, cache_read_input_tokens, and cache_creation_input_tokens; supports options required, requireInput, requireOutput, and allowNullCounts; validates cache_creation.ephemeral_5m_input_tokens plus cache_creation.ephemeral_1h_input_tokens as a subset of cache_creation_input_tokens; validates output_tokens_details.thinking_tokens as a subset of output_tokens; and validates safe summation of server_tool_use.web_search_requests plus server_tool_use.web_fetch_requests.reasoning_tokens, audio_tokens, accepted_prediction_tokens, and rejected_prediction_tokens. validateOpenAIUsage() validates prompt_tokens, completion_tokens, and total_tokens; requires both component counts when total_tokens exists; requires prompt_tokens + completion_tokens === total_tokens; treats prompt_tokens_details.cached_tokens and cache_write_tokens as subsets of prompt_tokens; and treats completion detail counts as subsets of completion_tokens, not additional totals.validateResponsesUsage() validates input_tokens, output_tokens, and total_tokens; requires both component counts when the total exists; requires input_tokens + output_tokens === total_tokens; validates both input_tokens_details and prompt_tokens_details against input_tokens; and validates output_tokens_details against output_tokens using the OpenAI completion detail fields.promptTokenCount, candidatesTokenCount, thoughtsTokenCount, cachedContentTokenCount, toolUsePromptTokenCount, and totalTokenCount. validateGeminiUsageMetadata() computes the billable component total from promptTokenCount + candidatesTokenCount + thoughtsTokenCount + toolUsePromptTokenCount, requires prompt and candidate counts when totalTokenCount exists, requires the component sum to equal totalTokenCount, and requires cachedContentTokenCount <= promptTokenCount.validateGeminiUsageMetadata() treats cachedContentTokenCount as a subset rather than an additional total and validates modality arrays cacheTokensDetails, candidatesTokensDetails, promptTokensDetails, and toolUsePromptTokensDetails; every detail must be a record, and each tokenCount contributes to a subset sum checked against its corresponding parent count.