{"record":{"id":"0cd272ebc253cd21","repo":"xtekky/gpt4free","slug":"model-model-not-found","errorCode":null,"errorMessage":"Model {model} not found","messagePattern":"Model (.+?) not found","errorType":"exception","errorClass":"ModelNotFoundError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/hf_space/CohereForAI_C4AI_Command.py","lineNumber":65,"sourceCode":"\n        # Check if the model exists directly in our models list\n        if model in cls.models:\n            return model\n\n        # Check if there's an alias for this model\n        if model in cls.model_aliases:\n            alias = cls.model_aliases[model]\n            # If the alias is a list, randomly select one of the options\n            if isinstance(alias, list):\n                selected_model = random.choice(alias)\n                debug.log(\n                    f\"{cls.__name__}: Selected model '{selected_model}' from alias '{model}'\"\n                )\n                return selected_model\n            debug.log(f\"{cls.__name__}: Using model '{alias}' for alias '{model}'\")\n            return alias\n\n        raise ModelNotFoundError(f\"Model {model} not found\")\n\n    @classmethod\n    async def create_async_generator(\n        cls,\n        model: str,\n        messages: Messages,\n        api_key: str = None,\n        proxy: str = None,\n        conversation: JsonConversation = None,\n        return_conversation: bool = True,\n        **kwargs,\n    ) -> AsyncResult:\n        model = cls.get_model(model)\n        headers = {\n            \"Origin\": cls.url,\n            \"User-Agent\": \"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:133.0) Gecko/20100101 Firefox/133.0\",\n            \"Accept\": \"*/*\",\n            \"Accept-Language\": \"en-US,en;q=0.5\",","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/hf_space/CohereForAI_C4AI_Command.py#L47-L83","documentation":"ModelNotFoundError raised in the Cohere Command HF Space provider's model resolution: the requested model string is neither a key in cls.model_aliases nor handled by an earlier branch (the shown code is the terminal else — every accepted name is an alias, possibly mapping to a list from which one variant is randomly chosen). It means the provider's static alias table does not know the model name you passed.","triggerScenarios":"Calling CohereForAI_C4AI_Command.create_async_generator with a model string not present in its model_aliases dict — e.g. a typo, a model name belonging to a different provider, or a newly released Cohere model not yet added to the alias table.","commonSituations":"Passing 'command-r-plus-08-2024' or 'command-a' before it was added to model_aliases; passing generic names like 'gpt-4' or 'claude-3' to this provider; case/format mismatches with the alias keys.","solutions":["List valid models first: use the provider's get_models()/image_models surface or inspect cls.model_aliases keys, and pass one of those exact names.","Check for typos and exact casing in the model name.","If the model genuinely exists on the HF Space but is missing from g4f, add it to model_aliases in CohereForAI_C4AI_Command.py (or open an upstream issue/PR)."],"exampleFix":"# before\nprovider.create_async_generator(model=\"command-r-plus\", messages=msgs)\n\n# after (use a name from cls.model_aliases)\nprovider.create_async_generator(model=provider.default_model, messages=msgs)","handlingStrategy":"validation","validationCode":"if model not in CohereForAI_C4AI_Command.model_aliases:\n    model = CohereForAI_C4AI_Command.default_model  # or raise your own error\n# or: valid = CohereForAI_C4AI_Command.get_models()","typeGuard":"def is_supported_model(provider_cls, model: str) -> bool:\n    return model in getattr(provider_cls, 'model_aliases', {})","tryCatchPattern":"try:\n    ...\nexcept ModelNotFoundError:\n    model = provider_cls.default_model  # fail over to a known-good alias\n    ...","preventionTips":["Derive model names from get_models()/model_aliases instead of hardcoding strings.","Validate user-supplied model names against the provider alias table before dispatch.","Catch ModelNotFoundError at the router level to fall back to the default model."],"tags":["model-not-found","hf-space","cohere","validation"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}