Tokens, context and output length

How Aimogen Pro computes the token budget for a request, why generated content gets truncated, and the settings that control input and output length.

Almost every "the article stops mid-sentence" report comes down to token budgeting. This page explains how Aimogen Pro decides how much room a request has.

The two limits#

Every model has two separate limits, and confusing them causes most of the trouble:

LimitMeaning
Input / context windowHow much prompt the model will accept
Output / completion limitHow much the model will generate in one reply

They are very different numbers. gpt-4.1 accepts around a million input tokens but will only produce about 32,000 in one reply. gpt-4o accepts 128,000 and produces up to about 16,000.

Aimogen Pro keeps per-model tables for both.

How the budget is computed#

For each request:

  1. The prompt is assembled — your template, placeholders expanded, plus any injected retrieval chunks and internet results.
  2. The prompt is tokenised locally to count its tokens.
  3. If the count exceeds the model input limit, the prompt is truncated to fit.
  4. The remaining room becomes the available output budget, capped by your Max Tokens setting.

Step 3 is important: the plugin trims the prompt rather than letting the provider reject the request. That keeps generation working, but it means content silently disappears from the end of a very long prompt.

Overriding context limits#

Four settings on Settings › Advanced AI Settings let you override the built-in input limits:

SettingApplies toDefault if empty
Context Window Limit For gpt-3.5-turbo-1106The 16K GPT-3.5 modelsThe built-in table value
Context Window Limit For gpt-4-1106GPT-4 turbo and newer OpenAI models128,000
Context Window Limit For Claude ModelsClaude models100,000
Context Window Limit For Claude Models (200K)Claude models in the 200K listThe built-in value

When to lower one. To control cost. Input tokens are billed, and a model that accepts 390,000 tokens will happily bill you for them. Setting a lower limit forces earlier prompt truncation.

When to raise one. Rarely. If a provider increases a window and you do not want to wait for a plugin update.

Max Tokens#

Max Tokens caps the output. Defaults:

ConstantValueWhere it applies
AIMOGEN_DEFAULT_MAX_TOKENS2048General writer default
AIMOGEN_BULK_CONTENT_MAX_TOKENS4096Bulk content generation
AIMOGEN_DEFAULT_COMPLETION_TOKENS2000Completions
AIMOGEN_MINIMUM_TOKENS_FOR_CHAT50Floor below which a chat request is not attempted
AIMOGEN_MINIMUM_TOKENS_FOR_COMPLETIONS50Same, for completions
AIMOGEN_MAX_HUGGINGFACE_TOKEN_COUNT2000Hard cap for Hugging Face
AIMOGEN_MAX_OLLAMA_TOKEN_COUNT4000Hard cap for Ollama

Rules of thumb for English prose: 1 token is roughly 0.75 words, so 2048 tokens is about 1,500 words and 4096 is about 3,000.

Why content gets truncated#

Symptom: the article stops mid-sentence, or the last section is missing.

Causes, in order of likelihood:

  1. Max Tokens is too low. Raise it, but do not exceed the model output limit.
  2. The model output limit was reached. gpt-4o-mini cannot produce 30,000 tokens no matter what you set. Generate in sections instead.
  3. PHP timed out. The request was killed before the provider finished. Check max_execution_time — see Recommended server configuration.
  4. The prompt consumed the window. Long retrieval injection plus long internet results leaves no room for output.

Diagnose it in System & Logs › Usage Logs: the row records the request. A finish_reason of length means the model hit the output cap; a truncated response with no finish_reason usually means PHP or the network cut the connection.

Generating long content properly#

Do not ask for 5,000 words in one call. Every bulk creator supports section-by-section generation, which is both more reliable and better structured:

  1. Generate the title.
  2. Generate a section outline.
  3. Generate each section as a separate request.
  4. Generate the introduction and conclusion with the finished body available as context.

That is what the bulk creators do by default, and it is why they can produce far longer articles than a single call allows.

The %%article_so_far%%, %%last_section_content%% and %%current_section%% placeholders give each call the context it needs. See Placeholder reference.

Two related settings on the rule:

SettingEffect
Maximum Prompt Token Count To Use Per API RequestCaps prompt size per call
Maximum Result Token Count To Use Per API RequestCaps output per call
Maximum Continue Token Count To Use Per API RequestCaps the continuation call when content is extended
Created Content Minimum Character CountIf the result is shorter, the plugin asks the model to continue

Do not send max tokens at all#

Settings › General Settings › Don't Send Maximum Tokens In API Request (Experimental) omits the parameter entirely and lets the model decide.

The plugin help text names the specific case it was added for: content editing involving Chinese characters, where the token estimate is unreliable. It is a workaround, not a general setting. Leave it off unless you have that problem.

Counting tokens#

The plugin tokenises locally using a bundled BPE vocabulary. That gives a good estimate for OpenAI models and a reasonable one elsewhere — other providers use different tokenisers, so counts for Claude, Gemini and open models are approximate.

The consequence: on non-OpenAI models the budget is conservative. If you see truncation earlier than expected on Claude or Gemini, that is the estimate being cautious.

Still stuck? Open a support ticket and include the diagnostics from Aimogen Pro › System & Logs › System Info.