Skip to content
Discussion options

You must be logged in to vote

The custom callback approach is solid for this use case. Here is how I would structure it:

from litellm import Callbacks
from litellm.types.utils import ModelResponse

MODEL_MAP = {
    "my-custom-gpt4": "gpt-4o",
    "my-custom-claude": "claude-3-5-sonnet-latest",
}

PRICE_OVERRIDE = {
    "my-custom-gpt4": {
        "input_cost_per_token": 0.000005,
        "output_cost_per_token": 0.000015,
    },
}

class ModelMappingCallback(Callbacks):
    def log_pre_api_call(self, model, messages, kwargs):
        # Map custom name to real name for upstream
        if model in MODEL_MAP:
            kwargs["model"] = MODEL_MAP[model]
            kwargs["_original_model"] = model  # Save for cost calc

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by changchiyou
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants