{"record":{"id":"063eac0fc5445e52","repo":"assafelovic/gpt-researcher","slug":"max-tokens-max-tokens-exceeds-the-largest-output","errorCode":null,"errorMessage":"max_tokens={max_tokens} exceeds the largest output limit of any currently available model (128k as of late 2025). Check your FAST_TOKEN_LIMIT / SMART_TOKEN_LIMIT / STRATEGIC_TOKEN_LIMIT env vars for typos.","messagePattern":"max_tokens=(.+?) exceeds the largest output limit of any currently available model \\(128k as of late 2025\\)\\. Check your FAST_TOKEN_LIMIT / SMART_TOKEN_LIMIT / STRATEGIC_TOKEN_LIMIT env vars for typos\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/utils/llm.py","lineNumber":76,"sourceCode":"        temperature (float, optional): The temperature to use. Defaults to 0.4.\n        max_tokens (int, optional): The max tokens to use. Defaults to 4000.\n        llm_provider (str, optional): The LLM Provider to use.\n        stream (bool): Whether to stream the response. Defaults to False.\n        webocket (WebSocket): The websocket used in the currect request,\n        llm_kwargs (dict[str, Any], optional): Additional LLM keyword arguments. Defaults to None.\n        cost_callback: Callback function for updating cost.\n        reasoning_effort (str, optional): Reasoning effort for OpenAI's reasoning models. Defaults to 'low'.\n        **kwargs: Additional keyword arguments.\n    Returns:\n        str: The response from the chat completion.\n    \"\"\"\n    # validate input\n    if model is None:\n        raise ValueError(\"Model cannot be None\")\n    # Sanity guard against absurd values (e.g., env var typos). The actual\n    # per-model output limits are enforced by the upstream provider.\n    if max_tokens is not None and max_tokens > 200_000:\n        raise ValueError(\n            f\"max_tokens={max_tokens} exceeds the largest output limit of \"\n            \"any currently available model (128k as of late 2025). \"\n            \"Check your FAST_TOKEN_LIMIT / SMART_TOKEN_LIMIT / \"\n            \"STRATEGIC_TOKEN_LIMIT env vars for typos.\"\n        )\n\n    # Get the provider from supported providers\n    provider_kwargs = {'model': model}\n\n    if llm_kwargs:\n        provider_kwargs.update(llm_kwargs)\n    elif os.environ.get(\"LLM_KWARGS\"):\n        import json\n        try:\n            provider_kwargs.update(json.loads(os.environ[\"LLM_KWARGS\"]))\n        except json.JSONDecodeError:\n            pass\n","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/utils/llm.py#L58-L94","documentation":"A sanity guard in create_chat_completion: any max_tokens above 200,000 is rejected because no current model supports more than ~128k output tokens. Values this large almost always come from a typo'd FAST_TOKEN_LIMIT / SMART_TOKEN_LIMIT / STRATEGIC_TOKEN_LIMIT env var (e.g. an extra digit) rather than a genuine need.","triggerScenarios":"Passing max_tokens > 200000, usually because a *_TOKEN_LIMIT env var was set incorrectly (e.g. 4000000 instead of 400000) or a config default got corrupted; the value is forwarded from token_limit settings into create_chat_completion.","commonSituations":"Copy-pasting token limits between projects with an extra digit; confusing context-window size (1M+) with output-token limits; env var typos after an upgrade that introduced these variables.","solutions":["Fix the env var: check FAST_TOKEN_LIMIT, SMART_TOKEN_LIMIT, STRATEGIC_TOKEN_LIMIT for extra digits and set realistic values (e.g. 4000–128000)","If calling directly, pass max_tokens=None to use provider defaults or a value ≤128000","Print your token-limit settings before the call to confirm what's actually being sent"],"exampleFix":"# before\nexport FAST_TOKEN_LIMIT=4000000  # ValueError: max_tokens=4000000 exceeds...\n\n# after\nexport FAST_TOKEN_LIMIT=400000","handlingStrategy":"validation","validationCode":"MAX_OUTPUT_TOKENS = 200_000\nlimit = int(os.getenv('FAST_TOKEN_LIMIT', 400000))\nassert limit <= MAX_OUTPUT_TOKENS, f'FAST_TOKEN_LIMIT={limit} is invalid'","typeGuard":"def valid_token_limit(v) -> bool:\n    return v is None or (isinstance(v, int) and 0 < v <= 200_000)","tryCatchPattern":"try:\n    resp = await create_chat_completion(prompt, model, max_tokens=limit)\nexcept ValueError as e:\n    if 'max_tokens' in str(e):\n        resp = await create_chat_completion(prompt, model)  # provider default\n    else:\n        raise","preventionTips":["Keep output token limits ≤128000 (real model maximum)","Treat *_TOKEN_LIMIT env vars as output limits, not context-window sizes","Add a config lint step that range-checks numeric env vars at startup"],"tags":["validation","llm","max-tokens","env-var","configuration"],"backgroundTag":"invalid-token-limit-config","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}