ScrapeGraphAI/Scrapegraph-ai · error · Exception
Error instancing model: {e}
Error message
Error instancing model: {e} What it means
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.
Source
Thrown at scrapegraphai/graphs/abstract_graph.py:291
elif model_provider == "xai":
return XAI(**llm_params)
elif model_provider == "togetherai":
try:
from langchain_together import ChatTogether
except ImportError:
raise ImportError(
"""The langchain_together module is not installed.
Please install it using `pip install langchain-together`."""
)
return ChatTogether(**llm_params)
elif model_provider == "nvidia":
return Nvidia(**llm_params)
except Exception as e:
raise Exception(f"Error instancing model: {e}")
def get_state(self, key=None) -> dict:
""" ""
Get the final state of the graph.
Args:
key (str, optional): The key of the final state to retrieve.
Returns:
dict: The final state of the graph.
"""
if key is not None:
return self.final_state[key]
return self.final_state
def append_node(self, node):
"""View on GitHub (pinned to 532dfffbf6)
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.
Example fix
# before
config = {'llm': {'model_provider': 'openai', 'model': 'gpt-4o', 'api_keys': key}} # typo: api_keys
# after
config = {'llm': {'model_provider': 'openai', 'model': 'gpt-4o', 'api_key': key}} Defensive patterns
Strategy: try-catch
Validate before calling
cfg = config['llm']
allowed = {'model_provider', 'model', 'api_key', 'temperature', 'max_tokens'}
extra = set(cfg) - allowed
assert not extra, f'unexpected llm config keys that get splatted into the constructor: {extra}' Try / catch
try:
graph = SmartScraperGraph(prompt=p, config=config)
except Exception as e:
msg = str(e)
if 'Error instancing model' not in msg:
raise
logger.error('LLM construction failed: %s', msg)
raise SystemExit('Check api_key / model name / constructor kwargs') from e Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- model_tokens not specified
- Provider {llm_params["model_provider"]} is not supported.
- Provider {llm_params["model_provider"]} is not supported.
- Model not supported
- The langchain_together module is not installed.
AI-assisted analysis of ScrapeGraphAI/Scrapegraph-ai@532dfffbf6 (2026-08-28).
Data as JSON: /api/errors/e41b270f9d6ead02.
Report an issue: GitHub.