Skip to content

Conversation

@waleedlatif1
Copy link
Collaborator

Summary

  • fixed hosted providers to exact string match model names rather than check provider names

Type of Change

  • Bug fix

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link

vercel bot commented Dec 6, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Comments Updated (UTC)
docs Skipped Skipped Dec 6, 2025 9:27pm

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Dec 6, 2025

Greptile Overview

Greptile Summary

Changed hosted provider logic from provider-based checks to exact model name matching to prevent incorrect billing for versioned models.

Key Changes:

  • shouldBillModelUsage() now uses exact string matching (case-insensitive) instead of includes() check
  • getApiKey() verifies exact model match against hosted list before using server credentials
  • Models like claude-sonnet-4-20250514 or gpt-4o-2024-08-06 now correctly require user-provided credentials instead of using server credentials
  • Added comprehensive test coverage for exact matching behavior and versioned model handling

Impact:
This fix ensures that only explicitly hosted models (like gpt-4o, claude-sonnet-4-0) use server credentials and billing, while versioned variants require user credentials. This prevents incorrect billing and credential usage for models not in the hosted list.

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • The changes are well-implemented with exact string matching logic that properly handles case-insensitivity. Comprehensive test coverage validates all edge cases including versioned models, case-insensitive matching, and fallback behavior. The logic correctly addresses the billing issue without introducing new vulnerabilities.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/providers/utils.ts 5/5 Fixed hosted provider logic to check exact model name matches instead of just provider names, preventing incorrect billing for non-hosted versioned models
apps/sim/providers/utils.test.ts 5/5 Added comprehensive test coverage for new exact model matching logic and billing behavior for versioned models

Sequence Diagram

sequenceDiagram
    participant Client
    participant getApiKey
    participant shouldBillModelUsage
    participant getHostedModels
    
    Note over Client,getHostedModels: Model Authorization Flow (PR #2228)
    
    Client->>getApiKey: Request authorization for model
    getApiKey->>getApiKey: Check hosted environment status
    
    alt Hosted environment detected
        getApiKey->>getHostedModels: Retrieve hosted models list
        getHostedModels-->>getApiKey: Return model names
        
        getApiKey->>getApiKey: Perform exact string match (case-insensitive)
        
        alt Exact match found in hosted list
            getApiKey->>getApiKey: Attempt server-side rotation
            alt Rotation successful
                getApiKey-->>Client: Return server credentials
            else Rotation failed with fallback
                getApiKey-->>Client: Return user credentials
            else Rotation failed without fallback
                getApiKey-->>Client: Error: No credentials available
            end
        else No exact match in hosted list
            alt User credentials provided
                getApiKey-->>Client: Return user credentials
            else No user credentials
                getApiKey-->>Client: Error: Credentials required
            end
        end
    else Non-hosted environment
        alt User credentials exist
            getApiKey-->>Client: Return user credentials
        else No credentials
            getApiKey-->>Client: Error: Credentials required
        end
    end
    
    Note over Client,getHostedModels: Usage Billing Determination
    
    Client->>shouldBillModelUsage: Check if model should be billed
    shouldBillModelUsage->>getHostedModels: Retrieve hosted models list
    getHostedModels-->>shouldBillModelUsage: Return model names
    shouldBillModelUsage->>shouldBillModelUsage: Exact match verification (case-insensitive)
    shouldBillModelUsage-->>Client: Boolean result (true if exact match)
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@waleedlatif1 waleedlatif1 merged commit 26670e2 into staging Dec 6, 2025
9 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/hosted branch December 6, 2025 21:33
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.

2 participants