{"record":{"id":"e41b270f9d6ead02","repo":"ScrapeGraphAI/Scrapegraph-ai","slug":"error-instancing-model-e","errorCode":null,"errorMessage":"Error instancing model: {e}","messagePattern":"Error instancing model: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"scrapegraphai/graphs/abstract_graph.py","lineNumber":291,"sourceCode":"\n                elif model_provider == \"xai\":\n                    return XAI(**llm_params)\n\n                elif model_provider == \"togetherai\":\n                    try:\n                        from langchain_together import ChatTogether\n                    except ImportError:\n                        raise ImportError(\n                            \"\"\"The langchain_together module is not installed.\n                                          Please install it using `pip install langchain-together`.\"\"\"\n                        )\n                    return ChatTogether(**llm_params)\n\n                elif model_provider == \"nvidia\":\n                    return Nvidia(**llm_params)\n\n        except Exception as e:\n            raise Exception(f\"Error instancing model: {e}\")\n\n    def get_state(self, key=None) -> dict:\n        \"\"\" \"\"\n        Get the final state of the graph.\n\n        Args:\n            key (str, optional): The key of the final state to retrieve.\n\n        Returns:\n            dict: The final state of the graph.\n        \"\"\"\n\n        if key is not None:\n            return self.final_state[key]\n        return self.final_state\n\n    def append_node(self, node):\n        \"\"\"","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/ScrapeGraphAI/Scrapegraph-ai/blob/532dfffbf6ee823a6c9cf8cfedc24a93bf026780/scrapegraphai/graphs/abstract_graph.py#L273-L309","documentation":"A catch-all Exception raised at the end of _create_llm's try block: any exception thrown while constructing the provider-specific chat model (bad API key, unknown kwargs, network/auth errors from the LangChain class, etc.) is re-raised as 'Error instancing model: {e}'. The original message is embedded but the original type/traceback context is flattened, so inspect the inner text.","triggerScenarios":"Any constructor failure of OpenAI(), ChatTogether(), Nvidia(), AzureChatOpenAI(), etc. with **llm_params: missing/invalid api_key, unexpected kwarg passed through from config, wrong endpoint/deployment name, or an auth connectivity failure at init.","commonSituations":"Typos in config keys that get splatted into the model constructor (e.g. 'temperature' misspelled or an extra key the class rejects); expired API keys; azure deployment_name mismatches; version changes in LangChain constructor signatures.","solutions":["Read the inner '{e}' text — it usually names the real cause (auth, kwarg, deployment).","Validate the llm config keys against the LangChain class signature for your provider and remove stray keys.","Test the model in isolation: instantiate the LangChain class directly with the same params to reproduce.","Check API key validity/quotas in the provider console."],"exampleFix":"# before\nconfig = {'llm': {'model_provider': 'openai', 'model': 'gpt-4o', 'api_keys': key}}  # typo: api_keys\n\n# after\nconfig = {'llm': {'model_provider': 'openai', 'model': 'gpt-4o', 'api_key': key}}","handlingStrategy":"try-catch","validationCode":"cfg = config['llm']\nallowed = {'model_provider', 'model', 'api_key', 'temperature', 'max_tokens'}\nextra = set(cfg) - allowed\nassert not extra, f'unexpected llm config keys that get splatted into the constructor: {extra}'","typeGuard":null,"tryCatchPattern":"try:\n    graph = SmartScraperGraph(prompt=p, config=config)\nexcept Exception as e:\n    msg = str(e)\n    if 'Error instancing model' not in msg:\n        raise\n    logger.error('LLM construction failed: %s', msg)\n    raise SystemExit('Check api_key / model name / constructor kwargs') from e","preventionTips":["Sanitize the llm config dict before passing it — stray keys are splatted into the provider constructor.","Smoke-test the LangChain client directly before building the graph.","Log the full inner message; the wrapper hides the original exception type."],"tags":["llm","wrapper-exception","constructor","configuration"],"backgroundTag":"llm-client-initialization-failed","analyzedSha":"532dfffbf6ee823a6c9cf8cfedc24a93bf026780","analyzedAt":"2026-08-28T15:19:38.821Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}