assafelovic/gpt-researcher · error · ValueError
max_tokens={max_tokens} exceeds the largest output limit of
Error message
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. What it means
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.
Source
Thrown at gpt_researcher/utils/llm.py:76
temperature (float, optional): The temperature to use. Defaults to 0.4.
max_tokens (int, optional): The max tokens to use. Defaults to 4000.
llm_provider (str, optional): The LLM Provider to use.
stream (bool): Whether to stream the response. Defaults to False.
webocket (WebSocket): The websocket used in the currect request,
llm_kwargs (dict[str, Any], optional): Additional LLM keyword arguments. Defaults to None.
cost_callback: Callback function for updating cost.
reasoning_effort (str, optional): Reasoning effort for OpenAI's reasoning models. Defaults to 'low'.
**kwargs: Additional keyword arguments.
Returns:
str: The response from the chat completion.
"""
# validate input
if model is None:
raise ValueError("Model cannot be None")
# Sanity guard against absurd values (e.g., env var typos). The actual
# per-model output limits are enforced by the upstream provider.
if max_tokens is not None and max_tokens > 200_000:
raise ValueError(
f"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."
)
# Get the provider from supported providers
provider_kwargs = {'model': model}
if llm_kwargs:
provider_kwargs.update(llm_kwargs)
elif os.environ.get("LLM_KWARGS"):
import json
try:
provider_kwargs.update(json.loads(os.environ["LLM_KWARGS"]))
except json.JSONDecodeError:
pass
View on GitHub (pinned to 6f998577d5)
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
Example fix
# before export FAST_TOKEN_LIMIT=4000000 # ValueError: max_tokens=4000000 exceeds... # after export FAST_TOKEN_LIMIT=400000
Defensive patterns
Strategy: validation
Validate before calling
MAX_OUTPUT_TOKENS = 200_000
limit = int(os.getenv('FAST_TOKEN_LIMIT', 400000))
assert limit <= MAX_OUTPUT_TOKENS, f'FAST_TOKEN_LIMIT={limit} is invalid' Type guard
def valid_token_limit(v) -> bool:
return v is None or (isinstance(v, int) and 0 < v <= 200_000) Try / catch
try:
resp = await create_chat_completion(prompt, model, max_tokens=limit)
except ValueError as e:
if 'max_tokens' in str(e):
resp = await create_chat_completion(prompt, model) # provider default
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- rate_limit_delay must be a number, got {rate_limit_delay!r}
- Invalid reasoning effort: {reasoning_effort_str}. Valid opti
- Model cannot be None
- rate_limit_delay must be non-negative, got {delay}
- LLM_PROVIDER, FAST_LLM_MODEL and SMART_LLM_MODEL are depreca
AI-assisted analysis of assafelovic/gpt-researcher@6f998577d5 (2026-08-28).
Data as JSON: /api/errors/063eac0fc5445e52.
Report an issue: GitHub.