Update enhanced-inference.ts#10
Conversation
Greptile SummaryThis PR prevents
Confidence Score: 4/5
Important Files Changed
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]
Last reviewed commit: 9f1ba06 |
| @@ -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; | |||
| } | |||
There was a problem hiding this comment.
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.
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