> For the complete documentation index, see [llms.txt](https://docs.maiagent.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.maiagent.ai/maiagent-user-guide/maiagent-user-guide-en/build/custom-max-tokens.md).

# Custom Maximum Output Tokens

### Feature Introduction <a href="#feature-introduction" id="feature-introduction"></a>

The custom max output tokens feature allows you to precisely control the maximum length of each AI assistant response. By adjusting this setting, you can have the AI assistant generate brief summaries or detailed explanations based on different use cases, while effectively managing token consumption costs.

{% hint style="info" %}
**About Tokens**

Tokens are the basic units used by AI models to process text. Generally speaking:

* Chinese: 1 character is approximately 1.5-2 Tokens
* English: 1 word is approximately 1-1.5 Tokens
* Punctuation marks also count toward the token count
  {% endhint %}

***

### Configure Max Output Tokens <a href="#configure-token-output-limit" id="configure-token-output-limit"></a>

#### Navigate to Settings Page <a href="#navigate-to-settings" id="navigate-to-settings"></a>

1. Click "<mark style="color:blue;">AI Assistant</mark>" in the left menu
2. Select the AI assistant you want to configure
3. Click the "<mark style="color:blue;">Settings</mark>" button
4. Switch to the "<mark style="color:blue;">Advanced Settings</mark>" tab

#### Adjust Token Limit <a href="#adjust-token-limit" id="adjust-token-limit"></a>

1. **Select Token Limit Mode**
   * "<mark style="color:blue;">Use Model Maximum</mark>": Directly apply the maximum output tokens supported by the selected model (default)
   * "<mark style="color:blue;">Custom Amount</mark>": Specify the limit yourself
2. **Enter Custom Value (when "Custom Amount" is selected)**
   * Enter the target value in the number input field
   * The available range depends on the selected model, and the screen will display the allowed range in real time (e.g., "Range: 512 - 64000 tokens" as shown below)
3. **Save Settings**
   * Click the "<mark style="color:blue;">Save</mark>" button
   * Settings take effect immediately without restarting the AI assistant

<figure><img src="/files/Ul0GTupfCAUU3qoM3WSc" alt="Advanced Settings: Max Output Tokens"><figcaption><p>AI assistant advanced settings page: Choose "Use Model Maximum" or "Custom Amount" to control the max output token limit</p></figcaption></figure>

{% hint style="warning" %}
**Important Notes**

* Setting the value too low may cause responses to be truncated, affecting completeness
* Setting the value too high will increase token consumption costs
* It is recommended to adjust based on actual needs and find the optimal balance through testing
  {% endhint %}

***

### Recommended Settings <a href="#recommended-settings" id="recommended-settings"></a>

Below are recommended token limit settings for different use cases:

<table><thead><tr><th width="200">Use Case</th><th width="150">Recommended Tokens</th><th>Description</th></tr></thead><tbody><tr><td><strong>Quick Q&#x26;A</strong></td><td>256 - 512</td><td>Suitable for quick answers, such as FAQ bots<br>Approximately 100-200 Chinese characters</td></tr><tr><td><strong>General Customer Service</strong></td><td>512 - 1024</td><td>Balances detail and cost<br>Approximately 200-400 Chinese characters</td></tr><tr><td><strong>Professional Consultation</strong></td><td>1024 - 2048</td><td>Provides detailed explanations and solutions<br>Approximately 400-800 Chinese characters</td></tr><tr><td><strong>Content Generation</strong></td><td>2048 - 4096</td><td>Generates long-form articles or reports<br>Approximately 800-1600 Chinese characters</td></tr><tr><td><strong>Code Generation</strong></td><td>1024 - 2048</td><td>Produces complete code snippets<br>Including comments and explanations</td></tr></tbody></table>

***

### Use Case Examples <a href="#use-case-examples" id="use-case-examples"></a>

#### Scenario 1: FAQ Quick Response Bot <a href="#scenario-1-faq-quick-response-bot" id="scenario-1-faq-quick-response-bot"></a>

**Requirement**: Common customer questions need short and clear answers, avoiding lengthy explanations

**Configuration**:

* Max output tokens: 256-512
* System prompt: "Please answer questions in a brief and clear manner, no more than 3 sentences"
* Expected result: Quick responses, reduced token consumption

**Example conversation**:

```
User: What are your business hours?
AI: Our business hours are Monday to Friday from 9:00 AM to 6:00 PM,
Saturday from 10:00 AM to 5:00 PM, and we are closed on Sundays.
```

#### Scenario 2: Technical Support Detailed Explanation <a href="#scenario-2-technical-support-detailed-explanation" id="scenario-2-technical-support-detailed-explanation"></a>

**Requirement**: Users encounter technical issues and need detailed step-by-step instructions

**Configuration**:

* Max output tokens: 1024-2048
* System prompt: "Please provide detailed step-by-step instructions to ensure users can follow along"
* Expected result: Complete troubleshooting guide

**Example conversation**:

```
User: What should I do if the software won't start?
AI: Please follow these steps to troubleshoot:

1. Check System Requirements
   - Operating System: Windows 10 or above
   - Memory: At least 4GB
   - Disk Space: At least 2GB

2. Reinstall the Software
   - Remove the existing version (Control Panel > Programs)
   - Download the latest version [link]
   - Run the installer as administrator

3. Check Firewall Settings
   - Add the software to the exception list
   - Allow the software to access the network

If the above steps don't resolve the issue, please provide a screenshot of the error message and we will assist you further.
```

#### Scenario 3: Content Summary Generation <a href="#scenario-3-content-summary-generation" id="scenario-3-content-summary-generation"></a>

**Requirement**: Extract key summaries from long articles

**Configuration**:

* Max output tokens: 512-768
* System prompt: "Please organize key points into 3-5 bullet points, each no more than 2 sentences"
* Expected result: Concise summaries that are easy to quickly understand

***

### Relationship with Other Settings <a href="#relationship-with-other-settings" id="relationship-with-other-settings"></a>

#### System Prompt <a href="#system-prompt-settings" id="system-prompt-settings"></a>

Even with a high token limit, the system prompt can still constrain response length:

```
Good example:
"Please answer concisely unless the user requests a detailed explanation"

Bad example:
"Please answer every question as thoroughly as possible" (may lead to overly long responses)
```

#### Model Selection <a href="#model-selection" id="model-selection"></a>

Different models support different maximum output token counts. When you switch the model used by the AI assistant, the customizable range will change accordingly, and the range hint displayed on the screen reflects the upper and lower limits of the currently selected model. When "Use Model Maximum" is selected, the system will automatically apply the maximum value for that model.

***

### Cost Optimization Recommendations <a href="#cost-optimization-recommendations" id="cost-optimization-recommendations"></a>

#### Calculate Token Consumption <a href="#calculate-token-consumption" id="calculate-token-consumption"></a>

Token consumption per conversation includes:

* **Input Tokens**: User question + conversation history + system prompt
* **Output Tokens**: AI response (limited by this setting)

**Example calculation**:

```
Input: User question 50 Tokens + Conversation history 200 Tokens + System prompt 100 Tokens = 350 Tokens
Output: AI response (limit set to 512 Tokens)
Total: 350 + 512 = 862 Tokens (maximum)
```

#### Optimization Strategies <a href="#optimization-strategies" id="optimization-strategies"></a>

1. **Adjust by scenario**
   * Use a low token limit for simple questions
   * Only increase the limit for complex questions
2. **Avoid unnecessary long responses**
   * Explicitly require conciseness in the system prompt
   * Use multi-turn conversations instead of single long responses
3. **Regularly review usage**
   * Use the "Usage Analytics" tab to view conversation word count and other usage trends
   * Adjust settings to optimize costs

{% hint style="info" %}
For detailed cost calculations and optimization recommendations, please refer to [Usage Calculation](/maiagent-user-guide/maiagent-user-guide-en/others/usage.md).
{% endhint %}

***

### FAQ <a href="#faq" id="faq"></a>

#### Q: After setting the token limit, will the AI response be forcibly truncated? <a href="#q-will-ai-response-be-cut-off-after-setting-token-limit" id="q-will-ai-response-be-cut-off-after-setting-token-limit"></a>

**A**: Yes. When the AI-generated response reaches the token limit, it will stop at that point, which may result in incomplete sentences. Recommendations:

* Set an appropriate limit (not too low)
* Include in the system prompt: "End naturally before reaching the character limit"

#### Q: How do I check the average token usage of my AI assistant? <a href="#q-how-to-check-average-token-usage" id="q-how-to-check-average-token-usage"></a>

**A**: Go to the AI assistant "<mark style="color:blue;">Settings</mark>" page and select the "<mark style="color:blue;">Usage Analytics</mark>" tab. You can view trend charts by date range for "<mark style="color:blue;">Conversation Word Count</mark>", "Conversation Count", "Message Count", "Average Conversation Interactions", and "User Satisfaction". The "Conversation Word Count" represents the cumulative word count generated by the assistant. Word count is positively correlated with token count and can serve as a reference for token consumption.

<figure><img src="/files/FkGl3j1Iiz8G1nLIaa5Y" alt="Usage Analytics tab"><figcaption><p>AI assistant "Usage Analytics" tab: View trend charts by date range for conversation word count, conversation count, message count, average conversation interactions, and user satisfaction</p></figcaption></figure>

#### Q: Does setting a higher token limit slow down response speed? <a href="#q-does-higher-token-limit-slow-down-responses" id="q-does-higher-token-limit-slow-down-responses"></a>

**A**: There is a slight impact. Longer responses require more generation time, but the difference is usually minimal (within a few seconds). The main factors affecting speed are:

* Model selection
* Network connection speed
* Server load

#### Q: Do different languages require different token limit settings? <a href="#q-different-languages-need-different-token-limits" id="q-different-languages-need-different-token-limits"></a>

**A**: It is recommended to adjust accordingly:

* **Chinese**: The same amount of text consumes more Tokens, so consider slightly increasing the limit
* **English**: Token efficiency is higher, so a lower limit can be used
* **Multi-language environments**: It is recommended to set a higher limit to ensure flexibility

#### Q: Does the token limit affect knowledge base retrieval results? <a href="#q-does-token-limit-affect-knowledge-base-retrieval" id="q-does-token-limit-affect-knowledge-base-retrieval"></a>

**A**: It does not directly affect retrieval, but it affects how retrieval results are presented:

* **High token limit**: Can reference more knowledge base segments
* **Low token limit**: Only references the most relevant segments

***

### Testing and Adjustment <a href="#testing-and-adjustment" id="testing-and-adjustment"></a>

#### Testing Process <a href="#testing-process" id="testing-process"></a>

1. **Set Initial Value**
   * Start with the recommended value (e.g., 1024)
2. **Conduct Test Conversations**
   * Enter typical user questions
   * Observe response length and completeness
3. **Evaluate Results**
   * Is the response complete?
   * Is there unnecessary verbosity?
   * Is token consumption reasonable?
4. **Adjust Gradually**
   * Too long → Lower the token limit
   * Too short/truncated → Increase the token limit
5. **Continuous Monitoring**
   * Regularly review usage
   * Fine-tune based on actual needs

#### Testing Examples <a href="#testing-examples" id="testing-examples"></a>

```
Test 1: Token limit 256
User: Please introduce your company
AI: We are a company focused on AI technology, providing enterprise-level chatbot solutions. [Response truncated]
Evaluation: Too short, need to increase

Test 2: Token limit 1024
User: Please introduce your company
AI: We are a company focused on AI technology...[Complete detailed introduction]...Feel free to contact us to learn more.
Evaluation: Appropriate, adopt this setting
```

***

### Related Features <a href="#related-features" id="related-features"></a>

{% hint style="info" %}
**Extended Features**

* [Create an AI Assistant](/maiagent-user-guide/maiagent-user-guide-en/build/setup.md)
* [System Prompt Design Guide](/maiagent-user-guide/maiagent-user-guide-en/build/system-prompt.md)
* [Usage Calculation](/maiagent-user-guide/maiagent-user-guide-en/others/usage.md)
* [Usage Analytics](/maiagent-user-guide/maiagent-user-guide-en/org/usage.md)
  {% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.maiagent.ai/maiagent-user-guide/maiagent-user-guide-en/build/custom-max-tokens.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
