Topic
Max Tokens, Stop Sequences & Output Truncation
8 posts on max tokens, stop sequences & output truncation — part of glossary on the n4n AI blog.
Why your LLM response cuts off mid-sentence
Your LLM response cuts off mid-sentence because of max_tokens, stop sequences, or provider limits. Here's how to diagnose and fix each cause.
What does max_tokens actually control in an API call?
A precise technical explanation of what max_tokens controls in LLM API calls, how it interacts with context windows and stop sequences, and common misconceptions that cause production bugs.
Max tokens explained: input, output, and total limits
Understand how max tokens, input limits, and output budgets interact across providers — with code patterns for safe truncation, streaming, and cost control.
Max output tokens by model: GPT-4o, Claude, and Gemini
Compare max output tokens across GPT-4o, Claude, and Gemini with practical guidance for handling truncation and stop sequences in production.
How to set max_tokens for long-form content generation
A step-by-step guide to configuring max_tokens for long-form content generation, covering model limits, chunking strategies, and verification techniques.
How to detect and handle truncated LLM responses
Learn to detect truncated LLM responses using finish_reason and usage fields, then implement retries, continuation prompts, and monitoring to handle incomplete outputs reliably.
How stop sequences work in the OpenAI and Claude APIs
Learn how stop sequences control LLM output termination in OpenAI and Claude APIs with practical code examples and verification steps.
Common max_tokens mistakes that truncate JSON output
Seven max_tokens mistakes that silently truncate JSON output, with fixes for token budgeting, reasoning models, streaming, and provider quirks.
More topics in glossary
- Structured Outputs & JSON Mode19
- AI Agents Fundamentals12
- Hallucination in LLMs11
- Sampling Parameters: Top-p, Top-k & Penalties11
- Context Window & Context Length10
- Fine-Tuning Fundamentals9
- Foundation Models: Base vs Instruct vs Chat9
- Model Families & Naming Conventions: GPT-5, Claude, Gemini 3, Llama 4, Mistral, DeepSeek, Qwen, Grok9
- Grounding & Fact-Checking in AI8
- LLM Benchmarks: MMLU, HumanEval, SWE-bench & GPQA8
- Quantization Formats: GGUF, GPTQ, AWQ & INT4/INT88
- Chain-of-Thought Prompting7