Skip to content

Update enhanced-inference.ts#10

Open
HO-git wants to merge 1 commit intoCache-error-testfrom
patch-1
Open

Update enhanced-inference.ts#10
HO-git wants to merge 1 commit intoCache-error-testfrom
patch-1

Conversation

@HO-git
Copy link
Copy Markdown
Owner

@HO-git HO-git commented Mar 6, 2026

remove the unnecessary errors for the providers that aren't wired up in the cache logic in the first place, but without messing up the original cache guard logic

@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Mar 6, 2026

Greptile Summary

This PR prevents PricingNotConfiguredError from crashing in-flight inference calls for openai-compatible provider models. Previously, user-defined (UUID / customEndpoint) openai-compatible models would correctly bypass validatePricingAvailable, but would then throw deep inside getInputPricePerToken / getOutputPricePerToken when no hardcoded pricing entry existed — potentially aborting an already-completed LLM call. The fix gracefully returns 0 (with a warning log) for that provider, treating cost metrics as best-effort.

  • getInputPricePerToken (line 703): added early return 0 + console.warn for openai-compatible before the PricingNotConfiguredError throw
  • getOutputPricePerToken (line 737): same change mirrored for output pricing
  • Missing newline at EOF: fixed
  • Potential inconsistency: validatePricingAvailable is not updated to align — non-UUID / non-customEndpoint openai-compatible models will still be rejected at the handler gate even though the pricing functions now handle them gracefully; see inline comment for a suggested fix

Confidence Score: 4/5

  • Safe to merge — the change is narrowly scoped and prevents real crashes for openai-compatible user-defined models without affecting billing accuracy for managed providers.
  • The fix correctly targets the only scenario where the error was reachable (UUID/customEndpoint models bypassing validatePricingAvailable), returns a semantically correct $0 value, and leaves all other provider error paths untouched. The only concern is the minor inconsistency with validatePricingAvailable not being updated in parallel, which is a style issue rather than a correctness or security problem.
  • No files require special attention — the change is self-contained within enhanced-inference.ts.

Important Files Changed

Filename Overview
deprecated-claude-app/backend/src/services/enhanced-inference.ts Adds a graceful return 0 (with a console.warn) in getInputPricePerToken and getOutputPricePerToken for openai-compatible providers when no pricing is found, preventing a PricingNotConfiguredError from crashing an in-flight inference call. Also fixes the missing newline at end of file.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Handler receives request] --> B{validatePricingAvailable}
    B -->|UUID / customEndpoint model| C[bypass → valid: true]
    B -->|Admin config found| C
    B -->|OpenRouter pricing found| C
    B -->|Hardcoded table hit| C
    B -->|No pricing source found\nnon-UUID / non-customEndpoint| D[valid: false → send error to client]

    C --> E[EnhancedInferenceService.streamCompletion]
    E --> F[LLM API call]
    F --> G[calculateCostSaved / calculateCostBreakdown]
    G --> H{getInputPricePerToken}

    H -->|Admin config| I[return configPricing.input / 1M]
    H -->|OpenRouter cache| J[return orPricing.input / 1M]
    H -->|Hardcoded table hit| K[return price / 1M]
    H -->|No price found\nprovider = openai-compatible| L["NEW: console.warn + return 0"]
    H -->|No price found\nother provider| M[throw PricingNotConfiguredError]
Loading

Last reviewed commit: 9f1ba06

Comment on lines 703 to +742
@@ -727,6 +734,13 @@ export class EnhancedInferenceService {
?? OUTPUT_PRICING_PER_MILLION[model.id];

if (price === undefined) {
if (model.provider === 'openai-compatible') {
console.warn(
`[Pricing] No pricing configured for openai-compatible model ${model.id} (${model.providerModelId || 'none'}), assuming $0 for metrics`
);
return 0;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

validatePricingAvailable not updated to match

The upstream validatePricingAvailable function (line 232) does not have a corresponding bypass for openai-compatible providers. This means a non-UUID, non-customEndpoint openai-compatible model without any configured pricing will still be blocked at the handler's validation gate before reaching these functions — so the new return 0 path is currently only reachable by user-defined (isUUID / hasCustomEndpoint) models.

This is consistent with the original intent (user-defined models bypass the pricing gate and accept responsibility for their own costs), but the two behaviours are not obviously co-located. Consider adding a matching bypass or comment in validatePricingAvailable to make it clear that openai-compatible models are expected to gracefully fall back to $0 pricing:

// In validatePricingAvailable, after step 3:
if (model.provider === 'openai-compatible') {
  // openai-compatible models are self-hosted; cost tracking is best-effort
  return { valid: true };
}

This would make the two functions consistent and prevent future confusion if validatePricingAvailable is called independently.

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